-
Notifications
You must be signed in to change notification settings - Fork 0
/
Landscape.pde
48 lines (48 loc) · 1.13 KB
/
Landscape.pde
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
/*
Infinite Scrolling Landscape by Bryan J. Cera
https://www.openprocessing.org/sketch/194607
*/
class Landscape {
Horizon[] points = new Horizon[1000];
int left, right;
int timer = 0;
float yy;
float shade;
float res;
Landscape(int b, float s, float r) {
res = r;
shade = s;
for (int i = 0; i < points.length; i++) {
float j = map(i, 0, points.length, 0, width);
points[i] = new Horizon(j, b, i);
}
}
void update(float speedx) {
timer-=3;
if (timer < 0) {
yy = random(-75, 75);
timer = int(random(25, 200));
}
for (int i = 0; i < points.length; i++) {
points[i].update(yy,speedx,res);
}
}
void display() {
pushMatrix();
scale(1.5, 1);
translate((-width/points.length)*2,0);
noStroke();
fill(75-shade,165-shade,70-shade);
beginShape();
for (int i = 0; i < points.length; i++) {
vertex(points[i].x, points[i].y);
if (points[i].x >= width-(width/points.length)-1) {
vertex(width, height*2);
vertex(0, height*2);
}
}
vertex(points[0].x, points[0].y);
endShape();
popMatrix();
}
}