Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 57 lines (42 sloc) 0.941 kB
a6b64d8 @potatono Refactored everything into separate classes.
potatono authored
1 class Wave {
2 private float a;
3 private float f;
4 private float r;
5 private int y;
6 private boolean t;
7 private float s;
8
9 PGraphics g;
10
11 color c;
12
13 public Wave() {
14 init();
15
16 g = createGraphics(WIDTH, HEIGHT, P2D);
17 }
18
19 public void init() {
20 r = random(TWO_PI);
21 f = PI/32 + random(PI/32);
22 a = HEIGHT/3 + random(HEIGHT/3);
23 y = HEIGHT/8 + int(random(HEIGHT - HEIGHT/8));
24 s = PI/128 + random(PI/64);
25
26 if (random(10)<5) {
27 s = -s;
28 }
29
30 c = color(random(255), random(255), random(255));
31 }
32
33 public void draw() {
34 float step;
35 float h;
36
37 r = r + s;
38 if (r > TWO_PI) r = r - TWO_PI;
39
40 step = r;
41
42 g.beginDraw();
43 g.background(0);
44 g.stroke(c);
45
46 for (int x=0; x<WIDTH; x++) {
47 h = sin(step) * a;
48 step = step + f;
49 g.line(x, y, x, y+h);
50 }
51
52 g.endDraw();
53
54 blend(g, 0, 0, WIDTH, HEIGHT, 0, 0, WIDTH, HEIGHT, SCREEN);
55 }
56 }
Something went wrong with that request. Please try again.