Hey, I’ve created a composition in void draw and when I pressed ‘r’ I would like that void draw() goes again so that I can have some random examples before I save it. But can’t figure out how to run void draw() again. Somebody got any help? Thanks!
import processing.pdf.*;
PFont myFont;
PImage img;
String txt6 = ""; // Extra 2
String txt4 = "line"; // Info
String txt3 = "Event type"; // Event Type
String txt5 = "Dates"; // Dates
String txt1 = "Name"; //
String txt2 = "Titel event"; // Titel Event
void setup() {
//size(1080, 1920, PDF, "filename.pdf");
size(1080, 1920);
noLoop();
myFont = createFont("Helvetica-Bold", 5);
img = loadImage("test.jpg");
}
void draw() {
background(0);
textFont(myFont);
for (int i = 0; i < 7; i++) {
int w = int(random(100, 500));
int h = int(random(100, 500));
int x6 = int(random(-200, width));
int y6 = int(random(-200, height));
int w6 = int(random(100, 1080));
int h6 = int(random(100, 1080));
int x1 = int(random(-200, width));
int y1 = int(random(-200, height));
int w1 = int(random(100, 1080));
int h1 = int(random(100, 1080));
int x2 = int(random(-200, width));
int y2 = int(random(-200, height));
int w2 = int(random(100, 1080));
int h2 = int(random(100, 1080));
int x3 = int(random(-200, width));
int y3 = int(random(-200, height));
int w3 = int(random(100, 1080));
int h3 = int(random(100, 1080));
int x4 = int(random(-200, width));
int y4 = int(random(-200, height));
int w4 = int(random(100, 1080));
int h4 = int(random(100, 1080));
int x5 = int(random(-200, width));
int y5 = int(random(-200, height));
int w5 = int(random(100, 1080));
int h5 = int(random(100, 1080));
textSize((w+h) / 20);
fill(255, 255, 0);
rect(x1, y1, w1, h1);
fill(0); // text
text(txt1, x1+5, y1+5, w1, h1);
textAlign(CENTER, CENTER);
textSize((w+h) / 10);
fill(255, 255, 0);
rect(x2, y2, w2, h2);
fill(0); // text
text(txt2, x2+5, y2+5, w2, h2);
textAlign(CENTER, CENTER);
textSize((w+h) / 10);
fill(255, 255, 0);
rect(x3, y3, w3, h3);
fill(0); // text
text(txt3, x3+5, y3+5, w3, h3);
textAlign(CENTER, CENTER);
textSize((w+h) / 10);
fill(255, 255, 0);
rect(x4, y4, w4, h4);
fill(0); // text
text(txt4, x4+5, y4+5, w4, h4);
textAlign(CENTER, CENTER);
textSize((w+h) / 10);
fill(255, 255, 0);
rect(x5, y5, w5, h5);
fill(0); // text
text(txt5, x5+5, y5+5, w5, h5);
textAlign(CENTER, CENTER);
textSize((w+h) / 10);
fill(255, 255, 0);
rect(x6, y6, w6, h6);
fill(0); // text
text(txt6, x6+5, y6+5, w6, h6);
textAlign(CENTER, CENTER);
}
for (int i = 0; i < 2; i = i+1) {
int ximg = int(random(-200, width));
int yimg = int(random(-200, height));
int wimg = int(random(100, 1080));
int himg = int(random(100, 1080));
image(img, ximg, yimg, wimg, himg);
}
// exit();
println("Finished.");
}
// void keyPressed() {
// println("key: "+key+" keyCode: "+keyCode);
// if ( key == ' ' ) save("test2.jpg");
// }
/**
* Handle key presses
*
* Space = trigger one iteration
* s = save SVG
* s = save raster image
*/
void keyPressed() {
switch(key) {
case 's':
saveImage();
break;
case 'r':
reloadDrawing();
break;
}
}
void saveImage() {
save("instagramstory-" + hour() + minute() + second() + ".jpg");
println("Image saved");
}
void reloadDrawing() {
println("Reloaded Image");
}