@prescott/geo-pattern
Version:
Create beautiful generative geometric background images from a string.
67 lines • 2.53 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OverlappingCirclesComposer = void 0;
const svg_1 = require("../svg");
const base_1 = require("./base");
class OverlappingCirclesComposer extends base_1.StructureComposer {
constructor(seed, preset) {
super(seed, preset);
this.name = "overlapping-circles";
this.scale = this.seed.read(0, 1);
this.diameter = this.map(this.scale, 0, 15, 25, 200);
this.radius = this.diameter / 2;
this.width = this.height = this.radius * 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);
const styles = {
fill,
style: `opacity: ${opacity}`,
};
nodes.push(new svg_1.SVGNode("circle", {
cx: x * this.radius,
cy: y * this.radius,
r: this.radius,
...styles,
}));
// Add an extra one at top-right, for tiling.
if (x === 0) {
nodes.push(new svg_1.SVGNode("circle", {
cx: 6 * this.radius,
cy: y * this.radius,
r: this.radius,
...styles,
}));
}
// Add an extra row at the end that matches the first row, for tiling.
if (y === 0) {
nodes.push(new svg_1.SVGNode("circle", {
cx: x * this.radius,
cy: 6 * this.radius,
r: this.radius,
...styles,
}));
}
// Add an extra one at bottom-right, for tiling.
if (x === 0 && y === 0) {
nodes.push(new svg_1.SVGNode("circle", {
cx: 6 * this.radius,
cy: 6 * this.radius,
r: this.radius,
...styles,
}));
}
i++;
}
}
return nodes;
}
}
exports.OverlappingCirclesComposer = OverlappingCirclesComposer;
//# sourceMappingURL=overlapping-circles.js.map