-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsilkCircular.js
72 lines (52 loc) · 1.86 KB
/
silkCircular.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
var ctx;
var width = 512;
var height = 512;
var i, j;
var offsetX, offsetY;
var time;
var lin;
var r1, g1, b1;
var r2, g2, b2;
var pointer;
function setup() {
var container = document.getElementById("container");
ctx = PNX.createCanvas(container, {
width: width,
height: height,
},
1
)[0];
ctx.lineWidth = 1;
//ctx.lineCap = "round";
//ctx.lineJoin = "round";
ctx.fillStyle = "black";
ctx.fillRect(0,0,width, height);
ctx.globalAlpha = 0.04;
ctx.globalCompositeOperation = "lighter";
offsetX = 100*Math.random();
offsetY = 100*Math.random();
r1 = Math.floor(256*Math.random());
g1 = Math.floor(256*Math.random());
b1 = Math.floor(256*Math.random());
r2 = Math.floor(256*Math.random());
g2 = Math.floor(256*Math.random());
b2 = Math.floor(256*Math.random());
time = 0;
lin = 0;
}
function loop() {
//ctx.clearRect(0,0,width, height);
if(time < Math.PI*2) {
ctx.strokeStyle = "#" + Math.floor(PNX.lerp(r2, r1, lin)).toString(16) + Math.floor(PNX.lerp(g2, g1, lin)).toString(16) + Math.floor(PNX.lerp(b2, b1, lin)).toString(16);
ctx.beginPath();
pointer = PNX.vector.fromPolar(PNX.map(PNX.noise2D(offsetX + 2*Math.cos(0), 0.5*Math.sin(0) + time, 2), 0, 1, 0, 0.5*width), 0).add(PNX.vector(0.5*width, 0.5*height));
ctx.moveTo(pointer.x, pointer.y);
for(i = 1; i <= width; i += 1) {
pointer = PNX.vector.fromPolar(PNX.map(PNX.noise2D(offsetX + 2*Math.cos(i/width*2*Math.PI), 0.5*Math.sin(i/width*2*Math.PI) + time, 2), 0, 1, 0, 0.5*width), i/width*2*Math.PI).add(PNX.vector(0.5*width, 0.5*height));
ctx.lineTo(pointer.x, pointer.y);
}
ctx.stroke();
time += 0.005;
lin = 0.5*(Math.sin(time) + 1);
}
}