-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrid.pde
45 lines (40 loc) · 1.41 KB
/
Grid.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
int w = 1280, h = 720, cols, rows, scl = 20, gridAmp, gridFill;
int gridStroke = color(0, 255, 0);
float[][] terrain;
float flying, spinX, spinY, spinXspeed, damp;
boolean gridPulse, gridSpin, vibrate;
void grid() {
// Grid topography and movement
gridAmp *= 0.99;
float yoff = flying;
flying -= 0.05;
for (int y = 0; y < rows; y++) {
float xoff = 0;
for (int x = 0; x < cols; x++) {
terrain[x][y] = map(noise(xoff, yoff), 0, 1, gridAmp, -gridAmp); // Map noise to 2D array.
xoff += 0.05;
}
yoff += 0.05;
}
// Grid colours and rotation
// Move rotation point to centre of plane
translate(width/2, height/2);
rotateX(QUARTER_PI); // Angle landscape to begin (might be nice to start without this, perhaps introduce the title and spin after elements).
rotateX(spinX); // Slowly spin plane
rotateY(spinY); // Leave for random angle flash.
if (gridSpin) spinX += spinXspeed;
// Draw triangle grid
translate(-w/2, -h/2);
stroke(gridStroke);
fill(gridFill);
for (int y = 0; y < rows-1; y++) {
beginShape(TRIANGLE_STRIP);
for (int x = 0; x < cols; x++) {
vertex(x * scl, y * scl, terrain[x][y]);
vertex(x * scl, (y + 1) * scl, terrain[x][y + 1]);
}
endShape();
}
if (gridPulse) gridStroke = color((sin(frameCount * 0.3) * 63) + 192, 0, 0, 255); // Sine pulse red, with a depth offset.
translate(w/2, 0);
}