5. November 2010
Vorgegebene Gemütszustände des Smileys umsetzen. angry: old:static int SMILEY_DEFAULT = 1<<0; static int SMILEY_SAD = 1<<1; static int SMILEY_DRUNK = 1<<2; static int SMILEY_ANGRY = 1<<4; static int SMILEY_OLD = 1<<5; static int SMILEY_ASTOUND = 1<<6; static int SMILEY_SLEEPY = 1<<7; static int SMILEY_HORNY = 1<<8; static 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); smiley(smileyType); // funktions aufruf 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; } } // funktion void smiley(int smileyType) { // kopf noFill(); ellipse(0,0,180,180); // kopf // augen 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,-40,-10,-10); line(50,-40,10,-10); } else if((smileyType & SMILEY_OLD) != 0) { ellipse(0 - 30,0 - 30,10,10); // linkes augen ellipse(0 + 30,0 - 30,10,10); // rechtes augen } else { ellipse(0 - 30,0 - 30,20,20); // linkes augen ellipse(0 + 30,0 - 30,20,20); // rechtes augen } // 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) { arc(0,60,100,100,radians(180+30),radians(360-30)); // mund } else if((smileyType & SMILEY_OLD) != 0) { line(-30,30,30,30); // mund line(30,10,40,45); line(-30,10,-40,45); } else arc(0,0,100,100,radians(20),radians(180-20)); // mund }