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 3 – smiling orbiter

20. Oktober 2011

The exercise was to get a smiley to turn around its own axis while orbiting around a larger smiley. This is my solution:
int i = 1;

void setup()
{
  size(400,400);      // def. fenstergroesse
 
  smooth();           // aktiviere antialiasing
  strokeWeight(15);    // linienbreite
}
 
void draw()
{
  background(255);    // def. hintergrundfarbe
 
  float radiusOrig = dist(mouseX,mouseY,width/2,height/2);  // rechne die distanz vom mousecursor zum fensterzentrum aus
  float radius = map(radiusOrig,0,width,1,3);                     // rechne aus in welchem bereich der radius am schluss sein sollte
 
  pushMatrix();
    translate(200,200);
    rotate(calcAngle());
    scale(radius);
    smiley();          // funtions aufruf

    rotate(radians(i % 360) + calcAngle());
    scale(.2);
    translate(radiusOrig + 500,radiusOrig + 500);
    smiley();          // funtions aufruf
  popMatrix();
  
  i+=2;
}
 
// funktion
void smiley()
{
  noFill();
  ellipse(0,0,180,180);  // kopf
 
  fill(0);
  ellipse(0 - 30,0 - 30,20,20);  // linkes augen
  ellipse(0 + 30,0 - 30,20,20);  // rechtes augen
 
  noFill();
  arc(0,0,100,100,radians(20),radians(180-20));  // mund
}
 
// berechne den winkel zur fenstermitter vom mausecursor aus
// die winkel sind in radiant
float calcAngle()
{
  return -atan2(mouseX - (width / 2),mouseY - (height / 2));
}