diff --git a/src/FractalSVG.ts b/src/FractalSVG.ts
index d7ddf8b..431fa94 100644
--- a/src/FractalSVG.ts
+++ b/src/FractalSVG.ts
@@ -22,7 +22,7 @@
return output;
}
-export function createInwardSpiral(input:Polygon, maxiterations:number, shrinkRate:number): Polygon[]
+function createInwardSpiral(input:Polygon, maxiterations:number, shrinkRate:number): Polygon[]
{
const cycle:Polygon[] = [input];
let pNext:Polygon;
@@ -37,27 +37,43 @@
return cycle;
}
-function polygonToSVG(polygon:Polygon, cssStyle:string): string
+function polygonToSvg(
+ svgRootElement:SVGSVGElement,
+ polygon:Polygon,
+ { fill }:{fill:string | null},
+): SVGPolygonElement
{
- const svg = [``);
- return svg.join("");
+ return polygonSvg;
}
-export function fractalToSVG(fractal:Polygon[][], sideLength:number): string
+function polygonStyle(strength:number)
{
- // const el = document.createElement("svg");
- // el.setAttribute("width", sideLength.toString());
- // el.setAttribute("height", sideLength.toString());
- // el.setAttribute("style", "fill:none;stroke:purple;stroke-width:1");
+ return {
+ fill: `rgb(0,0,${Math.floor(strength)})`,
+ };
+}
- const svg = [`");
-
- return svg.join("");
+ return el;
}
export function createSquare(side:number): Polygon
diff --git a/src/FractalSVG.ts b/src/FractalSVG.ts
index d7ddf8b..431fa94 100644
--- a/src/FractalSVG.ts
+++ b/src/FractalSVG.ts
@@ -22,7 +22,7 @@
return output;
}
-export function createInwardSpiral(input:Polygon, maxiterations:number, shrinkRate:number): Polygon[]
+function createInwardSpiral(input:Polygon, maxiterations:number, shrinkRate:number): Polygon[]
{
const cycle:Polygon[] = [input];
let pNext:Polygon;
@@ -37,27 +37,43 @@
return cycle;
}
-function polygonToSVG(polygon:Polygon, cssStyle:string): string
+function polygonToSvg(
+ svgRootElement:SVGSVGElement,
+ polygon:Polygon,
+ { fill }:{fill:string | null},
+): SVGPolygonElement
{
- const svg = [``);
- return svg.join("");
+ return polygonSvg;
}
-export function fractalToSVG(fractal:Polygon[][], sideLength:number): string
+function polygonStyle(strength:number)
{
- // const el = document.createElement("svg");
- // el.setAttribute("width", sideLength.toString());
- // el.setAttribute("height", sideLength.toString());
- // el.setAttribute("style", "fill:none;stroke:purple;stroke-width:1");
+ return {
+ fill: `rgb(0,0,${Math.floor(strength)})`,
+ };
+}
- const svg = [`");
-
- return svg.join("");
+ return el;
}
export function createSquare(side:number): Polygon
diff --git a/src/index.ts b/src/index.ts
index 344ff12..7468132 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,4 +1,4 @@
-import { createSquare, inwardSpiralFractal, fractalToSVG } from "./FractalSVG";
+import { createSquare, inwardSpiralFractal, fractalToSvg } from "./FractalSVG";
function pageInit(): void
{
@@ -8,11 +8,9 @@
const startShape = createSquare(sideLength);
const fractal = inwardSpiralFractal(startShape, iterations, shrinkRate);
- const svg = fractalToSVG(fractal, sideLength);
-
const divSpiral = document.getElementById("spiral") as HTMLDivElement;
- divSpiral.innerHTML = svg;
- // document.body.append(svg);
+
+ divSpiral.appendChild(fractalToSvg(fractal, sideLength));
}
document.addEventListener("DOMContentLoaded", pageInit);