9. November 2010
Konzept Um mehre Gemütszustände gleichzeitig darstellen zu können habe ich den Smiley in 3 Teile unterteilt: Kopf, Augen und Mund Beim drücken von unterschiedlichen Tasten auf der Tastatur (z.B. q, a , y, w, s, x, e, d, c) verändert sich der jeweilige Bereich des Smileys.../* * SMILEYS * * This little programm shows you a smiley in different frames of mind * depending on which key you pressed it changes the head, eyes and mouth * seperately. * * @name SMILEYS * @author Sebastian Pape * @version 0.9 *//* HEAD TYPES */ static int HEAD_DEFAULT = 0; static int HEAD_ROBOT = 1; static int HEAD_APE = 2; int headType = HEAD_DEFAULT; /* EYES TYPES */ static int EYES_DEFAULT = 0; static int EYES_SAD = 1; static int EYES_DRUNK = 2; int eyesType = EYES_DEFAULT; /* MOUTH TYPES */ static int MOUTH_DEFAULT = 0; static int MOUTH_SAD = 1; static int MOUTH_DRUNK = 2; int mouthType = MOUTH_DEFAULT; /* STROKE */ static int STROKE_WEIGHT = 15; /* SETUP */ void setup() { size(400,400); smooth(); strokeWeight(STROKE_WEIGHT); } /* DRAW */ void draw() { background(255); pushMatrix(); translate(width * .5,width * .5); drawSmiley(); popMatrix(); } /* KEY PRESSED */ void keyPressed() { switch(key) { // HEAD KEYS case 'q': headType = HEAD_DEFAULT; break; case 'a': headType = HEAD_ROBOT; break; case 'y': headType = HEAD_APE; break; // EYES KEYS case 'w': eyesType = EYES_DEFAULT; break; case 's': eyesType = EYES_SAD; break; case 'x': eyesType = EYES_DRUNK; break; // MOUTH KEYS case 'e': mouthType = MOUTH_DEFAULT; break; case 'd': mouthType = MOUTH_SAD; break; case 'c': mouthType = MOUTH_DRUNK; break; } } /* DRAW SMILEY */ void drawSmiley() { drawHead(); drawEyes(); drawMouth(); } /* DRAW HEAD */ void drawHead() { switch(headType) { case 0: drawDefaultHead(); break; case 1: drawRoboterHead(); break; case 2: drawApeHead(); } } void drawDefaultHead() { noFill(); ellipse(0,0,180,180); } void drawRoboterHead() { noFill(); rect(-90, -90, 180, 180); line(-90, -90, -40, -120); line(-40, -120, 40, -120); line(40, -120, 90, -90); } void drawApeHead() { noFill(); ellipse(0,-30,180,90); fill(255); ellipse(0,35,150,100); noFill(); fill(255); noStroke(); ellipse(0,0,130,70); stroke(0); strokeWeight(STROKE_WEIGHT); noFill(); } /* DRAW EYES */ void drawEyes() { switch(eyesType) { case 0: drawDefaultEyes(); break; case 1: drawSadEyes(); break; case 2: drawDrunkEyes(); break; } } void drawDefaultEyes() { fill(0); ellipse(0 - 30,0 - 30,20,20); ellipse(0 + 30,0 - 30,20,20); noFill(); } void drawSadEyes() { fill(0); ellipse(0 - 30,0 - 30,20,5); ellipse(0 + 30,0 - 30,20,5); noFill(); } void drawDrunkEyes() { line(-50,-40,-10,-10); line(-50,-10,-10,-40); line(50,-40,10,-10); line(50,-10,10,-40); } /* DRAW MOUTH */ void drawMouth() { switch(mouthType) { case 0: drawDefaultMouth(); break; case 1: drawSadMouth(); break; case 2: drawDrunkMouth(); break; } } void drawDefaultMouth() { arc(0,0,100,100,radians(20),radians(180-20)); } void drawSadMouth() { arc(0,60,100,100,radians(180+20),radians(360-20)); } void drawDrunkMouth() { line(-50,20,50,20); arc(-10,15,50,70,radians(20),radians(180-20)); }