33// http://pyopengl.sourceforge.net/context/tutorials/shader_4.html
44
55PShader sh;
6+ PShape grid;
67
78void setup () {
89 size (640 , 360 , P3D );
910 sh = loadShader(" frag.glsl" , " vert.glsl" );
1011 shader(sh);
11- noStroke ();
12+
13+ grid = createShape();
14+ grid. beginShape(QUADS );
15+ grid. noStroke();
16+ grid. fill(150 );
17+ float d = 10 ;
18+ for (int x = - 500 ; x < 500 ; x += d) {
19+ for (int y = - 500 ; y < 500 ; y += d) {
20+ grid. fill(255 * noise (x, y));
21+ grid. attribPosition(" tweened" , x, y, 100 * noise (x, y));
22+ grid. vertex(x, y, 0 );
23+
24+ grid. fill(255 * noise (x + d, y));
25+ grid. attribPosition(" tweened" , x + d, y, 100 * noise (x + d, y));
26+ grid. vertex(x + d, y, 0 );
27+
28+ grid. fill(255 * noise (x + d, y + d));
29+ grid. attribPosition(" tweened" , x + d, y + d, 100 * noise (x + d, y + d));
30+ grid. vertex(x + d, y + d, 0 );
31+
32+ grid. fill(255 * noise (x, y + d));
33+ grid. attribPosition(" tweened" , x, y + d, 100 * noise (x, y + d));
34+ grid. vertex(x, y + d, 0 );
35+ }
36+ }
37+ grid. endShape();
1238}
1339
1440void draw () {
@@ -20,27 +46,5 @@ void draw() {
2046 rotateX (frameCount * 0.01 );
2147 rotateY (frameCount * 0.01 );
2248
23- fill (150 );
24- beginShape (QUADS );
25- float d = 10 ;
26- for (int x = - 500 ; x < 500 ; x += d) {
27- for (int y = - 500 ; y < 500 ; y += d) {
28- fill (255 * noise (x, y));
29- attribPosition(" tweened" , x, y, 100 * noise (x, y));
30- vertex (x, y, 0 );
31-
32- fill (255 * noise (x + d, y));
33- attribPosition(" tweened" , x + d, y, 100 * noise (x + d, y));
34- vertex (x + d, y, 0 );
35-
36- fill (255 * noise (x + d, y + d));
37- attribPosition(" tweened" , x + d, y + d, 100 * noise (x + d, y + d));
38- vertex (x + d, y + d, 0 );
39-
40- fill (255 * noise (x, y + d));
41- attribPosition(" tweened" , x, y + d, 100 * noise (x, y + d));
42- vertex (x, y + d, 0 );
43- }
44- }
45- endShape ();
49+ shape (grid);
4650}
0 commit comments