forked from mitxela/plotterfun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spiral.js
55 lines (38 loc) · 1.21 KB
/
spiral.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: 'Frequency', value: 150, min: 5, max: 256},
{label: 'Amplitude', value: 1, min: 0.1, max: 5, step: 0.1},
{label: 'Spacing', value: 1, min: 0.5, max: 5, step: 0.1},
])]);
onmessage = function(e) {
const [ config, pixData ] = e.data;
const spacing = parseFloat(config.Spacing);
const amplitude = parseFloat(config.Amplitude);
const frequency = parseInt(config.Frequency);
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 )
r = amplitude * z *0.02*spacing;
a += z / frequency;
let tempradius = radius + Math.sin(a)*r;
points.push([
cx + tempradius*Math.sin(theta) ,
cy + tempradius*Math.cos(theta)
])
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);
}