import controlP5.*; import com.processinghacks.arcball.*; import processing.opengl.*; ControlP5 controlP5; ControlWindow controlWindow; float translateX = 40; float rotateX = QUARTER_PI; float scale = 1.1; int numberOfBoxes = 10; void setup(){ size(400,400,P3D); controlP5 = new ControlP5(this); controlP5.hide(); controlWindow = controlP5.addControlWindow("My Sketch Parameters",200,200); Controller mySlider = controlP5.addSlider("translateX",0,100,translateX,40,40,100,10); mySlider.setWindow(controlWindow); Controller mySlider2 = controlP5.addSlider("rotateX",0,PI,rotateX,40,70,100,10); mySlider2.setWindow(controlWindow); Controller mySlider3 = controlP5.addSlider("numberOfBoxes",0,30,numberOfBoxes,40,100,100,10); mySlider3.setWindow(controlWindow); Controller mySlider4 = controlP5.addSlider("scale",0.7,1.3,scale,40,130,100,10); mySlider4.setWindow(controlWindow); new ArcBall(this); noStroke(); } void draw(){ lights(); background(200); translate(width/2, height/2, -height/2); //calculate the size of the grid according to //thenumber of boxes and the translation value float gridsize = numberOfBoxes*translateX; //use this value to center the grid translate( -gridsize/2, -gridsize/2 ); for(int x = 0; x < numberOfBoxes;x++){ for(int y = 0; y < numberOfBoxes;y++){ pushMatrix(); //translate to gridposition translate(translateX*x,translateX*y,0); //rotate according to to x and y //values are devided by numberofboxes so that the //angles do not get to big rotateX(x/(float)numberOfBoxes*rotateX); rotateY(y/(float)numberOfBoxes*rotateX); //scale according to the sin of the x and y //this way we create a wave pattern scale( scale*map(sin(x/(float)numberOfBoxes*TWO_PI),-1,1,0.5,2)+ scale*map(sin(y/(float)numberOfBoxes*TWO_PI),-1,1,0.5,2) ); pyramide(20); popMatrix(); } } } float radius = 100; float resolution = 20; float depth = -100; /** * Function to draw a pyramide **/ void pyramide(float scale){ float x1 = 0, y1 = 0.5 * scale, z1 = 0; float x2 = 0, y2 = -0.5 * scale, z2 = 0.5 * scale; float x3 = 0.5 * scale, y3 = -0.5 * scale, z3 = -0.5 * scale; float x4 = -0.5 * scale, y4 = -0.5 * scale, z4 = -0.5 * scale; scale(0.05); // Hier ist Die KONTUR beginShape(TRIANGLE_STRIP); fill(255); vertex(200,0); vertex(200,0,depth); vertex(200,60); vertex(200,60,depth); vertex(250,60); vertex(250,60,depth); vertex(250,0); vertex(250,0,depth); endShape(); beginShape(TRIANGLE_STRIP); vertex(-100,0); vertex(-100,0,depth); vertex(-100,-80); vertex(-100,-80,depth); vertex(-50,-80); vertex(-50,-80,depth); vertex(-50,0); vertex(-50,0,depth); endShape(); beginShape(TRIANGLE_STRIP); for(int i = 0; i <= resolution;i++){ float angle = i/resolution * PI; float x = radius * cos(angle); float y = radius * sin(angle); vertex(x,y); vertex(x,y,depth); } endShape(); beginShape(TRIANGLE_STRIP); for(int i = 0; i <= resolution;i++){ float angle = i/resolution * PI; float x = radius * cos(angle)/2; float y = radius * sin(angle)/2; vertex(x,y); vertex(x,y,depth); //println(i+" : "+angle+" : "+" : "+x+" : "+y); } endShape(); beginShape(TRIANGLE_STRIP); for(int i = 0; i <= resolution;i++){ float angle = -i/resolution * PI; float x = 150+ radius * cos(angle); float y = radius * sin(angle); vertex(x,y); vertex(x,y,depth); //println(i+" : "+angle+" : "+" : "+x+" : "+y); } endShape(); beginShape(TRIANGLE_STRIP); for(int i = 0; i <= resolution;i++){ float angle = -i/resolution * PI; float x = 150 + radius * cos(angle)/2; float y = radius * sin(angle)/2; vertex(x,y); vertex(x,y,depth); //println(i+" : "+angle+" : "+" : "+x+" : "+y); } endShape(); // Hier ist Die FLÄCHE beginShape(TRIANGLE_STRIP); for(int i = 0; i <= resolution;i++){ float angle = i/resolution * PI; float x = radius * cos(angle); float y = radius * sin(angle); float xt = radius * cos(angle)/2; float yt = radius * sin(angle)/2; vertex(x,y); vertex(xt,yt); } endShape(); beginShape(TRIANGLE_STRIP); for(int i = 0; i <= resolution;i++){ float angle = -i/resolution * PI; float x = 150 + radius * cos(angle); float y = radius * sin(angle); float xt = 150 + radius * cos(angle)/2; float yt = radius * sin(angle)/2; vertex(x,y); vertex(xt,yt); } endShape(); beginShape(TRIANGLE_STRIP); vertex(200,0); vertex(200,60); vertex(250,60); vertex(200,0); vertex(250,0); endShape(); beginShape(TRIANGLE_STRIP); vertex(-100,0); vertex(-100,-80); vertex(-50,0); vertex(-50,-80); vertex(-50,0); endShape(); // Hier ist Die FLÄCHE IN DER TIEFE beginShape(TRIANGLE_STRIP); for(int i = 0; i <= resolution;i++){ float angle = i/resolution * PI; float x = radius * cos(angle); float y = radius * sin(angle); float xt = radius * cos(angle)/2; float yt = radius * sin(angle)/2; vertex(x,y,depth); vertex(xt,yt,depth); } endShape(); beginShape(TRIANGLE_STRIP); for(int i = 0; i <= resolution;i++){ float angle = -i/resolution * PI; float x = 150 + radius * cos(angle); float y = radius * sin(angle); float xt = 150 + radius * cos(angle)/2; float yt = radius * sin(angle)/2; vertex(x,y,depth); vertex(xt,yt,depth); } endShape(); beginShape(TRIANGLE_STRIP); vertex(200,0,depth); vertex(200,60,depth); vertex(250,60,depth); vertex(200,0,depth); vertex(250,0,depth); endShape(); beginShape(TRIANGLE_STRIP); vertex(-100,0,depth); vertex(-100,-80,depth); vertex(-50,0,depth); vertex(-50,-80,depth); vertex(-50,0,depth); endShape(); }