@slithy/prim-lib 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +10 -1
- package/dist/index.js +50 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -174,6 +174,15 @@ declare class Smiley extends Shape {
|
|
|
174
174
|
mutate(_cfg?: Partial<Cfg>): Smiley;
|
|
175
175
|
toSVG(): SVGElement;
|
|
176
176
|
}
|
|
177
|
+
declare class Square extends Shape {
|
|
178
|
+
center: Point;
|
|
179
|
+
r: number;
|
|
180
|
+
constructor(w: number, h: number);
|
|
181
|
+
computeBbox(): this;
|
|
182
|
+
render(ctx: CanvasRenderingContext2D): void;
|
|
183
|
+
toSVG(): SVGElement;
|
|
184
|
+
mutate(_cfg?: Partial<Cfg>): ShapeInterface;
|
|
185
|
+
}
|
|
177
186
|
declare class Hexagon extends Shape {
|
|
178
187
|
center: Point;
|
|
179
188
|
r: number;
|
|
@@ -203,4 +212,4 @@ declare function computeColorAndDifferenceChange(offset: Bbox, imageData: ShapeI
|
|
|
203
212
|
differenceChange: number;
|
|
204
213
|
};
|
|
205
214
|
|
|
206
|
-
export { type Bbox, Canvas, type Cfg, Debug, Ellipse, Hexagon, type ImageDataLike, Optimizer, type Point, type PreCfg, Rectangle, SVGNS, Shape, type ShapeImageData, type ShapeInterface, Smiley, State, Step, Triangle, clamp, clampColor, computeColorAndDifferenceChange, difference, differenceToDistance, distanceToDifference, stepPerf };
|
|
215
|
+
export { type Bbox, Canvas, type Cfg, Debug, Ellipse, Hexagon, type ImageDataLike, Optimizer, type Point, type PreCfg, Rectangle, SVGNS, Shape, type ShapeImageData, type ShapeInterface, Smiley, Square, State, Step, Triangle, clamp, clampColor, computeColorAndDifferenceChange, difference, differenceToDistance, distanceToDifference, stepPerf };
|
package/dist/index.js
CHANGED
|
@@ -618,6 +618,55 @@ var Smiley = class _Smiley extends Shape {
|
|
|
618
618
|
return text;
|
|
619
619
|
}
|
|
620
620
|
};
|
|
621
|
+
var Square = class _Square extends Shape {
|
|
622
|
+
center;
|
|
623
|
+
r;
|
|
624
|
+
constructor(w, h) {
|
|
625
|
+
super(w, h);
|
|
626
|
+
this.center = Shape.randomPoint(w, h);
|
|
627
|
+
this.r = 1 + ~~(Math.random() * 20);
|
|
628
|
+
this.computeBbox();
|
|
629
|
+
}
|
|
630
|
+
computeBbox() {
|
|
631
|
+
this.bbox = {
|
|
632
|
+
left: this.center[0] - this.r,
|
|
633
|
+
top: this.center[1] - this.r,
|
|
634
|
+
width: 2 * this.r || 1,
|
|
635
|
+
height: 2 * this.r || 1
|
|
636
|
+
};
|
|
637
|
+
return this;
|
|
638
|
+
}
|
|
639
|
+
render(ctx) {
|
|
640
|
+
ctx.fillRect(this.center[0] - this.r, this.center[1] - this.r, 2 * this.r, 2 * this.r);
|
|
641
|
+
}
|
|
642
|
+
toSVG() {
|
|
643
|
+
const node = document.createElementNS(SVGNS, "rect");
|
|
644
|
+
node.setAttribute("x", String(this.center[0] - this.r));
|
|
645
|
+
node.setAttribute("y", String(this.center[1] - this.r));
|
|
646
|
+
node.setAttribute("width", String(2 * this.r));
|
|
647
|
+
node.setAttribute("height", String(2 * this.r));
|
|
648
|
+
return node;
|
|
649
|
+
}
|
|
650
|
+
mutate(_cfg) {
|
|
651
|
+
const clone = new _Square(0, 0);
|
|
652
|
+
clone.center = [this.center[0], this.center[1]];
|
|
653
|
+
clone.r = this.r;
|
|
654
|
+
switch (Math.floor(Math.random() * 2)) {
|
|
655
|
+
case 0: {
|
|
656
|
+
const angle = Math.random() * 2 * Math.PI;
|
|
657
|
+
const radius = Math.random() * 20;
|
|
658
|
+
clone.center[0] += ~~(radius * Math.cos(angle));
|
|
659
|
+
clone.center[1] += ~~(radius * Math.sin(angle));
|
|
660
|
+
break;
|
|
661
|
+
}
|
|
662
|
+
case 1:
|
|
663
|
+
clone.r += (Math.random() - 0.5) * 20;
|
|
664
|
+
clone.r = Math.max(1, ~~clone.r);
|
|
665
|
+
break;
|
|
666
|
+
}
|
|
667
|
+
return clone.computeBbox();
|
|
668
|
+
}
|
|
669
|
+
};
|
|
621
670
|
var Hexagon = class _Hexagon extends Shape {
|
|
622
671
|
center;
|
|
623
672
|
r;
|
|
@@ -810,6 +859,7 @@ export {
|
|
|
810
859
|
SVGNS,
|
|
811
860
|
Shape,
|
|
812
861
|
Smiley,
|
|
862
|
+
Square,
|
|
813
863
|
State,
|
|
814
864
|
Step,
|
|
815
865
|
Triangle,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slithy/prim-lib",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Core engine for primitive-based image reconstruction.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"tsup": "^8",
|
|
20
20
|
"typescript": "^5",
|
|
21
21
|
"vitest": "^4",
|
|
22
|
-
"@slithy/
|
|
23
|
-
"@slithy/
|
|
22
|
+
"@slithy/tsconfig": "0.0.0",
|
|
23
|
+
"@slithy/eslint-config": "0.0.0"
|
|
24
24
|
},
|
|
25
25
|
"author": {
|
|
26
26
|
"name": "Matthew Campagna",
|