@prescott/geo-pattern
Version:
Create beautiful generative geometric background images from a string.
62 lines • 1.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StructureComposer = void 0;
const processing_1 = require("../processing");
const svg_1 = require("../svg");
class StructureComposer {
constructor(seed, preset) {
this.seed = seed;
this.preset = preset;
this.width = 100;
this.height = 100;
this.map = processing_1.map;
}
async compose(pattern) {
pattern.structure = {
image: this.generate(),
preset: this.preset,
name: this.name,
composer: this,
};
pattern.width = this.width;
pattern.height = this.height;
}
fillColor(value) {
return value % 2 === 0 ? this.preset.fill.light : this.preset.fill.dark;
}
opacity(value) {
return this.map(value, 0, 15, this.preset.opacity.min, this.preset.opacity.max);
}
buildPlusShape(size) {
return [
new svg_1.SVGNode("rect", {
x: size,
y: 0,
width: size,
height: size * 3,
}),
new svg_1.SVGNode("rect", {
x: 0,
y: size,
width: size * 3,
height: size,
}),
];
}
buildTransform(commands) {
return commands.map((command) => {
const { translate, rotate, scale } = command;
if (translate) {
return `translate(${translate.join(",")})`;
}
else if (rotate) {
return `rotate(${rotate.join(",")})`;
}
else if (scale) {
return `scale(${scale.join(",")})`;
}
}).join(" ");
}
}
exports.StructureComposer = StructureComposer;
//# sourceMappingURL=base.js.map