Skip to content

Visual compare random algorithm. Generate visual noise by random generated sequences.

Notifications You must be signed in to change notification settings

avnovoselov/compare_random_algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compare random generated noise

Install

git clone https://github.com/avnovoselov/compare_random_algorithm.git
cd compare_random_algorithm
composer install

Start server

php -S 127.0.0.1:8080 -t public

open link in your browser

Add custom algorithm

You need implements AlgorithmInterface and put your class into src/Algorithm/<YourRandomGenerator>.php. AlgorithmInterface require implement method sequence.

Example custom algorithm

Put Custom.php to src/Algorithm

<?php
// src/Algorithm/Custom.php

namespace Random\Algorithm;

use Generator;

/**
 * Class Custom
 * @package Random\Algorithm
 */
final class Custom extends AbstractAlgorithm
{

    /**
     * @inheritDoc
     */
    public function sequence(): Generator
    {
        $i = 0;
        $halfMaxX = $this->maxX / 2;
        $halfMaxY = $this->maxY / 2;
        while ($i++ < $this->getSequenceLength()) {
            yield [
                $halfMaxX + rand(-$halfMaxX, $halfMaxX),
                $halfMaxY + rand(-$halfMaxY, $halfMaxY),
            ];
        }
    }

    /**
     * @inheritDoc
     */
    public function __construct(int $maxX, int $maxY)
    {
        $this->maxX = $maxX;
        $this->maxY = $maxY;
    }
}

Add rule for custom algorithm to src/AlgorithmStaticFactory.php

...
    final public static function factory(string $algorithmName, int $maxX, int $maxY): AlgorithmInterface
    {
        switch ($algorithmName) {
            ...
            case "custom":
                return new Custom($maxX, $maxY);
            ...
        }
    }
...

Now you can get a noised image by url http://127.0.0.1:8080/application.php?algorithm=custom

About

Visual compare random algorithm. Generate visual noise by random generated sequences.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published