amercier / rectangular-mozaic
Rectangular mozaic generator library
Installs: 1 417
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- myclabs/php-enum: ^1.6
Requires (Dev)
- brainmaestro/composer-git-hooks: ^2.5
- phpunit/phpunit: ^7.3
- squizlabs/php_codesniffer: ^3.3
This package is auto-updated.
Last update: 2024-11-07 03:40:12 UTC
README
Rectangular mozaic generator library for PHP.
Description
Given a number of tiles T, and a number of columns Columns C
, this library helps
generating a grid of C
columns containing T
tiles. Each tile will either:
- occupy 1 cell, or
- span over 2 cells vertically,
- span over 2 cells horizontally.
Note: as tiles are distributed randomly, number of lines may vary from one execution to another.
Demo
Example at Œco Architectes (refresh the page to get a new layout):
Note: all images belong to Œco Architectes.
Installation
Install using Composer:
composer require amercier/rectangular-mozaic
Usage
In the following example, we will create a HTML <table>
element containing 20
tiles.
Note: we just use a table for simplicity here. For a real website, only use
<table>
for tabular data.
<?php use \RectangularMozaic\Generator as Mozaic; use \RectangularMozaic\Cell; $tilesNumber = 20; $columns = 5; $grid = Mozaic::generate($tilesNumber, $columns); echo '<table>'; $i = 1; foreach ($grid->getCells() as $row) { echo '<tr>'; foreach ($row as $cell) { switch ($cell) { case Cell::SMALL: echo '<td>' . $i . '</td>'; break; case Cell::TALL_TOP: echo '<td rowspan="2">' . $i . '</td>'; break; case Cell::TALL_BOTTOM: break; // do nothing case Cell::WIDE_LEFT: echo '<td colspan="2">' . $i . '</td>'; break; case Cell::WIDE_RIGHT: break; // do nothing } $i += 1; } echo '</tr>'; } echo '</table>';
Example of generated tables:
To run this example, git clone
this repository locally and run:
composer install composer start