-
Notifications
You must be signed in to change notification settings - Fork 0
/
spiral_z.js
55 lines (38 loc) · 1.16 KB
/
spiral_z.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
importScripts('helpers.js')
postMessage(['sliders', defaultControls.concat([
{label: 'Spacing', value: 1, min: 0.5, max: 5, step: 0.1},
{label: 'Pen width', value: 5, min: 0.1, max: 20, step: 1},
{label: 'Z steps', value: 8, min: 2, max: 255, step: 4},
])]);
onmessage = function(e) {
const [ config, pixData ] = e.data;
const spacing = parseFloat(config.Spacing);
const width = config['Pen width'];
const step = config['Z steps'];
const getPixel = pixelProcessor(config, pixData)
let r = 5;
let a = 0;
const cx = config.width/2;
const cy = config.height/2;
let points = [];
points.push([cx,cy])
let x = cx, y = cy;
let radius = 1;
let theta = 0;
while ( x>0 && y>0 && x<config.width && y<config.height ) {
z = getPixel( x , y )
let w = Math.round(z * step / 255) * width / step;
let tempradius = radius;
points.push([
cx + tempradius*Math.sin(theta) ,
cy + tempradius*Math.cos(theta) ,
w
])
let incr = Math.asin(1/radius);
radius +=incr*spacing;
theta +=incr;
x = Math.floor( cx + radius*Math.sin(theta))
y = Math.floor( cy + radius*Math.cos(theta))
}
postLines(points);
}