-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoisson.js
72 lines (52 loc) · 1.73 KB
/
poisson.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, back;
var width = 512;
var height = 512;
var i, j;
var p;
var offsetX, offsetY;
var time;
var color, complement;
function setup() {
var container = document.getElementById("container");
var ctxA = PNX.createCanvas(container, {
width: width,
height: height,
},
2
);
ctx = ctxA[0];
back = ctxA[1];
color = PNX.color("#0b24ad");
complement = color.complement().lighten(20).saturate(40);
back.fillStyle = color.toHexString();
ctx.fillStyle = complement.toHexString();
var n = PNX.blueNoise(PNX.vector(0,0), width, height, 30, 30);
offsetX = 100*Math.random();
offsetY = 100*Math.random();
p = [];
for(i = 0; i < n.length; i += 1) {
p.push(PNX.point(ctx, n[i]));
}
time = 0;
back.fillRect(0, 0, width, height);
}
function loop() {
back.fillRect(0, 0, width, height);
ctx.clearRect(0, 0, width, height);
for(i = 0; i < p.length; i += 1) {
var noise = PNX.noise3D(p[i].position.x/width*2 + offsetX, p[i].position.y/height*2 + offsetY, time, 2, 0.8);
if(noise > 0.3) {
back.fillStyle = color.toHexString();
ctx.fillStyle = PNX.color.mix(complement, color, Math.round(PNX.map(PNX.vector(PNX.mouseX, PNX.mouseY).distance(p[i].position), 0, 200, 0, 100)));
ctx.beginPath();
ctx.arc(p[i].position.x, p[i].position.y, PNX.map(noise, 0.3, 1, 0, 25), 0, 2*Math.PI);
ctx.closePath();
ctx.fill();
}
}
time += 1/120;
}
function keyPressed() {
color.spin(PNX.random(20, 180));
complement = color.complement().lighten(20).saturate(40);
}