-
Notifications
You must be signed in to change notification settings - Fork 0
/
Waves.js
80 lines (68 loc) · 1.3 KB
/
Waves.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
73
74
75
76
77
78
79
80
var s;
var g_width;
var g_height
var w = [];
function init_w(){
for (let x = 0; x < g_width; x++){
w[x] = [];
for (let y = 0; y < g_height; y++){
w[x][y] = random(0, 0.05);
}
}
}
function draw_w(){
for (let x = 0; x < g_width; x++){
for (let y = 0; y < g_height; y++){
fill(150, 128, (w[x][y] * 128) + 128);
square(x*s, y*s, s);
}
}
}
function update_w(){
var e;
var l;
var u;
for (let xb = 0; xb < g_width; xb++){
w[xb][g_height - 1] += random(0.05);
}
for (let yb = 0; yb < g_height; yb++){
w[g_width - 1][yb] += random(0.05);
}
for (let x = 0; x < g_width; x++){
for (let y = 0; y < g_height; y++){
if (w[x][y] > 0){
e = w[x][y] * random(0, 1);
w[x][y] = w[x][y] - e;
l = e * random(0, 1);
u = e - l;
if(x > 0 && y > 0){
w[x-1][y] += l;
w[x][y-1] += u;
}
}
if(w[x][y] < 0){
w[x][y] = 0;
}
if(w[x][y] > 1){
w[x][y] = 1;
}
if(random(0, 1) > 0.999){
w[x][y] = 1;
}
}
}
}
function setup() {
createCanvas(400, 400);
colorMode(HSB, 256)
noStroke();
s = 5;
g_width = width/s;
g_height = height/s;
init_w();
}
function draw() {
background(220);
draw_w();
update_w();
}