351
edits
No edit summary |
No edit summary |
||
Line 154: | Line 154: | ||
} | } | ||
</source> | </source> | ||
------- | |||
Man sieht einen Kreis in der Mitte des Fensters. Im Laufe der Zeit verfremdet sich der Kreis zufällig. | |||
[[File:verfremdeterkreis.jpg|300px]] | |||
<source lang="java"> | |||
import processing.pdf.*; | |||
boolean recordPDF = false; | |||
int formResolution = 15; | |||
int stepSize = 1; | |||
float distorsionFactor = 1; | |||
float initRadius = 150; | |||
float centerX, centerY; | |||
float[] x = new float[formResolution]; | |||
float[] y = new float[formResolution]; | |||
boolean filled = false; | |||
boolean pause = false; | |||
void setup(){ | |||
size(700, 700); | |||
smooth(); | |||
// init form | |||
centerX = width/2; | |||
centerY = height/2; | |||
float angle = radians(360/float(formResolution)); | |||
for (int i=0; i<formResolution; i++){ | |||
x[i] = cos(angle*i) * initRadius; | |||
y[i] = sin(angle*i) * initRadius; | |||
} | |||
stroke(3); | |||
background(255); | |||
} | |||
void draw(){ | |||
background(255); | |||
// calculate new points | |||
for (int i=0; i<formResolution; i++){ | |||
x[i] += random(-stepSize,stepSize); | |||
y[i] += random(-stepSize,stepSize); | |||
// ellipse(x[i], y[i], 5, 5); | |||
} | |||
beginShape(); | |||
// Start Kontrollpunkte | |||
curveVertex(x[formResolution-1]+centerX, y[formResolution-1]+centerY); | |||
// nur die Kontrollpunkte werden gezeichnet | |||
for (int i=0; i<formResolution; i++){ | |||
curveVertex(x[i]+centerX, y[i]+centerY); | |||
} | |||
curveVertex(x[0]+centerX, y[0]+centerY); | |||
// Ende Kontrollpunkte | |||
curveVertex(x[1]+centerX, y[1]+centerY); | |||
endShape(); | |||
} | |||
// events | |||
void mousePressed() { | |||
//init form on mouse position | |||
centerX = mouseX; | |||
centerY = mouseY; | |||
float angle = radians(360/float(formResolution)); | |||
float radius = initRadius * random(0.5,1.0); | |||
for (int i=0; i<formResolution; i++){ | |||
x[i] = cos(angle*i) * radius; | |||
y[i] = sin(angle*i) * radius; | |||
} | |||
} | |||
void keyReleased() { | |||
if (key == 's' || key == 'S') saveFrame(timestamp()+"_##.png"); | |||
if (key == DELETE || key == BACKSPACE) background(255); | |||
if (key == '1') filled = false; | |||
if (key == '2') filled = true; | |||
// ------ pdf export ------ | |||
// press 'r' to start pdf recording and 'e' to stop it | |||
// ONLY by pressing 'e' the pdf is saved to disk! | |||
if (key =='r' || key =='R') { | |||
if (recordPDF == false) { | |||
beginRecord(PDF, timestamp()+".pdf"); | |||
println("recording started"); | |||
recordPDF = true; | |||
stroke(0, 50); | |||
} | |||
} | |||
else if (key == 'e' || key =='E') { | |||
if (recordPDF) { | |||
println("recording stopped"); | |||
endRecord(); | |||
recordPDF = false; | |||
background(255); | |||
} | |||
} | |||
// switch draw loop on/off | |||
if (key == 'p' || key == 'P') pause = !pause; | |||
if (pause == true) noLoop(); | |||
else loop(); | |||
} | |||
// timestamp | |||
String timestamp() { | |||
Calendar now = Calendar.getInstance(); | |||
return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now); | |||
} | |||
</source> | |||
------- |
edits