RedeyeVentures\GeoPattern\GeoPattern::geoHexagons PHP Method

geoHexagons() protected method

Pattern Makers
protected geoHexagons ( )
    protected function geoHexagons()
    {
        $scale = $this->hexVal(0, 1);
        $sideLength = $this->map($scale, 0, 15, 8, 60);
        $hexHeight = $sideLength * sqrt(3);
        $hexWidth = $sideLength * 2;
        $hex = $this->buildHexagonShape($sideLength);
        $this->svg->setWidth($hexWidth * 3 + $sideLength * 3)->setHeight($hexHeight * 6);
        $i = 0;
        for ($y = 0; $y <= 5; $y++) {
            for ($x = 0; $x <= 5; $x++) {
                $val = $this->hexVal($i, 1);
                $dy = $x % 2 == 0 ? $y * $hexHeight : $y * $hexHeight + $hexHeight / 2;
                $opacity = $this->opacity($val);
                $fill = $this->fillColor($val);
                $styles = ['stroke' => self::STROKE_COLOR, 'stroke-opacity' => self::STROKE_OPACITY, 'fill-opacity' => $opacity, 'fill' => $fill];
                $onePointFiveXSideLengthMinusHalfHexWidth = $x * $sideLength * 1.5 - $hexWidth / 2;
                $dyMinusHalfHexHeight = $dy - $hexHeight / 2;
                $this->svg->addPolyline($hex, array_merge($styles, ['transform' => "translate({$onePointFiveXSideLengthMinusHalfHexWidth}, {$dyMinusHalfHexHeight})"]));
                // Add an extra one at top-right, for tiling.
                if ($x == 0) {
                    $onePointFiveSideLengthSixMinusHalfHexWidth = 6 * $sideLength * 1.5 - $hexWidth / 2;
                    $this->svg->addPolyline($hex, array_merge($styles, ['transform' => "translate({$onePointFiveSideLengthSixMinusHalfHexWidth}, {$dyMinusHalfHexHeight})"]));
                }
                // Add an extra row at the end that matches the first row, for tiling.
                if ($y == 0) {
                    $dy2 = $x % 2 == 0 ? 6 * $hexHeight : 6 * $hexHeight + $hexHeight / 2;
                    $dy2MinusHalfHexHeight = $dy2 - $hexHeight / 2;
                    $this->svg->addPolyline($hex, array_merge($styles, ['transform' => "translate({$onePointFiveXSideLengthMinusHalfHexWidth}, {$dy2MinusHalfHexHeight})"]));
                }
                // Add an extra one at bottom-right, for tiling.
                if ($x == 0 && $y == 0) {
                    $onePointFiveSideLengthSixMinusHalfHexWidth = 6 * $sideLength * 1.5 - $hexWidth / 2;
                    $fiveHexHeightPlusHalfHexHeight = 5 * $hexHeight + $hexHeight / 2;
                    $this->svg->addPolyline($hex, array_merge($styles, ['transform' => "translate({$onePointFiveSideLengthSixMinusHalfHexWidth}, {$fiveHexHeightPlusHalfHexHeight})"]));
                }
                $i++;
            }
        }
    }