import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; import java.util.Date; Minim minim; AudioOutput out, out2, out3, out4; SineWave G3, Bflat3, D4, note; Date date, date2; float[] freqArray; int earthSetup = 0, evolutionSetup = 0, volcanoSetup = 0, caveSetup = 0, citySetup = 0, gearsSetup = 0; int numNotes = 8, noteUsed = 0, noteNow; float noteTempo = 1000; //Starting tempo is one note per second int sceneLength = 20000; // 12 seconds long time, time2; void setup(){ size(600,400,OPENGL); date = new Date(); time = date.getTime(); freqArray = new float[numNotes]; freqArray[0] = 392.00; freqArray[1] = 440.00; freqArray[2] = 466.16; freqArray[3] = 523.25; freqArray[4] = 587.33; freqArray[5] = 622.25; freqArray[6] = 698.46; freqArray[7] = 783.99; minim = new Minim(this); out = minim.getLineOut(Minim.MONO); out2 = minim.getLineOut(Minim.MONO); out3 = minim.getLineOut(Minim.MONO); out4 = minim.getLineOut(Minim.MONO); G3 = new SineWave(196.00, 0.5, out.sampleRate()); Bflat3 = new SineWave(233.08, 0.4, out.sampleRate()); D4 = new SineWave(293.66, 0.45, out.sampleRate()); note = new SineWave(293.66, 0.4, out.sampleRate()); out.addSignal(G3); out2.addSignal(Bflat3); out3.addSignal(D4); out4.addSignal(note); } void draw(){ date2 = new Date(); time2 = date2.getTime(); if(time2-time >= noteTempo){ noteNow = int(random(numNotes)); if(noteNow == noteUsed){ if(noteNow < 4){ noteNow = noteNow+1; } else{ noteNow = noteNow-1; } note.setFreq(freqArray[noteNow]); noteUsed = noteNow; } else{ note.setFreq(freqArray[noteNow]); noteUsed = noteNow; } time = time2; } if(millis() < sceneLength){ if(earthSetup == 0){ setupEarth(); earthSetup++; } drawEarth(); } else if((millis() >= sceneLength) && (millis() < sceneLength*3)){ if(evolutionSetup == 0){ setupEvolution(); evolutionSetup++; } drawEvolution(); noteTempo = 875; } else if((millis() >= sceneLength*3) && (millis() < sceneLength*4)){ if(volcanoSetup == 0){ setupVolcano(); volcanoSetup++; } drawVolcano(); noteTempo = 750; } else if((millis() >= sceneLength*4) && (millis() < sceneLength*5)){ if(caveSetup == 0){ setupCave(); caveSetup++; } drawCave(); noteTempo = 625; } else if((millis() >= sceneLength*5) && (millis() < sceneLength*6)){ if(citySetup == 0){ setupCity(); citySetup++; } drawCity(); noteTempo = 500; } else{ if(gearsSetup == 0){ setupGears(); gearsSetup++; } drawGears(); noteTempo = 375; } } void stop() { super.stop(); minim.stop(); out.close(); } import processing.opengl.*; float spin = 0.0; PFont font; void setupEarth() { size(600, 400, OPENGL); noStroke(); font = loadFont("EarthquakeMF-48.vlw"); textFont(font,48); colorMode(RGB); } void drawEarth() { background(0); spin += 0.03; lights(); ambient(100-spin*15,10,10); emissive(150-spin*20,10,10); lightFalloff(0.6,0.0,0.0); specular(0,0,255); pushMatrix(); translate(width/2, height/2, 0); rotateY(PI/5+spin); fill(120,10+spin*50,0+spin*10); pointLight(150-spin*21, 20, 210, -50, 300, -100); pointLight(200-spin*12, 10, 210, 70, -15, 130); pointLight(80-spin*12, 5, 110,130, 40, 50); pointLight(120-spin*13, 0, 100, 160, -30, -75); pointLight(210-spin*15,0,100,-20,-290,120); pointLight(120-spin*20, 5, 135, -320, -35, 50); sphereDetail(75); sphere(100); popMatrix(); text (("EPOCH"),211,60,10); loop(); } int motion; PFont treb; PFont small; float xpos; float ypos; float drag = random(20,45); void setupEvolution(){ size(600,400, OPENGL); smooth(); frameRate(50); treb = loadFont("TrebuchetMS-Bold-14.vlw"); small = loadFont("TrebuchetMS-10.vlw"); smooth(); } class Tadpole { Tadpole(float x, float y){ stroke(0); fill(120, 230, 130); beginShape(); vertex(x-32, y+10); vertex(x-24, y+3); vertex(x-16, y+5); vertex(x-12, y); vertex(x-4, y); vertex(x, y+5); vertex(x, y+15); vertex(x-4, y+20); vertex(x-12, y+20); vertex(x-16,y+15); vertex(x-24, y+17); vertex(x-32, y+10); endShape(); fill(255); ellipse(x-8, y+5, 3, 3); } } class Fish { Fish(float x, float y){ stroke(0); fill(180, 210, 120); beginShape(); vertex(x-35, y+20); vertex(x-27, y+23); vertex(x-18,y+28); vertex(x-20, y+30); vertex(x-15, y+30); vertex(x-14, y+28); vertex(x, y+20); vertex(x-7, y+12); vertex(x-15, y+7); vertex(x-22, y); vertex(x-20, y+12); vertex(x-35, y+20); endShape(); fill(255); ellipse(x-10, y+14, 4, 4); } } class Frog{ Frog(float x, float y){ stroke(0); fill(220, 200, 100); beginShape(); vertex(x-40, y+14); vertex(x-35, y+20); vertex(x-29, y+18); vertex(x-25, y+24); vertex(x-27, y+28); vertex(x-23, y+36); vertex(x-19, y+36); vertex(x-19, y+32); vertex(x-23, y+28); vertex(x-19, y+32); vertex(x-16, y+28); vertex(x-14, y+20); vertex(x-19, y+16); vertex(x-14, y+20); vertex(x-15, y+26); vertex(x-5, y+26); vertex(x, y+20); vertex(x-5, y+20); vertex(x, y+20); vertex(x, y+12); vertex(x-5, y+8); vertex(x-10, y+4); vertex(x-12, y); vertex(x-19, y); vertex(x-32, y+12); vertex(x-38, y+12); vertex(x-40, y+14); endShape(); fill(255); ellipse(x-7, y+12, 4, 4); } } class Lizard { Lizard(float x, float y){ stroke(0); fill(240, 170, 100); beginShape(); vertex(x-48, y+12); vertex(x-46, y+16); vertex(x-40, y+18); vertex(x-32, y+16); vertex(x-28, y+20); vertex(x-30, y+25); vertex(x-22, y+25); vertex(x-25, y+23); vertex(x-22, y+20); vertex(x-24, y+14); vertex(x-22, y+20); vertex(x-17, y+18); vertex(x-16, y+16); vertex(x-17, y+18); vertex(x-15, y+25); vertex(x-12, y+25); vertex(x-13, y+20); vertex(x-12, y+16); vertex(x-13, y+18); vertex(x-2, y+20); vertex(x, y+16); vertex(x-2, y+12); vertex(x-14, y+2); vertex(x-22, y); vertex(x-28, y+2); vertex(x-40, y+14); vertex(x-48, y+12); endShape(); fill(255); ellipse(x-7, y+12, 4, 4); } } class Rocks { Rocks(int x, int y){ stroke(0); fill(190); beginShape(); vertex(x, y+290); vertex(x-10, y+300); vertex(x-20, y+290); vertex(x-30, y+290); vertex(x-40, y+300); vertex(x-60, y+300); vertex(x-80, y+310); vertex(x-100, y+310); vertex(x-120, y+325); vertex(x-130, y+320); vertex(x-160, y+325); vertex(x-180, y+330); vertex(x-220, y+350); vertex(x-240, y+350); vertex(x-250, y+360); vertex(x-270, y+360); vertex(x-290, y+365); vertex(x-300, y+370); vertex(x-320, y+370); vertex(x-340, y+365); vertex(x-360, y+385); vertex(x-380, y+390); vertex(x-390, y+400); vertex(x, y+400); vertex(x, y+290); endShape(); } } class Plant{ Plant(int x, int y){ stroke(0); fill(30, 230, 140); beginShape(); vertex(x, y+15); vertex(x+8, y+10); vertex(x+11, y+5); vertex(x+19, y); vertex(x+11, y); vertex(x+16, y-10); vertex(x+8, y-5); vertex(x+11, y-15); vertex(x+3, y-5); vertex(x, y-25); vertex(x-3, y-5); vertex(x-11, y-15); vertex(x-8, y-5); vertex(x-16, y-10); vertex(x-11,y); vertex(x-19, y); vertex(x-11, y+5); vertex(x-8, y+10); vertex(x, y+15); endShape(); } } class Sign{ Sign(int x, int y){ stroke(0); fill(230, 230, 140); rect(x-30, y-50, 60, 30); rect(x-5, y-60, 10, 10); beginShape(); vertex(x-5, y-20); vertex(x-5, y+10); vertex(x, y+15); vertex(x+5, y+10); vertex(x+5, y-20); vertex(x-5, y-20); endShape(); textFont(treb); fill(0); text(("LAND"), x-18, y-35); beginShape(); vertex(x-15, y-25); vertex(x+15, y-25); vertex(x+12, y-22); vertex(x+15, y-25); vertex(x+12, y-28); vertex(x+15, y-25); endShape(); } } class Land{ Land(){ noStroke(); fill(20, 170, 240); rect(0,0,600, 200); fill(40, 230, 140); beginShape(); vertex(50, 200); vertex(250, 400); vertex(600, 400); vertex(600, 200); endShape(); fill(80, 40, 30); beginShape(); vertex(225, 200); vertex(290, 160); vertex(310, 180); vertex(380, 120); vertex(450, 170); vertex(540, 80); vertex(600, 150); vertex(600, 200); endShape(); fill(230, 230,0); ellipse(75, 75, 50, 50); fill(240, 210, 0, 50); ellipse(75, 75, 85, 85); } } class Years{ Years(int x, int y){ textFont(small); fill(0); text(("years elapsed: " + motion*40), x, y); } } void drawEvolution(){ float difx = mouseX - xpos-10; if(abs(difx) > 1.0) { xpos = xpos + difx/drag; xpos = constrain(xpos, 0, width-20); } float dify = mouseY - ypos-10; if(abs(dify) > 1.0) { ypos = ypos + dify/drag; ypos = constrain(ypos, 0, height-20); } if(motion < 500){ background(20, 130, 210); Rocks r = new Rocks(600, 0); Tadpole[] rayT = new Tadpole[4]; rayT[0] = new Tadpole(mouseX-20, ypos+20); rayT[1] = new Tadpole(xpos-52, mouseY-16); rayT[2] = new Tadpole(xpos-85, ypos+16); rayT[3] = new Tadpole(mouseX-125, mouseY-22); } else if (motion>500 && motion<1000){ background(20, 130, 210); Rocks r = new Rocks(600, 0); Fish[] rayF = new Fish[4]; Plant[] rayP = new Plant[3]; rayP[0] = new Plant(250, 375); rayP[1] = new Plant(400, 330); rayP[2] = new Plant(550, 350); rayF[0] = new Fish(mouseX-20, ypos+20); rayF[1] = new Fish(xpos-52, mouseY-16); rayF[2] = new Fish(xpos-85, ypos+16); rayF[3] = new Fish(mouseX-125, mouseY-22); } else if (motion>1000 && motion<1500) { background(20, 130, 210); Rocks r = new Rocks(600, 0); Frog[] rayR = new Frog[4]; Plant[] rayP = new Plant[6]; Sign sign = new Sign(500, 305); rayP[0] = new Plant(250, 375); rayP[1] = new Plant(400, 330); rayP[2] = new Plant(550, 350); rayP[3] = new Plant(575, 310); rayP[4] = new Plant(190, 390); rayP[5] = new Plant(480, 365); rayR[0] = new Frog(mouseX-20, ypos+20); rayR[1] = new Frog(xpos-52, mouseY-16); rayR[2] = new Frog(xpos-85, ypos+16); rayR[3] = new Frog(mouseX-125, mouseY-22); } else if (motion>=1500){ background(20, 130, 210); Land m = new Land(); Lizard[] rayL = new Lizard[2]; rayL[0] = new Lizard(xpos-20, 250); rayL[1] = new Lizard(ypos+35, 275); } Years q = new Years(10, 390); } void mouseMoved(){ motion++; redraw(); } ArrayList fireball; void setupVolcano() { size(600,400, OPENGL); frameRate(30); colorMode(RGB,255,255,255,100); fireball = new ArrayList(); smooth(); } void drawVolcano() { background(80, 160, 220); Mountain volcano = new Mountain(); for (int i = fireball.size()-1; i >= 0; i--) { System psys = (System) fireball.get(i); psys.run(); if (psys.dead()) { fireball.remove(i); } } Grass field = new Grass(); Stegosaurus steg = new Stegosaurus(375, 385); Brontosaurus bron = new Brontosaurus(200, 340); if (mousePressed==true) { fireball.add(new System(int(random(5,10)),new Vector(300,110))); } } class Magma { Vector loc; Vector vel; Vector acc; float r; float timer; float theta = 0.0; Magma (Vector a, Vector v, Vector l, float r_) { acc = a.copy(); vel = v.copy(); loc = l.copy(); r = r_; timer = 100.0; } Magma (Vector l) { acc = new Vector(0.0,0.05); vel = new Vector(random(-1,1),random(-2,0)); loc = l.copy(); r = 10.0; timer = 100.0; } void run() { update(); render(); } void update() { vel.add(acc); loc.add(vel); timer -= 1.0; float theta_vel = (vel.x * vel.magnitude()) / 10.0f; theta += theta_vel; } void render() { ellipseMode(CENTER); noStroke(); fill(110, 10, 10, timer); ellipse(loc.x,loc.y,r,r); pushMatrix(); translate(loc.x,loc.y); rotate(theta); stroke(230, 80, 30, timer); line(0,7,0,-7); line(7,0,-7,0); line(0,0,5,5); line(0,0,5,-5); line(0,0,-5,-5); line(0,0,-5,5); popMatrix(); } boolean dead() { if (timer <= 0.0) { return true; } else { return false; } } } class System { ArrayList lava; Vector origin; System(int num, Vector v) { lava = new ArrayList(); origin = v.copy(); for (int i = 0; i < num; i++) { lava.add(new Magma(origin)); } } void run() { for (int i = lava.size()-1; i >= 0; i--) { Magma p = (Magma) lava.get(i); p.run(); if (p.dead()) { lava.remove(i); } } } void addParticle() { lava.add(new Magma(origin)); } void addParticle(Magma p) { lava.add(p); } boolean dead() { if (lava.isEmpty()) { return true; } else { return false; } } } public class Vector { public float x; public float y; Vector(float x_, float y_) { x = x_; y = y_; } public float magnitude() { return (float) Math.sqrt(x*x + y*y); } public Vector copy() { return new Vector(x,y); } public Vector copy(Vector v) { return new Vector(v.x, v.y); } public void add(Vector v) { x += v.x; y += v.y; } public float distance (Vector v1, Vector v2) { float dx = v1.x - v2.x; float dy = v1.y - v2.y; return (float) Math.sqrt(dx*dx + dy*dy); } } class Mountain { Mountain(){ fill(50, 25, 15); beginShape(); vertex(0,325); vertex(0,290); vertex(30,300); vertex(80,260); vertex(110,280); vertex(220,160); vertex(230,170); vertex(275,100); vertex(295,120); vertex(300,130); vertex(310,135); vertex(325,100); vertex(370,200); vertex(400,180); vertex(450,230); vertex(500,215); vertex(560,280); vertex(580,260); vertex(600,300); vertex(600,325); endShape(); fill(0); beginShape(); vertex(295,120); vertex(300,130); vertex(310,135); vertex(325,100); vertex(295,120); endShape(); noStroke(); fill(230, 230,0); ellipse(75, 75, 50, 50); fill(240, 210, 0, 30); ellipse(75, 75, 85, 85); } } class Grass { Grass(){ fill(60, 120, 40); noStroke(); beginShape(); vertex(0,325); vertex(0,400); vertex(600,400); vertex(600,325); endShape(); } } class Stegosaurus { Stegosaurus(int x, int y){ stroke(0); fill(120, 95, 40); beginShape(); vertex(x,y-35); vertex(x+5,y-39); vertex(x+15,y-39); vertex(x+20,y-35); vertex(x+30,y-45); vertex(x+45,y-48); vertex(x+55,y-48); vertex(x+70,y-44); vertex(x+80,y-30); vertex(x+90,y-12); vertex(x+100,y-16); vertex(x+90,y-9); vertex(x+75,y-20); vertex(x+70,y-16); vertex(x+70,y); vertex(x+60,y); vertex(x+60,y-3); vertex(x+63,y-5); vertex(x+63,y-9); vertex(x+60,y-16); vertex(x+45,y-12); vertex(x+35,y-17); vertex(x+30,y-5); vertex(x+30,y); vertex(x+23,y); vertex(x+23,y-3); vertex(x+25,y-5); vertex(x+25,y-20); vertex(x+15,y-24); vertex(x+10,y-30); vertex(x,y-30); vertex(x,y-35); endShape(); fill(0); beginShape(); vertex(x+23,y-39); vertex(x+23,y-46); vertex(x+29,y-44); endShape(); beginShape(); vertex(x+34,y-46); vertex(x+36,y-52); vertex(x+40,y-47); endShape(); beginShape(); vertex(x+43,y-48); vertex(x+50,y-60); vertex(x+54,y-48); endShape(); beginShape(); vertex(x+60,y-47); vertex(x+65,y-52); vertex(x+65,y-46); endShape(); beginShape(); vertex(x+73,y-42); vertex(x+79,y-44); vertex(x+77,y-35); endShape(); noStroke(); fill(255); ellipse(x+5,y-35,3,3); } } class Brontosaurus { Brontosaurus(int x, int y){ stroke(0); fill(20, 40, 50); beginShape(); vertex(x-75,y-24); vertex(x-70,y-16); vertex(x-70,y); vertex(x-60,y); vertex(x-60,y-3); vertex(x-63,y-5); vertex(x-63,y-9); vertex(x-60,y-16); vertex(x-45,y-12); vertex(x-35,y-17); vertex(x-30,y-5); vertex(x-30,y); vertex(x-23,y); vertex(x-23,y-3); vertex(x-25,y-5); vertex(x-20,y-20); vertex(x-15,y-24); vertex(x-5,y-48); vertex(x-3,y-70); vertex(x+5,y-70); vertex(x+5,y-75); vertex(x,y-80); vertex(x-8,y-80); vertex(x-14,y-48); vertex(x-23,y-39); vertex(x-30,y-40); vertex(x-45,y-43); vertex(x-55,y-43); vertex(x-70,y-39); vertex(x-100,y-25); vertex(x-120,y-32); vertex(x-100,y-20); vertex(x-75,y-24); endShape(); fill(255); ellipse(x, y-75,3,3); } } float noiseVal, noiseScale=0.01; float personWidth = 50, personHeight = 100, personX, personY; float turtleWidth = 80, turtleHeight = 50, turtleX, turtleY; color currColor; int personDrawn = 0, turtleDrawn = 0; void setupCave() { size(600, 400, OPENGL); cursor(HAND); ellipseMode(CORNER); smooth(); background(166,142,105); for(int y = 0; y < 400; y++) { for(int x = 0; x < 600; x++) { noiseDetail(8,0.6); noiseVal=noise( (x) * noiseScale, (y) * noiseScale ); stroke(noiseVal * 166 * 1.5, noiseVal * 142 * 1.5, noiseVal* 105 * 1.5); line(x,y,x+1,y+1); } } personX = random(personWidth,width)-personWidth; personY = random(personHeight,height)-personHeight; turtleX = random(turtleWidth,width)-turtleWidth; turtleY = random(turtleHeight,height)-turtleHeight; if((turtleX > personX) && (turtleX+turtleWidth < personX+personWidth)){ turtleX = turtleX - personWidth; if(turtleX < 0){ turtleX = turtleX + 300; } } if((turtleY > personY) && (turtleY+turtleHeight < personY+personHeight)){ turtleY = turtleY - personHeight; if(turtleY-20 < 0){ turtleY = turtleY + 200; } } currColor = color(202,105,26); colorMode(HSB); currColor = color(hue(currColor), saturation(currColor), brightness(currColor)-90); colorMode(RGB); } void drawCave() { if(mousePressed == true){ fill(143,19,16); paint(mouseX, mouseY, pmouseX, pmouseY); } fill(currColor); noStroke(); if(brightness(currColor) < brightness(color(202,105,26))){ colorMode(HSB); currColor = color(hue(currColor), saturation(currColor), brightness(currColor)+2); colorMode(RGB); if(personDrawn == 0){ drawPerson(personX,personY); } if(turtleDrawn == 1){ drawTurtle(turtleX,turtleY); } } else{ personDrawn++; turtleDrawn++; currColor = color(202,105,26); colorMode(HSB); currColor = color(hue(currColor), saturation(currColor), brightness(currColor)-90); colorMode(RGB); } loop(); } void paint(int x, int y, int px, int py) { float speed = abs(x-px) + abs(y-py); stroke(143,19,16); strokeWeight(5.5); line(x,y,px,py); } void drawPerson(float x, float y){ //Head ellipse(x,y,15,25); //Body ellipse(x-5,y+22,25,45); //Legs ellipse(x-2,y+22+40,8,22); ellipse(x-2+8+3,y+22+40,8,22); ellipse(x-2,y+22+40+20,7,20); ellipse(x-2+8+4,y+22+40+20,7,20); //Feet ellipse(x-2-10,y+22+40+20+18,15,6); ellipse(x-2+8+4+1,y+22+40+20+18,15,6); //Arms ellipse(x-5-17,y+22+4,22,7); ellipse(x+14,y+22+4,22,7); ellipse(x-5-18,y+7,6,22); ellipse(x+14+17,y+7,6,22); //Hands ellipse(x-5-20,y+2,8,8); ellipse(x+14+17,y+2,8,8); } void drawTurtle(float x, float y){ //Head ellipse(x,y,20,20); //Body ellipse(x+18,y-12,45,40); //Legs ellipse(x+24,y-24,8,15); ellipse(x+24+24,y-24,8,15); ellipse(x+24,y+24,8,15); ellipse(x+24+24,y+24,8,15); //Tail triangle(x+60,y+4,x+60+10,y+9,x+60,y+14); } int h; float c; float s; float theta; int tx; int th; float xval = 300/4.0; float randX; float randZ; float randC; float[] treeX = new float[40]; float[] treeZ = new float[40]; float[] treeC = new float[40]; PFont cityFont; void setupCity() { size (600,400,OPENGL); cursor(ARROW); randX = random(500); randZ = random(-200,500); cityFont = loadFont("TrebuchetMS-Bold-14.vlw"); textFont(cityFont, 20); for(int i=0; i < 40; i++) { treeX [i] = randX; treeZ [i] = randZ; treeC [i] = randC; randX = random(-400,900); randZ = random(-500,500); randC = random(40,150); } } void drawCity(){ camera(xval*4+100, height/2, (height/2.0) / tan(PI*60.0 / 360.0), width/2.0, height/2.0, 0, 0, 1, 0); frameRate(30); float a = ((tx)/ (float) width) * 90f; theta = radians(a); if (mouseX < 150) { h = 150; } else { h = mouseX; } if (mouseX < 150) { c = 0; } else { c = (mouseX*0.2); } if (mouseX < 30) { s = 0; } else { s = (mouseX*0.1); } lights(); background(c*1.5,c*1.5,250); fill(20); text (("Years Passed: " + mouseX/3),50,100,10); fill(255,165,0); //sun noStroke(); pushMatrix(); translate(width-150,100,10); sphere(40); popMatrix(); fill(0,0,255); pushMatrix(); translate(100,height+100+h/10,-80); sphere(180); popMatrix(); pushMatrix(); translate(0,height+80+h/10,-120); sphere(150); popMatrix(); fill(80); pushMatrix(); translate(100,height+100-h/11,-80); box(180); popMatrix(); pushMatrix(); translate(0,height+85-h/11,-120); box(150); popMatrix(); pushMatrix(); //building base translate(width/2,height,0); fill(90,c,c); stroke(60,c-30,c-30); box(92,h,30); popMatrix(); pushMatrix(); //building base 2 translate(width-100,height,-200); //rotateY(1); fill(c,c,30); stroke(c-30,c-30,30); box(200,h-150,40); popMatrix(); fill(70); ambientLight(100,100,100); stroke(100,100,100); beginShape(TRIANGLES); //roof1 vertex(width/2-45,height-75,13); vertex(width/2,height-110+s,13); vertex(width/2+45,height-75,13); vertex(width/2-45,height-75,13); vertex(width/2,height-110+s,13); vertex(width/2-45,height-75,-10); vertex(width/2+45,height-75,13); vertex(width/2,height-110+s,13); vertex(width/2+45,height-75,-10); endShape(CLOSE); fill(30); pushMatrix(); //door 1 stroke(30); translate(width/2,height-45,18); box(10,20,0); popMatrix(); pushMatrix(); //door 2 stroke(30); translate(width-100,height,-175); box(15,h/2-150,0); popMatrix(); pushMatrix(); //base windows fill(50); strokeWeight(0.5); //stroke(70); translate(width/2-25,height-60,11); box(15); popMatrix(); pushMatrix(); translate(width/2+25,height-60,11); box(15); popMatrix(); if (mouseX >230) { fill(50); stroke(30,30,30); pushMatrix(); translate(width/2-25,height-105,12); box(15); popMatrix(); pushMatrix(); translate(width/2+25,height-105,12); box(15); popMatrix(); } if (mouseX >310) { fill(50); stroke(30,30,30); pushMatrix(); translate(width/2-25,height-145,12); box(15); popMatrix(); pushMatrix(); translate(width/2+25,height-145,12); box(15); popMatrix(); } if (mouseX >390) { fill(50); stroke(30,30,30); pushMatrix(); translate(width/2-25,height-185,12); box(15); popMatrix(); pushMatrix(); translate(width/2+25,height-185,12); box(15); popMatrix(); pushMatrix(); translate(width-165,height-105,-180); box(35,45,15); popMatrix(); pushMatrix(); translate(width-45,height-105,-180); box(35,45,15); popMatrix(); } if (mouseX >470) { fill(50); stroke(30,30,30); pushMatrix(); translate(width/2-25,height-225,12); box(15); popMatrix(); pushMatrix(); translate(width/2+25,height-225,12); box(15) ; popMatrix(); } if (mouseX >550) { fill(50); stroke(30,30,30); pushMatrix(); translate(width/2-25,height-265,12); box(15); popMatrix(); pushMatrix(); translate(width/2+25,height-265,12); box(15) ; popMatrix(); pushMatrix(); translate(width-165,height-185,-180); box(35,45,15); popMatrix(); pushMatrix(); translate(width-45,height-185,-180); box(35,45,15); popMatrix(); } for(int i=0; i < 40; i++) { pushMatrix(); //tree if (mouseX < 550) { tx = 550-mouseX; strokeWeight(1.5) ; stroke(mouseX/3.5,treeC[i],0); } else { tx = 0; noStroke(); } translate(treeX[i],height - 30 + mouseX/5,treeZ[i]); line(0,0,0,-60); translate(0,-60); branch(60); popMatrix(); } pushMatrix(); //grass fill(0,100-mouseX/12,0); stroke(0,100,0); translate(300,height,40); box(1000,85,800); popMatrix(); loop(); } void branch(float h) { h *= 0.66f; if (h > 1) { pushMatrix(); rotate(theta); line(0,0,0,-h); translate(0,-h); branch(h); popMatrix(); pushMatrix(); rotate(-theta); line(0,0,0,-h); translate(0,-h); branch(h); popMatrix(); } } void keyPressed() { if (key == CODED) { if (keyCode == LEFT) { if (xval > 0){ xval --; } } if (keyCode == RIGHT) { if (xval < 150) { xval ++; } } } } float angle = 0.0; float gearSize, cogLength, cogWidth; Gear[] gearArray; Chain[] chainArray; int gearCount = 3, chainLinkCount = 20; float sval = 1.8; int fadeYellow = 0, fadeRed = 128; void setupGears(){ size(600,400,OPENGL); gearSize = 0.832*width/8; cogLength = 0.832*width/20; cogWidth = cogLength/2; camera(50*4+100, height/2, (height/2.0) / tan(PI*60.0 / 360.0), width/2.0, height/2.0, 0, 0, 1, 0); noStroke(); noSmooth(); fill(174,155,90); gearArray = new Gear[gearCount]; chainArray = new Chain[chainLinkCount]; gearArray[0] = new Gear(width/3,height/3,gearSize,cogWidth,cogLength,0,-0.010*4); gearArray[1] = new Gear(width/6-45,height/6,gearSize,cogWidth,cogLength,0,0.010*4); gearArray[2] = new Gear(width/3,height/3+250,gearSize,cogWidth,cogLength,0,-0.010*4); for(int i = 0; i < chainLinkCount/2; i++){ chainArray[i] = new Chain(gearArray[0].originX+gearArray[0].radius,gearArray[0].originY + 25*i,10,20); } for(int i = chainLinkCount/2; i < chainLinkCount; i++){ chainArray[i] = new Chain(gearArray[2].originX-gearArray[2].radius,gearArray[2].originY - 25*(i-chainLinkCount/2),10,20); } } void drawGears(){ background(0); fill(174,155,90); shininess(5.0); directionalLight(126, 126, 126, 0, 0, -1); ambientLight(152, 152, 152); lights(); // Translate, rotate and draw for (int i = 0; i < gearCount; i++){ pushMatrix(); gearArray[i].setAngle(gearArray[i].angle + gearArray[i].angleDelta); if(sval > 0.7){ sval -= 0.002*4; } scale(sval); translate(50,25,0); gearArray[i].drawGear(); popMatrix(); } fill(100); for (int i = 0; i < chainLinkCount; i++){ pushMatrix(); if(i < chainLinkCount/2){ chainArray[i].originY-= (1 - (gearArray[0].angleDelta*30)); if(chainArray[i].originY < gearArray[0].originY){ chainArray[i].originY = gearArray[2].originY; } } else{ chainArray[i].originY+= (1 - (gearArray[0].angleDelta*30)); if(chainArray[i].originY > gearArray[2].originY){ chainArray[i].originY = gearArray[0].originY; } } scale(sval); translate(50,25,0); chainArray[i].drawChainLink(); popMatrix(); } // Motherboard scale(sval); translate(50,25,0); fill(28,113,19); translate(600,250,-4); box(width/2,height,4); translate(-100,-50,4); fadeRed+=6; if(fadeRed >= 200){ fadeRed = 0; } fill(255-fadeRed,0,0); sphere(10); translate(0,-80,0); fadeYellow+=6; if(fadeYellow >= 200){ fadeYellow = 0; } fill(255-fadeYellow,255-fadeYellow,0); sphere(10); translate(90,0,0); fill(100); box(50,50,10); fill(50); box(30,30,15); translate(80,20,0); box(10,150,15); fill(0); box(5,140,15); fill(50); translate(20,0,0); box(10,150,15); fill(0); box(5,140,15); translate(25,-40,0); fill(200); ellipse(0,0,15,15); ellipse(20,0,15,15); translate(10,60,0); fill(0,0,200); box(20,70,15); fill(0,0,100); box(10,65,15); translate(-180,30,0); fill(200); ellipse(0,0,15,15); ellipse(20,0,15,15); ellipse(40,0,15,15); ellipse(60,0,15,15); ellipse(80,0,15,15); translate(20,80,0); ellipse(0,0,15,15); ellipse(20,0,15,15); ellipse(40,0,15,15); translate(0,50,0); box(140,20,15); fill(50); box(130,5,15); translate(0,30,0); fill(200); box(140,20,15); fill(50); box(130,5,15); translate(0,30,0); fill(200); box(140,20,15); fill(50); box(130,5,15); translate(100,20,0); fill(200); ellipse(0,0,15,15); ellipse(20,0,15,15); ellipse(40,0,15,15); translate(30,-80,0); ellipse(0,0,30,30); translate(0,-60,0); fill(50); box(30,30,10); translate(-40,20,0); box(30,30,10); translate(-600,-250,0); if(mousePressed == true){ int gearRef = 0; for(int i = 0; i < gearCount; i++){ if(dist(mouseX,mouseY,gearArray[i].originX,gearArray[i].originY) < gearArray[i].radius){ if(gearArray[i].angleDelta < 0){ gearArray[i].angleDelta -= .006*4; while(gearRef < gearCount){ if(gearRef != i){ if(gearArray[gearRef].angleDelta < 0){ gearArray[gearRef].angleDelta -= .006*4; } else{ gearArray[gearRef].angleDelta += .006*4; } } gearRef++; } } else{ gearArray[i].angleDelta += .006; while(gearRef < gearCount){ if(gearRef != i){ if(gearArray[gearRef].angleDelta < 0){ gearArray[gearRef].angleDelta -= .006*4; } else{ gearArray[gearRef].angleDelta += .006*4; } } gearRef++; } } } } } loop(); } public class Gear{ float originX, originY, radius, cogWidth, cogLength, angle, angleDelta; Gear(float originX, float originY, float radius, float cogWidth, float cogLength, float angle, float angleDelta){ this.originX = originX; this.originY = originY; this.radius = radius; this.cogWidth = cogWidth; this.cogLength = cogLength; this.angle = angle; this.angleDelta = angleDelta; } public void setAngle(float angleIn){ this.angle = angleIn; } public void drawGear(){ translate(originX, originY); rotateZ(angle); sphere(radius); translate(radius+cogWidth-.2,0); for(int i = 0; i < 16; i++){ box(cogLength,cogWidth,cogWidth); translate(-10,37); rotate(PI/6); } rotate(-15*PI/6); translate(-radius-cogWidth+.2,0); translate(-originX,-originY); } } public class Chain{ float originX, originY, linkWidth, linkHeight; Chain(float originX, float originY, float linkWidth, float linkHeight){ this.originX = originX; this.originY = originY; this.linkWidth = linkWidth; this.linkHeight = linkHeight; } public void drawChainLink(){ translate(originX, originY); box(linkWidth,linkHeight,linkWidth); translate(-originX, -originY); } }