termlings 0.1.5 → 0.1.6
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/bin/termlings.js +13 -7
- package/package.json +1 -1
- package/src/index.ts +13 -7
package/bin/termlings.js
CHANGED
|
@@ -407,16 +407,19 @@ function renderSVG(dna2, pixelSize = 10, frame = 0, background = "auto", padding
|
|
|
407
407
|
const cols = 9;
|
|
408
408
|
const rows = grid.length;
|
|
409
409
|
const pad = padding;
|
|
410
|
-
const
|
|
411
|
-
const
|
|
410
|
+
const side = Math.max(cols, rows) + pad * 2;
|
|
411
|
+
const w = side * pixelSize;
|
|
412
|
+
const h = side * pixelSize;
|
|
413
|
+
const ox = Math.floor((side - cols) / 2);
|
|
414
|
+
const oy = Math.floor((side - rows) / 2);
|
|
412
415
|
const half = Math.round(pixelSize / 2);
|
|
413
416
|
const quarter = Math.round(pixelSize / 4);
|
|
414
417
|
const rects = [];
|
|
415
418
|
for (let y = 0; y < rows; y++) {
|
|
416
419
|
for (let x = 0; x < cols; x++) {
|
|
417
420
|
const cell = grid[y][x];
|
|
418
|
-
const rx = (x +
|
|
419
|
-
const ry = (y +
|
|
421
|
+
const rx = (x + ox) * pixelSize;
|
|
422
|
+
const ry = (y + oy) * pixelSize;
|
|
420
423
|
if (cell === "f") {
|
|
421
424
|
rects.push(`<rect x="${rx}" y="${ry}" width="${pixelSize}" height="${pixelSize}" fill="${faceHex}"/>`);
|
|
422
425
|
} else if (cell === "l") {
|
|
@@ -517,8 +520,11 @@ function renderLayeredSVG(dna2, pixelSize = 10, bw2 = false, padding = 0) {
|
|
|
517
520
|
const legFrameCount2 = legVariant.length;
|
|
518
521
|
const totalRows = hatRows.length + 1 + 1 + 2 + 2 + 1;
|
|
519
522
|
const pad = padding;
|
|
520
|
-
const
|
|
521
|
-
const
|
|
523
|
+
const side = Math.max(cols, totalRows) + pad * 2;
|
|
524
|
+
const w = side * pixelSize;
|
|
525
|
+
const h = side * pixelSize;
|
|
526
|
+
const ox = Math.floor((side - cols) / 2);
|
|
527
|
+
const oy = Math.floor((side - totalRows) / 2);
|
|
522
528
|
function px(cell, rx, ry) {
|
|
523
529
|
if (cell === "_") return "";
|
|
524
530
|
if (cell === "f") return `<rect x="${rx}" y="${ry}" width="${pixelSize}" height="${pixelSize}" fill="${faceHex}"/>`;
|
|
@@ -537,7 +543,7 @@ function renderLayeredSVG(dna2, pixelSize = 10, bw2 = false, padding = 0) {
|
|
|
537
543
|
let out = "";
|
|
538
544
|
for (let y = 0; y < rows.length; y++) {
|
|
539
545
|
for (let x = 0; x < cols; x++) {
|
|
540
|
-
out += px(rows[y][x], (x +
|
|
546
|
+
out += px(rows[y][x], (x + ox) * pixelSize, (startY + y + oy) * pixelSize);
|
|
541
547
|
}
|
|
542
548
|
}
|
|
543
549
|
return out;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -488,8 +488,11 @@ export function renderSVG(dna: string, pixelSize = 10, frame = 0, background: st
|
|
|
488
488
|
const cols = 9;
|
|
489
489
|
const rows = grid.length;
|
|
490
490
|
const pad = padding;
|
|
491
|
-
const
|
|
492
|
-
const
|
|
491
|
+
const side = Math.max(cols, rows) + pad * 2;
|
|
492
|
+
const w = side * pixelSize;
|
|
493
|
+
const h = side * pixelSize;
|
|
494
|
+
const ox = Math.floor((side - cols) / 2);
|
|
495
|
+
const oy = Math.floor((side - rows) / 2);
|
|
493
496
|
|
|
494
497
|
const half = Math.round(pixelSize / 2);
|
|
495
498
|
const quarter = Math.round(pixelSize / 4);
|
|
@@ -497,8 +500,8 @@ export function renderSVG(dna: string, pixelSize = 10, frame = 0, background: st
|
|
|
497
500
|
for (let y = 0; y < rows; y++) {
|
|
498
501
|
for (let x = 0; x < cols; x++) {
|
|
499
502
|
const cell = grid[y][x];
|
|
500
|
-
const rx = (x +
|
|
501
|
-
const ry = (y +
|
|
503
|
+
const rx = (x + ox) * pixelSize;
|
|
504
|
+
const ry = (y + oy) * pixelSize;
|
|
502
505
|
if (cell === "f") {
|
|
503
506
|
rects.push(`<rect x="${rx}" y="${ry}" width="${pixelSize}" height="${pixelSize}" fill="${faceHex}"/>`);
|
|
504
507
|
} else if (cell === "l") {
|
|
@@ -635,8 +638,11 @@ export function renderLayeredSVG(dna: string, pixelSize = 10, bw = false, paddin
|
|
|
635
638
|
// hat + face + eyes + 2 mouth + 2 body + 1 legs
|
|
636
639
|
const totalRows = hatRows.length + 1 + 1 + 2 + 2 + 1;
|
|
637
640
|
const pad = padding;
|
|
638
|
-
const
|
|
639
|
-
const
|
|
641
|
+
const side = Math.max(cols, totalRows) + pad * 2;
|
|
642
|
+
const w = side * pixelSize;
|
|
643
|
+
const h = side * pixelSize;
|
|
644
|
+
const ox = Math.floor((side - cols) / 2);
|
|
645
|
+
const oy = Math.floor((side - totalRows) / 2);
|
|
640
646
|
|
|
641
647
|
function px(cell: Pixel, rx: number, ry: number): string {
|
|
642
648
|
if (cell === "_") return "";
|
|
@@ -657,7 +663,7 @@ export function renderLayeredSVG(dna: string, pixelSize = 10, bw = false, paddin
|
|
|
657
663
|
let out = "";
|
|
658
664
|
for (let y = 0; y < rows.length; y++) {
|
|
659
665
|
for (let x = 0; x < cols; x++) {
|
|
660
|
-
out += px(rows[y][x], (x +
|
|
666
|
+
out += px(rows[y][x], (x + ox) * pixelSize, (startY + y + oy) * pixelSize);
|
|
661
667
|
}
|
|
662
668
|
}
|
|
663
669
|
return out;
|