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.

Processing 04 (20.02.2013)

Vektor Rechnen

Für viele Anwendungen ist es nützlich mit Vektoren zu arbeiten. Processing stellt hierfür die Klasse PVector zur Verfügung. Vektor-Klassen macht den Code übersichtlicher und ersparen Fleissarbeit beim tippen. Beitrag zu PVector auf Processing.org

Beispiele:

1.Ball Klasse
class Ball
{
  PVector location;  // Location of shape
  PVector velocity;  // Velocity of shape
  PVector gravity;   // Gravity acts at the shape's acceleration

  Ball(float _startX, float _startY)
  {
    location = new PVector(_startX, _startY);
    velocity = new PVector(1.5, 2.1);
    gravity = new PVector(0, 0.2);
  }

  void update()
  {
    // Add velocity to the location.
    location.add(velocity);
    // Add gravity to velocity
    velocity.add(gravity);
  }

  void checkEdges()
  {
    if ((location.x > width) || (location.x < 0)) 
    {
      velocity.x = velocity.x * -1;
    }
    if (location.y > height || location.y < 0) 
    {
      velocity.y = velocity.y * -1;
    }
  }

  void draw()
  {
    //Display an Ellipse at the Vector of the Ball
    stroke(255);
    strokeWeight(2);
    fill(127);
    ellipse(location.x, location.y, 48, 48);
  }
}

2. Ball mit Geschwindigkeit und Schwerkraft
//Implement Class Ball
Ball bouncer;

void setup() 
{
  size(640, 360);
  smooth();
  //Create a new object of class Bouncer
  bouncer = new Ball(width/2, height/2);
}

void draw() 
{
  //Draw the background
  background(0);
  //Update,Check and draw the bouncer
  bouncer[i].update();
  bouncer[i].checkEdges();
  bouncer[i].draw();
}
3. Viele Bälle
Ball [] bouncer;

numOfBouncers = 100;

void setup() 
{
  size(640, 360);
  smooth();
  //bouncer = new Ball(width/2,height/2);
  
  bouncer = new Ball[numOfBouncers];
  
  for (int i=0; i<numOfBouncers;i++)
  {
    bouncer[i] = new Ball(random(0, width), random(0, height));
  }
}

void draw() 
{
  background(0);

  for (int i=0; i<numOfBouncers;i++)
  {
    bouncer[i].update();
    bouncer[i].checkEdges();
    bouncer[i].draw();
  }
}

Histogramm Aufgaben

  1. Erstelle ein Histogramm eines Bildes (Mögliche Lösung: Processing.org)
  2. Prozentanteil Rot/ Grün/ Blau (Mögliche Lösung: Find_RGB)
  3. Hellste/ Dunkelste Regionen anzeichnen (Mögliche Lösung: Find_Spot)
  4. (Die Pixel eines Videobildes nach einer farblichen Systematik umordnen)

ASCII Art Aufgaben

  1. Erstelle diese Funktions: color getAverangeColor(PImage img,int posX,int posY,int w,int h)
  2. Lass eine Bilderserie als Animation abspielen (Array)
  3. Schau das Beispiel für die Verwendung von Schrift an Weise zehn Buchstaben einen Helligkeitswert zu. Lies die Helligkeitswerte eines Bildes aus und setze dem entsprechend die Buchstaben ein. - Experimentier mit der Schriftgrösse, Zuordnung der Buchstaben zur Helligkeit, ...
  4. (Programmiere eine Animation von 320 x 240 Pixeln auf 1×1 Pixel)