# Void draw() again?

**URL:** <https://discourse.processing.org/t/void-draw-again/15610>\
**Category:** Coding Questions\
**Created:** [November 18, 2019, 3:07pm UTC](https://discourse.processing.org/t/void-draw-again/15610 "2019-11-18T15:07:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanoevelenstef](https://avatars.discourse-cdn.com/v4/letter/v/41988e/32.png) [@vanoevelenstef](https://discourse.processing.org/u/vanoevelenstef)\
**Post date:** [November 18, 2019, 3:07pm UTC](https://discourse.processing.org/t/void-draw-again/15610/1 "2019-11-18T15:07:08Z")

</div>

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!

```auto
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"); 
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 18, 2019, 3:17pm UTC](https://discourse.processing.org/t/void-draw-again/15610/2 "2019-11-18T15:17:42Z")

</div>

When you delete noLoop, the function draw() runs automatically on and on, 60 times per second

You can slow that down when you say frameRate (3);

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 18, 2019, 3:22pm UTC](https://discourse.processing.org/t/void-draw-again/15610/3 "2019-11-18T15:22:33Z")

</div>

in keyPressed just say redraw();

See reference

Forget about my last post…

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 18, 2019, 3:23pm UTC](https://discourse.processing.org/t/void-draw-again/15610/4 "2019-11-18T15:23:45Z")

</div>

[https://processing.org/reference/redraw\_.html](https://processing.org/reference/redraw_.html)

---

<div class="post-metadata">

**Author:** ![vanoevelenstef](https://avatars.discourse-cdn.com/v4/letter/v/41988e/32.png) [@vanoevelenstef](https://discourse.processing.org/u/vanoevelenstef)\
**Post date:** [November 18, 2019, 3:36pm UTC](https://discourse.processing.org/t/void-draw-again/15610/5 "2019-11-18T15:36:31Z")

</div>

Thanks mate.  
I didn’t know that was even a function, thank you!
