Newer
Older
fractals / src / app.ts
@peter peter on 2 Oct 2019 765 bytes Refactoring.
import * as express from "express";
import { join } from "path";
import { Point, Polygon } from "./Polygon";
import { createInwardSpiral, fractalToSVG, inwardSpiralFractal, createSquare } from "./FractalSVG";

const app = express();

const port = 8081;

app.get("/randomFractal.svg", (req, res) => {
    const sideLength = 400;
    const iterations = 50;
    const shrinkRate = 0.1;

    const startShape = createSquare(sideLength);
    const fractal = inwardSpiralFractal(startShape, iterations, shrinkRate);
    const svg = fractalToSVG(fractal, sideLength);

    res.setHeader("content-type", "image/svg+xml");
    res.send(svg);
});

app.use(express.static(join(".", "public")));

app.listen(port, () => console.log(`Fractals server started on port ${port}`));