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. Oktober 2011

In der 2ten Lektion wurde als erstes der Aufbau der "Klasse Processing" erklärt. Darin wurden die 2 Grundfunktionen oder eber besser Methoden beschrieben: Die funktionen draw und void. Diese funktionen (ich nene sie besser funcktionen als Methoden da es später keine verwechslungen mit den Klassen im Framework selber gibt) werden automatisch beim Programmstart gestartet. Dabei wird die Funktion Void immer nur 1 mal die Funktion draw bei jedem Zeichenvorgang ausgeführt. In einer 2ten Stufte wurden uns Funktionen näher gebracht. Dabei wurde überprüft wie diese anzuwenden sind, was auch das übergeben von Werten beinhaltet. Die sogenannten Funktionsparameter.

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);      // 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_HORNY;
 break;
 case '5':
 smileyType  = SMILEY_OLD;
 break;
 case '6':
 smileyType  = SMILEY_SLEEPY;
 break;
 }
 }

void smiley(int smileyType)
 {
 // kopf
 noFill();
 ellipse(0, 0, 180, 180);  // kopf

if((smileyType & SMILEY_SAD) != 0)
 {
 eyes(2);
 mouth(2);
 }
 else if((smileyType & SMILEY_DRUNK) != 0)
 {
 eyes(3);
 mouth(3);
 }
 else if((smileyType & SMILEY_OLD) != 0)
 {
 eyes(2);
 mouth(1);
 }
 else if((smileyType & SMILEY_HORNY) != 0)
 {
 eyes(4);
 mouth(4);
 }
 else if((smileyType & SMILEY_SLEEPY) != 0)
 {
 eyes(5);
 mouth(3);
 }
 else
 {
 eyes(1);
 mouth(1);
 }
 }

void eyes(int num)
 {
 switch(num)
 {
 case 1:
 ellipse(0 - 30,0 - 30,20,20);  // linkes augen
 ellipse(0 + 30,0 - 30,20,20);  // rechtes augen
 break;
 case 2:
 ellipse(0 - 30,0 - 30,20,5);  // linkes augen
 ellipse(0 + 30,0 - 30,20,5);  // rechtes augen
 break;
 case 3:
 line(-50,-40,-10,-10);
 line(-50,-10,-10,-40);

line(50,-40,10,-10);
 line(50,-10,10,-40);
 break;
 case 4:
 noFill();
 ellipse(0 - 30, 0 - 30, 50, 50);  // linkes augen
 ellipse(0 + 30, 0 - 30, 50, 50);  // linkes augen
 break;
 case 5:
 line(0-50, 0-30, 0-20, 0-30);  //left eye
 line(0+50, 0-30, 0+20, 0-30);  //rigth eye
 break;
 }
 }

void mouth(int num)
 {
 switch(num)
 {
 case 1:
 arc(0,0,100,100,radians(20),radians(180-20));
 break;
 case 2:
 arc(0,60,100,100,radians(180+20),radians(360-20));
 break;
 case 3:
 line(-50,20,50,20);
 arc(-10,15,50,70,radians(20),radians(180-20));
 break;
 case 4:
 arc(0,0,100,100,radians(20),radians(180-20));
 arc(-10,35,50,70,radians(40),radians(180-0));
 break;
 }
 }