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 4 – Patterns

20. Oktober 2011

Screenshot Mein Beispiel zur Lektion 4. Ich habe im Illustrator ein Muster entworfen und dieses mit PShape in meinen Code geladen. Mit dem Mauszeiger wird das Muster gedreht und es entstehen neue Kombinationen. Das Muster kann man im Illustrator verändern. Wenn man es abspeichert wird es sogleich im Processing so dargestellt. Mit PFont habe ich eine Schriftart importiert. Mit Druck auf 's' kann man Screenshots speichern. Hier wird nicht einfach screenshot immer wieder überschrieben, sondern ein neuer Name angelegt ( saveFrame("screenshot-##.png"); ). Den entstanden Code könnte man zu einem Pattern-Generator weiterentwickeln, bei dem man mittels Drag'n'Drop eigene Muster laden kann. Diese kann man dann manipulieren und mit Druck auf s wieder abspeichern. Mit Druck auf "i" könnte man die Instruktionen aus- oder einblenden, so dass man nur das Muster alleine als Screenshot ausgeben könnte. Ich habe die pushMatrix/popMatrix Funktionen noch nicht verstanden.  Bei diesem Beispiel habe ich nicht viel Code selber geschrieben, sondern nur Änderungen am Beispielcode vorgenommen.    
PShape loadOrnament;
PFont font;
int rotateOrn = mouseX-mouseY;

/*
Pattern wiederholt sich. Einzelne Ornamente sollen rotieren, wenn die Maus bewegt wird.
's' speichert einen Screenshot
'r' setzt die Rotation zurück
Zweite Ebene > Farbig?
*/

void setup()
{
  size(600,770);      // def. fenstergroesse

  smooth();           // aktiviere antialiasing
}

void draw()
{
  background(255,207,31);    // hintergrundfarbe

  font = loadFont("Serif-48.vlw");
  textFont(font, 120);
  fill(0);
  text("Patternin'", 80, 180);
  strokeWeight(3);
  line(0,263,600,263);

  for(int x = 0; x   {
    for(int y = 0; y     {
      pushMatrix();
        translate(x,y);
        scale(0.5);
        ornament();          // Funktionsaufruf
      popMatrix();
      instructions();
    }
  }

}

// Keyboardeingaben

void keyPressed()
{
  switch(key)
  {
  case 's':
    saveFrame("screenshot-##.png");
    println("save the screen to screenshot-##.png");
    break;
  case 'r':
    //resets the rotation of the single ornaments to the initial state
    println("Reset Rotation of patterns");
    break;
  case 'i':
    //hides or shows instructions panel
    println("Show/Hide instructions");
    break;
  }
}

// Funktionen
void ornament()
{
        loadOrnament = loadShape("ornament.svg");
        rotate(mouseX + mouseY);
        shape(loadOrnament, 10, 10, 80, 80);
}

void instructions()
{
  fill(255);
  strokeWeight(10);
  strokeJoin(BEVEL);
  rect(125,600,350,100);
  fill(0);
  textFont(font, 14);
  text("Move the mouse to rotate patterns.", 150, 625);
  text("Press 's' to save a screenshot.", 150, 650);
  text("Press 'r' to reset ornaments.", 150, 665);
  text("Press 'i' to hide instructions.", 150, 680);
}