Newer
Older
fractals / src / index.ts
@peter peter on 3 Oct 2019 1 KB Added hexagonal base shape.
import { createSquare, createTriangle, inwardSpiralFractal, fractalToSvg, createHexagonalBase, createInwardSpiral } from "./FractalSVG";

function pageInit(): void
{
    const sideLength = 400;
    const iterations = 50;
    const shrinkRate = 0.1;
    const randomizeShrinkRate = 0.3;

    const startShape = createSquare(sideLength);

    const fractal = inwardSpiralFractal(startShape, iterations, shrinkRate, 0);
    const divSpiral = document.getElementById("spiral") as HTMLDivElement;
    divSpiral.appendChild(fractalToSvg(fractal, sideLength));

    const randomizedFractal = inwardSpiralFractal(startShape, iterations, shrinkRate, randomizeShrinkRate);
    const divRandomizedSpiral = document.getElementById("randomizedSpiral") as HTMLDivElement;
    divRandomizedSpiral.appendChild(fractalToSvg(randomizedFractal, sideLength));

    const triangle = createTriangle(sideLength);
    const triangleFractal = inwardSpiralFractal(triangle, iterations, 1-0.06, 0);
    const divTriangle = document.getElementById("triangle") as HTMLDivElement;
    divTriangle.appendChild(fractalToSvg(triangleFractal, sideLength));

    const hexagonalBase = createHexagonalBase(sideLength);
    const hexagonalFractal = hexagonalBase.map(h => createInwardSpiral(h, iterations, 0.1, 0));
    const divHexagonal = document.getElementById("hexagonal") as HTMLDivElement;
    divHexagonal.appendChild(fractalToSvg(hexagonalFractal, sideLength));
}

document.addEventListener("DOMContentLoaded", pageInit);