-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstar22.js
executable file
·117 lines (104 loc) · 5.36 KB
/
star22.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env node
//ESOL Star v 2.0 2020
//TODO: Mega-star
"use strict"; //find bugs + typos easier
//imports(); //hoist
const assert = require('assert').strict; //https://nodejs.org/api/assert.html; CAUTION: SLOW; don't use in big loops!
const {PAL} = require("../incl/color-mgmt22");
const {Model, Rect, ZZ, flip} = require("../models/model22");
const {debug, TODO, srcline, replace_prop} = require("../incl/utils22");
//my_exports({mary: NatFig("Mary: NAT"), joseph: Natfig("Joseph: NAT"), Natfig}); //NOTE: exporting instances + ctor
my_exports({star: Star(), Star}); //NOTE: exporting instances + ctor
TODO("use other star projections? should center be in middle? (depends on fx)");
//star:
//~ radial 9 main spokes, each 2-4 wide, 11-14 long
function Star(opts) { return Object.assign(/*{}, opts || {},*/ new Model(
{
maxbr: 100/100, //20A supply
order: "RGB",
name: "Star: NAT, prop",
num_wired: 2*150 - 2, //~ 2 5m strips
//map radial top-down view of spokes to X ofs (CW):
spikes: Object.defineProperties(
{ //enumerable:
//TODO: use other projections? should center be in middle? (depends on fx)
center: Rect({X: 0, Y: 0, W: 3, H: 14}),
get S() { const parent = this; return Rect({X: parent.center.rightE, Y: 0, W: parent.fb.W, H: parent.fb.L}); },
get SW() { const parent = this; return Rect({X: parent.S.rightE, Y: 0, W: parent.diag.W, H: parent.diag.L}); },
get W() { const parent = this; return Rect({X: parent.SW.rightE, Y: 0, W: parent.lr.W, H: parent.lr.L}); },
get NW() { const parent = this; return Rect({X: parent.W.rightE, Y: 0, W: parent.diag.W, H: parent.diag.L}); },
get N() { const parent = this; return Rect({X: parent.NW.rightE, Y: 0, W: parent.fb.W, H: parent.fb.L}); },
get NE() { const parent = this; return Rect({X: parent.N.rightE, Y: 0, W: parent.diag.W, H: parent.diag.L}); },
get E() { const parent = this; return Rect({X: parent.NE.rightE, Y: 0, W: parent.lr.W, H: parent.lr.L}); },
get SE() { const parent = this; return Rect({X: parent.E.rightE, Y: 0, W: parent.diag.W, H: parent.diag.L}); },
}, { // !enumerable:
// get all() { return this.SE + diagW; },
lr: {value: {W: 3, L: 12}}, //left, right
fb: {value: {W: 4, L: 12}}, //front, back
diag: {value: {W: 2, L: 11}},
}),
get width() { return Object.values(this.spikes).reduce((total, submodel) => total + submodel.W, 0); }, //25
get height() { return Object.values(this.spikes).reduce((total, submodel) => Math.max(total, submodel.H), 0); }, //14
draw: function() //default texture
{
this.fill(PAL.OFF);
// Object.values(this.spikes).forEach(
[this.spikes.center, this.spikes.N, this.spikes.S, this.spikes.E, this.spikes.W].forEach(submodel => this.fill(PAL.WARM_WHITE.dim(80), submodel));
[this.spikes.NW, this.spikes.SW, this.spikes.NE, this.spikes.SE].forEach(submodel => this.fill(PAL.COOL_WHITE.dim(60), submodel));
},
get numpx() //CAUTION: nodes must be in wiring order
{
let numpx = 0;
//TODO: reorder spikes L2R?
//spikes L2RB2T (CW center outward) mostly ZZ
//center (upright) spike:
for (let x = 0; x < this.spikes.center.W; ++x)
for (let y = 0; y < this.spikes.center.H; ++y)
{
const yZZ = (x & 1)? flip(y, this.spikes.center.H): y;
this.nodes2D[this.spikes.center.X + x][this.spikes.center.Y + yZZ] = numpx++;
}
//debug(numpx);
//S/N (front/back) spikes:
[this.spikes.S, this.spikes.N].forEach(spike =>
{
for (let x = 0; x < spike.W; ++x)
for (let y = 0; y < spike.H; ++y)
{
const yZZ = (x & 1)? flip(y, spike.H): y;
this.nodes2D[spike.X + x][spike.Y + yZZ] = numpx++;
}
});
//debug(numpx);
//W/E (left/right) spikes:
[this.spikes.W, this.spikes.E].forEach(spike =>
{
for (let x = 0; x < spike.W; ++x)
for (let y = 0; y < spike.H; ++y)
{
const yZZ = (x & 1)? flip(y, spike.H): y;
this.nodes2D[spike.X + x][spike.Y + yZZ] = numpx++;
}
});
//debug(numpx);
//SW/NW/NE/SE (diag) spikes:
[this.spikes.SW, this.spikes.NW, this.spikes.NE, this.spikes.SE].forEach(spike =>
{
for (let x = 0; x < spike.W; ++x)
for (let y = 0; y < spike.H; ++y)
{
const yZZ = (x & 1)? flip(y, spike.H): y;
this.nodes2D[spike.X + x][spike.Y + yZZ] = numpx++;
}
});
//debug(numpx);
assert(numpx == Object.values(this.spikes).reduce((total, spike) => total + spike.W * spike.H, 0), `numpx ${numpx} != center ${this.spikes.center.area} + 2 N/S ${this.spikes.N.area} + 2 W/E ${this.spikes.W.area} + 4 diag ${this.spikes.SW.area} = ${Object.values(this.spikes).reduce((total, spike) => total + spike.W * spike.H, 0)}`); //check all nodes mapped
assert(numpx == this.num_wired, `numpx ${numpx} != num_wired ${this.num_wired}`);
return numpx;
},
}), opts || {}); }
if (!module.parent) setImmediate(async () => await module.exports.star.unit_test()); //unit-test; run after inline init
//wisemen[0].csv();
//run();
function my_exports(things) { return Object.assign(module.exports, things); } //{[entpt.name]: entpt}); }
//eof