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; Koordinatensysteme

9. November 2010

This exercise was interesting in that I began to understand the coordinates system and the rotation of objects. In addition how important it was to where the floats etc where initialized. Especially when working with draw(). Here is the finished code;
float radSec = 0.0;
  
void setup()
{
  size(400,400);      // def. fenstergroesse

  smooth();           // aktiviere antialiasing
  strokeWeight(15);    // linienbreite

}

void draw()
{
  background(255);    // def. hintergrundfarbe

  float radius = dist(mouseX,mouseY,width/2,height/2);  // rechne die distanz vom mousecursor zum fensterzentrum aus
  //radius = map(radius,0,width,1,4);                     // rechne aus in welchem bereich der radius am schluss sein sollte
  radius = map(radius, 0,width,1,4);

  pushMatrix();
    translate(mouseX,mouseY); //translate(200,200);
    rotate(calcAngle());
    scale(radius);
    smiley();
    
    pushMatrix();
    translate(80,80);

    // Radsec icreases the radian everysecond. float radSec = 360/60 * second();
    rotate(radSec);
    //rotate(radians(radSec));
    radSec += 0.1;
    scale(.2);
    smiley();          // funtions aufruf
    popMatrix();    // funtions aufruf
    
    popMatrix();

  
}

// 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));
}