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

26. November 2010

In der zweiten Lektion wurden die Themen; Framework, Funktionen(Void), Funktionsparameter, Animation, Bedingungen und Keyboardevents eingeführt. Anschliessend wurden die neu eingeführten Themen anhand einer Smiley-Übung angewendet. Hier noch der Code:
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);          // funtions 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_PANIC;
break;
}
}
// funktion
void smiley(int smileyType)
{
// kopf
noFill();
rect(-90,-90,180,180);  // kopf
// augen
fill(0);
if((smileyType & SMILEY_SAD) > 0)
{
ellipse(0 - 30,0 - 30,30,5);  // linkes augen
ellipse(0 + 30,0 - 30,20,5);  // rechtes augen
}
else if((smileyType & SMILEY_DRUNK) != 0)
{
line(-40,-40,-15,-10);
line(-40,-10,-15,-40);
line(50,-40,10,-10);
line(50,-10,10,-40);
}
else if((smileyType & SMILEY_DRUNK) != 0)
{
line(-40,-40,-15,-10);
line(-40,-10,-15,-40);
line(50,-40,10,-10);
line(50,-10,10,-40);
}
else
{
ellipse(0 - 30,0 - 30,30,20);  // linkes augen
ellipse(0 + 30,0 - 30,20,30);  // 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
arc(0,0,100,100,radians(20),radians(180-20));  // mund
// hut
fill(0);
if((smileyType & SMILEY_SAD) > 0)
{
int offsety = 20;
triangle(-110,-90+offsety,110,-90+offsety,0,-200+offsety); //hut
}
else if((smileyType & SMILEY_DRUNK) != 0)
{
triangle(-120,-80,110,-90,0,-150);  //hut
}
else
{
triangle(-110,-90,110,-90,0,-180);  //hut
}
}
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);          // funtions 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_PANIC;    break;  }} // funktionvoid smiley(int smileyType){  // kopf  noFill();  rect(-90,-90,180,180);  // kopf // augen  fill(0);  if((smileyType & SMILEY_SAD) > 0)  {    ellipse(0 - 30,0 - 30,30,5);  // linkes augen    ellipse(0 + 30,0 - 30,20,5);  // rechtes augen  }  else if((smileyType & SMILEY_DRUNK) != 0)  {    line(-40,-40,-15,-10);    line(-40,-10,-15,-40); line(50,-40,10,-10);    line(50,-10,10,-40);  }  else if((smileyType & SMILEY_DRUNK) != 0)  {    line(-40,-40,-15,-10);    line(-40,-10,-15,-40); line(50,-40,10,-10);    line(50,-10,10,-40);  }  else  {    ellipse(0 - 30,0 - 30,30,20);  // linkes augen    ellipse(0 + 30,0 - 30,20,30);  // 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    arc(0,0,100,100,radians(20),radians(180-20));  // mund      // hut  fill(0);  if((smileyType & SMILEY_SAD) > 0)  {    int offsety = 20;     triangle(-110,-90+offsety,110,-90+offsety,0,-200+offsety); //hut  }  else if((smileyType & SMILEY_DRUNK) != 0)  {    triangle(-120,-80,110,-90,0,-150);  //hut  }  else  {    triangle(-110,-90,110,-90,0,-180);  //hut  } }