Interaction Design WikiProgramming

Verschachtelten Schleife (de)

Beispiel mit Screenshot-Funktion

void setup()
{
  size(600,600);      // def. fenstergroesse
  
  smooth();           // aktiviere antialiasing
  strokeWeight(1);    // linienbreite
}
  
void draw()
{
  background(255);    // def. hintergrundfarbe
  
  for(int x = 0; x <= width; x+=30)
  {
    for(int y = 0; y <= height; y+=30)
    {
        smiley(x,y);          // funtions anruf
    }
  }
  
}
  
void keyPressed()
{
  switch(key)
  {
  case 's':
    save("screenShot.jpg");
    println("save the screen to screenShot.jpg");
    break;
  }
}
  
// funktion
void smiley(int x, int y)
{
  println("smiley");
  noFill();
  ellipse(x,y,18,18);  // kopf
  
  fill(0);
  ellipse(x - 3,y - 3,2,5);  // linkes augen
  ellipse(x + 3,y - 3,2,5);  // rechtes augen
  
  noFill();
  arc(x,y,10,10,radians(20),radians(180-20));  // mund
}

Dieses Beispiel gibt die Zeichnung nicht auf den Bildschirm aus, es schreibt die Ausgabe in ein PDF-File.

import processing.pdf.*;
  
void setup()
{
  size(600,600,PDF,"ornament.pdf");      // def. fenstergroesse
  
  smooth();           // aktiviere antialiasing
  strokeWeight(1);    // linienbreite
}
  
void draw()
{
  background(255);    // def. hintergrundfarbe
  
  for(int x = 0; x <= width; x+=30)
  {
    for(int y = 0; y <= height; y+=30)
    {
        smiley(x,y);          // funtions aufruf
    }
  }
  
  exit();
}
  
// funktion
void smiley(int x, int y)
{
  println("smiley");
  noFill();
  ellipse(x,y,18,18);  // kopf
  
  fill(0);
  ellipse(x - 3,y - 3,2,5);  // linkes augen
  ellipse(x + 3,y - 3,2,5);  // rechtes augen
  
  noFill();
  arc(x,y,10,10,radians(20),radians(180-20));  // mund
}

Aufgabe