RedeyeVentures\GeoPattern\GeoPattern::geoXes PHP Method

geoXes() protected method

protected geoXes ( )
    protected function geoXes()
    {
        $squareSize = $this->map($this->hexVal(0, 1), 0, 15, 10, 25);
        $xSize = $squareSize * 3 * 0.9429999999999999;
        $xShape = $this->buildPlusShape($squareSize);
        $this->svg->setWidth($xSize * 3)->setHeight($xSize * 3);
        $i = 0;
        for ($y = 0; $y <= 5; $y++) {
            for ($x = 0; $x <= 5; $x++) {
                $val = $this->hexVal($i, 1);
                $opacity = $this->opacity($val);
                $fill = $this->fillColor($val);
                $dy = $x % 2 == 0 ? $y * $xSize - $xSize * 0.5 : $y * $xSize - $xSize * 0.5 + $xSize / 4;
                $styles = ['fill' => $fill, 'style' => ['opacity' => $opacity]];
                $group = new Group();
                $group->addItem($xShape[0])->addItem($xShape[1]);
                $t1 = $x * $xSize / 2 - $xSize / 2;
                $t2 = $dy - $y * $xSize / 2;
                $halfXSize = $xSize / 2;
                $this->svg->addGroup($group, array_merge($styles, ['transform' => "translate({$t1}, {$t2}) rotate(45, {$halfXSize}, {$halfXSize})"]));
                // Add an extra column on the right for tiling.
                if ($x == 0) {
                    $xT1 = 6 * $xSize / 2 - $xSize / 2;
                    $xT2 = $dy - $y * $xSize / 2;
                    $this->svg->addGroup($group, array_merge($styles, ['transform' => "translate({$xT1}, {$xT2}) rotate(45, {$halfXSize}, {$halfXSize})"]));
                }
                // Add an extra row on the bottom that matches the first row, for tiling.
                if ($y == 0) {
                    $dy = $x % 2 == 0 ? 6 * $xSize - $xSize / 2 : 6 * $xSize - $xSize / 2 + $xSize / 4;
                    $yT1 = $x * $xSize / 2 - $xSize / 2;
                    $yT2 = $dy - 6 * $xSize / 2;
                    $this->svg->addGroup($group, array_merge($styles, ['transform' => "translate({$yT1}, {$yT2}) rotate(45, {$halfXSize}, {$halfXSize})"]));
                }
                // These can hang off the bottom, so put a row at the top for tiling.
                if ($y == 5) {
                    $y2T1 = $x * $xSize / 2 - $xSize / 2;
                    $y2T2 = $dy - 11 * $xSize / 2;
                    $this->svg->addGroup($group, array_merge($styles, ['transform' => "translate({$y2T1}, {$y2T2}) rotate(45, {$halfXSize}, {$halfXSize})"]));
                }
                // Add an extra one at top-right and bottom-right, for tiling.
                if ($x == 0 && $y == 0) {
                    $xyT1 = 6 * $xSize / 2 - $xSize / 2;
                    $xyT2 = $dy - 6 * $xSize / 2;
                    $this->svg->addGroup($group, array_merge($styles, ['transform' => "translate({$xyT1}, {$xyT2}) rotate(45, {$halfXSize}, {$halfXSize}"]));
                }
                $i++;
            }
        }
    }