20. Oktober 2011
Im Ersten Teil des Moduls erarbeiteten wirzusammen Teile des Processing (1.51) Syntax. Am ersten Tag erlernten wir neben dem Standardsetup die Grundlagen über die Anzeige sowie Farben, Attribute und Variablen. Am Zweiten Tag folgten Funktionen mit Parameter, Bewegungen, Bedingungen und Maus, Beziehungsweise Tastaturevents. Dazu kam eine erste Aufgabe: Über die Tastatur sollen verschiedene Smileys angezeigt werden. In einer Zweiten Aufgabe Sollte ein Smiley dynamisch um ein Zweites Smiley Rotieren, welches ich um weitere Smileys erweitert habe. Am dritten Tag lernten wir die Grundsätzliche Anwendung von "For"-, "While"- und "Do while"-Schleifen und anpassen der Matrix. Zudem erweiterten wir die Ausgabemöglichkeiten um PDF- und PNG- Screenshots. Mit diesen Neuen Werkzeugen erstellten wir Muster, welche sich auf allen Seiten mit sich selbst erweitern lassen. Meret's und meine Lösung sind Auschnitte einer Ziegelsteinmauer, wobei wir vor allem Mit dem Versatz der einzelen Blöcke zu kämpfen hatten. Anschliessende Spielereien mit der dritten Dimension ergaben eine Tiefenfuge in der Mauer. In der Vorerst letzten Aufgabe spielten wir mit einem Fraktal, wobei ich eine dritte Dimension Hinzugefügt und, statt mit Verschieben, das Fraktal über die Rotation verändert habe. Nebenbei erlangten wir Wissen umRandom-seeds. Zum Schluss noch die entsprechenden Codes: Smiley Rotation:int i = 0; void setup() { size(800,800); // def. fenstergroesse smooth(); // aktiviere antialiasing strokeWeight(15); // linienbreite } void draw() { background(255); // def. hintergrundfarbe i=i+1; float radius = dist(mouseX,mouseY,width/2,height/2); // rechne die distanz vom mousecursor zum fensterzentrum aus radius = map(radius,0,width,1,4); // rechne aus in welchem bereich der radius am schluss sein sollte pushMatrix(); translate(400,400); rotate(calcAngle()); scale(radius); smiley(); // funtions aufruf pushMatrix(); rotate(radians (i)); translate(100,100); scale(.5); smiley(); // funtions aufruf pushMatrix(); rotate(radians (i)); translate(100,100); scale(.5); smiley(); // funtions aufruf pushMatrix(); rotate(radians (i)); translate(100,100); scale(.5); smiley(); // funtions aufruf pushMatrix(); rotate(radians (i)); translate(100,100); scale(.5); smiley(); // funtions aufruf pushMatrix(); rotate(radians (i)); translate(100,100); scale(.5); smiley(); // funtions aufruf pushMatrix(); rotate(radians (i)); translate(100,100); scale(.5); smiley(); // funtions aufruf pushMatrix(); rotate(radians (i)); translate(100,100); scale(.5); smiley(); // funtions aufruf pushMatrix(); rotate(radians (i)); translate(100,100); scale(.5); smiley(); // funtions aufruf pushMatrix(); rotate(radians (i)); translate(100,100); scale(.5); smiley(); // funtions aufruf pushMatrix(); rotate(radians (i)); translate(100,100); scale(.5); smiley(); // funtions aufruf pushMatrix(); rotate(radians (i)); translate(100,100); scale(.5); smiley(); // funtions aufruf pushMatrix(); rotate(radians (i)); translate(100,100); scale(.5); smiley(); // funtions aufruf pushMatrix(); rotate(radians (i)); translate(100,100); scale(.5); popMatrix(); popMatrix(); popMatrix(); popMatrix(); popMatrix(); popMatrix(); popMatrix(); popMatrix(); popMatrix(); popMatrix(); popMatrix(); popMatrix(); popMatrix(); popMatrix(); } // funktion void smiley() { noFill(); ellipse(0,0,180,180); // kopf fill(0); ellipse(0 - 30,0 - 30,20,20); // linkes augen ellipse(0 + 30,0 - 30,20,20); // rechtes augen noFill(); arc(0,0,100,100,radians(20),radians(180-20)); // mund } // berechne den winkel zur fenstermitter vom mausecursor aus // die winkel sind in radiant float calcAngle() { return -atan2(mouseX - (width / 2),mouseY - (height / 2)); }Smiley Emotionen:
static final int SMILEY_DEFAULT = 1<<0; static final int SMILEY_SAD = 1<<1; static final int SMILEY_DRUNK = 1<<2; static final int SMILEY_ANGRY = 1<<4; static final int SMILEY_OLD = 1<<5; static final int SMILEY_ASTOUND = 1<<6; static final int SMILEY_SLEEPY = 1<<7; static final int SMILEY_HORNY = 1<<8; static final int SMILEY_PANIC = 1<<9; int smileyType = SMILEY_DEFAULT; void setup() { size(400,400); // def. fenstergroesse smooth(); // aktiviere antialiasing strokeWeight(15); // linienbreite } void draw() { background(255); // def. hintergrundfarbe pushMatrix(); translate(width * .5,width * .5); smileyhead(smileyType); // funtions aufruf smileyeyes(smileyType); smileymouth(smileyType); smileyadds(smileyType); popMatrix(); } void keyPressed() { switch(key) { case '1': smileyType = SMILEY_DEFAULT; break; case '2': smileyType = SMILEY_SAD; break; case '3': smileyType = SMILEY_DRUNK; break; case '4': smileyType = SMILEY_ANGRY; break; case '5': smileyType = SMILEY_OLD; break; case '6': smileyType = SMILEY_ASTOUND; break; case '7': smileyType = SMILEY_SLEEPY; break; case '8': smileyType = SMILEY_HORNY; break; case '9': smileyType = SMILEY_PANIC; break; } } // funktion Kopf void smileyhead(int smileyType) { // kopf noFill(); ellipse(0,0,180,180); // kopf } // Funktion Augen void smileyeyes(int smileyType) { fill(0); if((smileyType & SMILEY_SAD) != 0) { ellipse(0 - 30,0 - 30,20,5); // linkes augen ellipse(0 + 30,0 - 30,20,5); // rechtes augen } else if((smileyType & SMILEY_DRUNK) != 0) { line(-50,-40,-10,-10); line(-50,-10,-10,-40); line(50,-40,10,-10); line(50,-10,10,-40); } else if((smileyType & SMILEY_ANGRY) != 0) { line(-50,-30,-10,-20); line(50,-30,10,-20); } else if((smileyType & SMILEY_OLD) != 0) { ellipse(0 - 30,0 - 30,20,5); // linkes augen ellipse(0 + 30,0 - 30,20,5); // rechtes augen } else if((smileyType & SMILEY_ASTOUND) != 0) { ellipse(0 - 30,0 - 30,30,30); // linkes augen ellipse(0 + 30,0 - 30,30,30); // rechtes augen } else if((smileyType & SMILEY_SLEEPY) != 0) { noFill(); arc(30,-50,30,30,radians(20),radians(180-20)); arc(-30,-50,30,30,radians(20),radians(180-20)); fill(0); } else if((smileyType & SMILEY_HORNY) != 0) { noFill(); ellipse(-30,-20,50,50); ellipse(30,-20,50,50); ellipse(-30,-20,1,1); ellipse(30,-20,1,1); } else { ellipse(0 - 30,0 - 30,20,20); // linkes augen ellipse(0 + 30,0 - 30,20,20); // rechtes augen } } void smileymouth(int smileyType) // mund { noFill(); if((smileyType & SMILEY_SAD) != 0) arc(0,60,100,100,radians(180+20),radians(360-20)); // mund else if((smileyType & SMILEY_DRUNK) != 0) { line(-50,20,50,20); arc(-10,15,50,70,radians(20),radians(180-20)); // mund } else if((smileyType & SMILEY_ANGRY) != 0) { noFill(); beginShape(); vertex(-45, 40); vertex(-30, 20); vertex(-15, 40); vertex(0, 20); vertex(15, 40); vertex(30, 20); vertex(45, 40); endShape(); } else if((smileyType & SMILEY_OLD) != 0) { line(-50,20,50,20); // mund } else if((smileyType & SMILEY_ASTOUND) != 0) { ellipse(0, 40, 40, 60); // mund } else if((smileyType & SMILEY_SLEEPY) != 0) arc(0,20,100,50,radians(20),radians(180-20)); // mund else if((smileyType & SMILEY_HORNY) != 0) { arc(0,0,100,100,radians(20),radians(180-20)); arc(-10,15,50,70,radians(20),radians(180-20)); // mund } else arc(0,0,100,100,radians(20),radians(180-20)); // mund } void smileyadds(int smileyType) { // Zusätze if((smileyType & SMILEY_OLD) != 0) { fill(100); stroke(100); beginShape(); vertex(-50, 20); vertex(-20, 80); vertex(-15, 60); vertex(0, 90); vertex(15, 60); vertex(20, 80); vertex(50, 20); endShape(); stroke(0); } }Mauer
import processing.pdf.*; import processing.opengl.*; void setup() { size(720,540,OPENGL); // def. fenstergroesse smooth(); // aktiviere antialiasing strokeWeight(10); // linienbreite } void draw() { lights(); background(100); // def. hintergrundfarbe for(int y = 0; y <= 5*width; y+=250) { for(int x = 0; x <= 5*height; x+=250) { pushMatrix(); rotate(radians(45)); translate(x,y-800); scale(1); muster(); // funtions aufruf popMatrix(); } } camera(mouseX, mouseY, 500.0, 500, 500, 0.0, 0.0, 1.0, 0.0); } // funktion void muster() { fill(200,50,50); noStroke(); beginShape(); vertex(100,0,0); //Ziegel vertex(200,100,0); vertex(0,300,0); vertex(-100,200,0); endShape(CLOSE); beginShape(); vertex(100,0,0); //Ziegel vertex(200,100,0); vertex(0,300,0); vertex(-100,200,0); endShape(CLOSE); fill(200); beginShape(); //Fuge 1 vertex(100,0,0); vertex(100,-20,-10); vertex(-120,200,-10); vertex(-100,200,0); endShape(CLOSE); beginShape(); //Fuge 1 vertex(100,0,0); vertex(200,100,0); vertex(220,100,-10); vertex(100,-20,-10); endShape(CLOSE); beginShape(); //Fuge 1 vertex(200,100,0); vertex(220,100,-10); vertex(0,320,-10); vertex(0,300,0); endShape(CLOSE); beginShape(); //Fuge 1 vertex(-120,200,-10); vertex(0,320,-10); vertex(0,300,0); vertex(-100,200,0); endShape(CLOSE); beginShape(); vertex(-120,200,-20); vertex(0,320,-20); vertex(220,100,-20); vertex(100,-20,-20); vertex(-180,200,-20); vertex(0,380,-20); vertex(280,100,-20); vertex(100,-80,-20); endShape(CLOSE); }Fraktal
int W =4; void setup() { size(400,400,P3D); // def. fenstergroesse randomSeed(millis()); // seed random smooth(); // aktiviere antialiasing stroke(0,0,0,150); //camera(0, 0, 0 , width/2, height/2, 0, mouseX-width/2, mouseY, 50); noLoop(); } void draw() { background(255); pushMatrix(); translate(width *.5,height-70); wurzel(5); popMatrix(); } void mousePressed() { redraw(); } // funktion void wurzel(int tiefe) { if(tiefe <=0) // teste ob das ende erreicht worden ist { // zeichen blueten pushStyle(); int clr1 = (int)random(100,255); int clr2 = (int)random(100,255); int clr3 = (int)random(100,255); int clr4 = (int)random(100,255); int clr5 = (int)random(100,255); int clr6 = (int)random(100,255); stroke(clr1, clr2, clr3,190); fill(clr4, clr5, clr6,190); Blume(); popStyle(); return; } // zeichne zweige int x; int y; int z; int count = (int)random(1,8); for(int i = 0; i =1) { W=W-1; println(W); } } } void Blume() { noFill(); ellipse(0,40,20,80); // kopf /*fill(0); ellipse(0 - 10,0 - 10,10,10); // linkes augen ellipse(0 + 10,0 - 10,10,10); // rechtes augen noFill(); arc(0,0,50,50,radians(20),radians(180-20)); // mund */}