@prescott/geo-pattern
Version:
Create beautiful generative geometric background images from a string.
38 lines • 1.36 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SquaresComposer = void 0;
const svg_1 = require("../svg");
const base_1 = require("./base");
class SquaresComposer extends base_1.StructureComposer {
constructor(seed, preset) {
super(seed, preset);
this.name = "squares";
this.squareSize = this.map(this.seed.read(0, 1), 0, 15, 10, 60);
this.width = this.height = this.squareSize * 6;
}
generate() {
const nodes = [];
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("rect", {
x: x * this.squareSize,
y: y * this.squareSize,
width: this.squareSize,
height: this.squareSize,
fill,
"fill-opacity": opacity,
stroke: this.preset.stroke.color,
"stroke-opacity": this.preset.stroke.opacity,
}));
i++;
}
}
return nodes;
}
}
exports.SquaresComposer = SquaresComposer;
//# sourceMappingURL=squares.js.map