Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
Confluence
/
P5js Verschachtelten Schleife (de)

P5js Verschachtelten Schleife (de)

Jul 30, 2021

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

  • Erstelle ein Ornament, welches sich auf allen 4 Seiten mit sich selbst erweitern lässt. Druck es aus und test es.
  • Erstelle ein Ornament welches mit einem Ornament einer anderen Person erweitert werden kann.
, multiple selections available,
For you

Programming
Results will update as you type.
  • Tiling and Repetition
  • Reactors
  • Programming Basics: Parametric and Generative Graphic Design 2016
  • Archive
  • High Scores
  • Artificial Neural Network
  • Alternatives to the Processing IDE
  • p5.js Programming
    • p5.js Introduction
    • p5.js Variables
    • p5.js Random Numbers
    • p5.js SVG + Images
    • p5.js WebGL
    • p5.js Classes and Objects
    • p5.js Events and Functions
    • p5.js Loops
    • p5.js Coordinates
    • P5js Nested Loops
      • P5js Verschachtelten Schleife (de)
    • p5.js Animation Exercise 1
    • p5.js Animation Exercise 2
    • p5.js Conditionals
    • p5.js Arrays and Lists
    • p5.js Simple Collision Detection
    • p5.js Reactors
    • p5.js Tiling and Repetition
    • p5.js Vectors
    • p5.js Animation Solution with Objects
    • p5.js Easing
    • p5.js Perlin Noise
    • p5.js Particle System
    • p5.js Sound
    • p5j.s Typography
    • P5js Archive
  • Programming in Processing (java)

{"serverDuration": 34, "requestCorrelationId": "27b9d590e4df4085b84b3dcf14ef7cac"}