20. Oktober 2011
Übung zu Lektion 2 / Aufgabe 10 (Keyboard Events, http://blogs.iad.zhdk.ch/codingspace2011/lektion-2/) Ich habe den Mund und die Augen in eigene Funktionen mit einem Switch-Statement umgewandelt.. Das Switch-Statement frägt den Stand von smileyType ab und gibt entsprechend einen anderen Mund oder Augen aus. Der SmileyType wird von Keyboard-Eingaben (1-9) verändert. Zusätzlich lasse ich in der Konsole die Mausposition anzeigen und es wird angezeigt, welche Augen und welcher Mund momentan gerade angezeigt werden. Zum Zeichnen der verschiedenen Smileys bin ich noch nicht gekommen. Ich wollte auch noch einen Text auf dem Bildschirm angeben, der den momentan Zustand angibt, aber der Code funktioniert noch nicht.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); //Fenstergroesse smooth(); // Anti-Aliasing strokeWeight(15); //Linienbreite) //textMode(SCREEN); } void draw() { background(255); //Hintergrundfarbe fill(0, 102, 153); pushMatrix(); translate(width * .5,width * .5); smiley(smileyType); //Funktionsaufruf popMatrix(); println("mouseX: " + mouseX + ", mouseY: " + mouseY); } 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 void descriptionText () { switch(smileyType) { case SMILEY_DEFAULT: text("Boring old Default smiley"); break; case SMILEY_SAD: text("Life sucks"); break; case SMILEY_DRUNK: text("No more Jagermeisters for me"); break; case SMILEY_ANGRY: text("AAAAAAAARGH!!!"); break; case SMILEY_OLD: text("When I was young..."); break; case SMILEY_ASTOUND: text("WHOA!"); break; case SMILEY_SLEEPY: text("I'm sooo tired"); break; case SMILEY_HORNY: text("Me so horny"); break; case SMILEY_PANIC: text("RUN FOR THE HILLS!"); break; } } void mouth () { switch(smileyType) { case SMILEY_DEFAULT: println("Default Mouth"); arc(0,0,100,100,radians(20),radians(180-20)); // mund break; case SMILEY_SAD: println("Sad Mouth"); arc(0,60,100,100,radians(180+20),radians(360-20)); // mund break; case SMILEY_DRUNK: println("Drunk Mouth"); line(-50,20,50,20); arc(-10,15,50,70,radians(20),radians(180-20)); // mund break; case SMILEY_ANGRY: println("Angry Mouth"); break; case SMILEY_OLD: println("Old Mouth"); break; case SMILEY_ASTOUND: println("Astounded Mouth"); break; case SMILEY_SLEEPY: println("Sleepy Mouth"); break; case SMILEY_HORNY: println("Horny Mouth"); break; case SMILEY_PANIC: println("Panicked Mouth"); break; } } void eyes () { switch(smileyType) { case SMILEY_DEFAULT: println("Default Eyes"); ellipse(0 - 30,0 - 30,20,20); // linkes augen ellipse(0 + 30,0 - 30,20,20); // rechtes augen break; case SMILEY_SAD: println("Sad Eyes"); ellipse(0 - 30,0 - 30,20,5); // linkes augen ellipse(0 + 30,0 - 30,20,5); // rechtes augen break; case SMILEY_DRUNK: println("Drunk Eyes"); line(-50,-40,-10,-10); line(-50,-10,-10,-40); line(50,-40,10,-10); line(50,-10,10,-40); break; case SMILEY_ANGRY: println("Angry Eyes"); break; case SMILEY_OLD: println("Old Eyes"); break; case SMILEY_ASTOUND: println("Astounded Eyes"); break; case SMILEY_SLEEPY: println("Sleepy Eyes"); break; case SMILEY_HORNY: println("Horny Eyes"); break; case SMILEY_PANIC: println("Panicked Eyes"); break; } } void smiley(int smileyType) { // kopf noFill(); ellipse(0,0,180,180); // kopf // augen fill(0); eyes(); // mund noFill(); mouth(); }