-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsilkLinear.js
68 lines (49 loc) · 1.51 KB
/
silkLinear.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
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;
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.06;
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();
ctx.moveTo(0, PNX.map(PNX.noise2D(0, time)));
for(i = 0; i < width; i += 1) {
ctx.lineTo(i, PNX.map(PNX.noise2D(i*0.004 + offsetX, time), 0, 1, 0, height), 1, 1);
}
ctx.stroke();
time += 0.008;
lin = 0.5*(Math.sin(time) + 1);
}
}