UNPKG

@prescott/geo-pattern

Version:

Create beautiful generative geometric background images from a string.

53 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OctagonsComposer = void 0; const svg_1 = require("../svg"); const base_1 = require("./base"); class OctagonsComposer extends base_1.StructureComposer { constructor(seed, preset) { super(seed, preset); this.name = "octagons"; this.squareSize = this.map(this.seed.read(0, 1), 0, 15, 10, 60); this.width = this.height = this.squareSize * 6; } generate() { const nodes = []; const points = (() => { const s = this.squareSize; const c = s * 0.33; return [ c, 0, s - c, 0, s, c, s, s - c, s - c, s, c, s, 0, s - c, 0, c, c, 0, ].join(","); })(); let i = 0; for (let y = 0; y <= 5; y++) { for (let x = 0; x <= 5; x++) { const value = this.seed.read(i, 1); const opacity = this.opacity(value); const fill = this.fillColor(value); nodes.push(new svg_1.SVGNode("polyline", { points, fill, "fill-opacity": opacity, stroke: this.preset.stroke.color, "stroke-opacity": this.preset.stroke.opacity, transform: this.buildTransform([ { translate: [x * this.squareSize, y * this.squareSize] }, ]), })); i++; } } return nodes; } } exports.OctagonsComposer = OctagonsComposer; //# sourceMappingURL=octagons.js.map