sixty-nine/php-cloud-lib

View on GitHub
src/SixtyNine/Cloud/Placer/LissajouPlacer.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace SixtyNine\Cloud\Placer;

use Imagine\Image\Point;
use Imagine\Image\PointInterface;

class LissajouPlacer extends AbstractPlacer
{
    protected $increment = 0;

    /** {@inheritdoc} */
    public function getNextPlaceToTry(PointInterface $current)
    {
        $first = $this->getFirstPlaceToTry();
        // TODO: needs some params adjusting ($a, $b, $delta)
        $a = 50;
        $b = 49;
        $A = $first->getX();
        $B = $first->getY();
        $delta = pi() / 4;
        $this->increment += 0.01;

        $x = $A * sin($a * $this->increment + $delta) + $A;
        $y = $B * sin($b * $this->increment) + $B;

        if ($this->increment > 2 * pi()) {
            return false;
        }

        return new Point($x, $y);
    }

    /** {@inheritdoc} */
    function getFirstPlaceToTry()
    {
        return new Point((int)($this->imgWidth / 2), (int)($this->imgHeight / 2));
    }
}