dimitrievski / shapegen
Generates 2D shapes in different sizes
Requires
- php: ^7.0
Requires (Dev)
- phpunit/phpunit: ^6.0
This package is not auto-updated.
Last update: 2025-06-22 09:26:17 UTC
README
Generates 2D shapes (circles, ellipses, diamonds, squares, rectangles, triangles) in different sizes.
Requirements
PHP 7.0 and later.
Composer
You can install the bindings via Composer. Run the following command:
$ composer require dimitrievski/shapegen
To use the bindings, use Composer's autoload:
<?php require __DIR__ . '/vendor/autoload.php';
Getting Started
Simple usage looks like:
<?php $shapeGen = new \ShapeGen\ShapeGen(); echo $shapeGen->generate("diamond"); // X // XXXXX //XXXXXXXXX // XXXXX // X
To generate a shape with different size, pass an additional argument - number of lines. This argument must be an odd number between 5 and 49. The default is 5.
<?php $shapeGen = new \ShapeGen\ShapeGen(); echo $shapeGen->generate("diamond", 9); // X // XXXXX // XXXXXXXXX // XXXXXXXXXXXXX //XXXXXXXXXXXXXXXXX // XXXXXXXXXXXXX // XXXXXXXXX // XXXXX // X
To generate a shape with different filling, pass one more argument - filling character. This argument must be a string. The default is X.
<?php $shapeGen = new \ShapeGen\ShapeGen(); echo $shapeGen->generate("diamond", 9, "D"); // D // DDDDD // DDDDDDDDD // DDDDDDDDDDDDD //DDDDDDDDDDDDDDDDD // DDDDDDDDDDDDD // DDDDDDDDD // DDDDD // D
To create new shapes, use the shape factory like:
<?php $shapeFactory = new \ShapeGen\ShapeFactory(); $diamond = $shapeFactory->create("diamond"); //set different size and filling $diamond->setLines(15); $diamond->setFilling("-"); echo $diamond->generate(); // - // ----- // --------- // ------------- // ----------------- // --------------------- // ------------------------- //----------------------------- // ------------------------- // --------------------- // ----------------- // ------------- // --------- // ----- // -
Development
Install dependencies:
$ composer install
Tests
Install dependencies as mentioned above (which will resolve PHPUnit), then you can run the test suite:
$ ./vendor/bin/phpunit tests/