Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

Lektion 2 – Bedingungen – smile gone vile

20. Oktober 2011

The smiley gets angry when you move over its face.
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
 
  // teste ob der mauszeiger innerhalb des smiley ist
  if(mouseX > (width * .5 - 90)  && mouseX < (width * .5 + 90) &&
     mouseY > (height * .5 - 90)  && mouseY < (height * .5 + 90))
     // die mouse ist im smiley, smiley mag das nicht
     smileyType = SMILEY_ANGRY;
  else
     smileyType = SMILEY_DEFAULT;
 
  pushMatrix();
    translate(width * .5,width * .5);
    smiley(smileyType);          // funtions aufruf
  popMatrix();
 
}
 
// funktion
void smiley(int smileyType)
{
  if((smileyType & SMILEY_ANGRY) > 0)
  {
    fill(#E51010);
  } else {
    fill(#E5DB10);
  }
  ellipse(0,0,180,180);  // kopf
 
  fill(0);
  if((smileyType & SMILEY_ANGRY) > 0)
  {
    line(-40, -40, -10, -10);
    line(40, -40, 10, -10);
    //ellipse(0 - 30,0 - 30,20,5);  // linkes augen
    //ellipse(0 + 30,0 - 30,20,5);  // rechtes augen
  }
  else
  {
    ellipse(0 - 30,0 - 30,20,20);  // linkes augen
    ellipse(0 + 30,0 - 30,20,20);  // rechtes augen
  }
 
  noFill();
  if((smileyType & SMILEY_ANGRY) != 0)
    arc(0,60,100,100,radians(180+20),radians(360-20));  // mund
  else
    arc(0,0,100,100,radians(20),radians(180-20));  // mund
}