Tag 2 2.Kreisfunktionen
Junger Mann beunruhigt durch den Flug einer nicht-euklidischen Fliege (Max Ernst, Öl auf Leinwand, 82 x 66 cm,1947)
Winkel können in Grad und Radiant (Rad) angegeben werden, der volle Kreisbogen beträgt 360° oder 2PI (~2*3.1415) in Rad. Processing bietet für die irrationale Zahl Pi die Konstanten PI, QUARTER_PI, HALF_PI und TWO_PI. Um zwischen den Einheiten umzurechnen stehen die Funktionen radians() und degrees() zur Verfügung. Processing erwartet als Winkelangabe stets Rad. Für generative Grafiken können Sinus- und Kosinus-Funktionen interessant sein. Processing stellt sie mit den Funktionen sin() und cos() zu Verfügung.
sin(winkel);
cos(winkel);
Video generative Illustration: Spirograph
Die Winkel werden in Rad angegeben, die Funktionen liefern einen Wert zwischen -1 und 1 zurück.
Beispiel 1-12
size (800,600);
noStroke();
float angle = 0.0;
fill(0,50);
background(255);
for (int count = 0; count <= 100; count ++){
float scale = random(50,height); // definiert eine zufällig x-Skalierung
for (float x=0; x<= width; x+=1) { //die Schleife ist notwendig, um alle x-Werte zu zeichnen
float y= height/2 + (-sin(radians(angle))*scale); //berechnet die y-Werte für eine Sin-Kurve
ellipse(x,y,2,2);
angle += 0.5;
}
}
Beispiel 1-13
float radius = 200;
float mittelpunktX;
float mittelpunktY;
float x, y;
float step = 0.01;
float multiRad = 0;
void setup(){
size(800,600);
noStroke();
fill(0,50);
background(255);
mittelpunktX = width/2;
mittelpunktY = height/2;
}
void draw(){
background(255);
float winkel = 0;
multiRad += 0.1;
float multi = sin(multiRad)*50;
while (winkel < 2*PI){
float shift = randomGaussian()*multi;
x = mittelpunktX + ((radius+shift) * cos(winkel));
y = mittelpunktY + ((radius+shift) * sin(winkel));
//y = winkel*100;
//ellipse(x, y, 4*multi, 4*multi);
stroke(0,30);
line(mittelpunktX, mittelpunktY, x,y);
noStroke();
ellipse(x, y, 4, 4);
winkel += step;
}
}