How to reload a background using millis()

edited March 2015 in Questions about Code

Hello All,

Is it possible to bring the background forward and clear the screen? effectively I want blank canvas for everything apart from the background. I also want this to be timed, I am aware of Millis() but lack the knowledge to where to put the lines of code.

Thank you!!

:)>- :)>- :)>- :)>-

int frames = 10; 

PImage bg; 

PGraphics pg[] = new PGraphics[frames];

void setup() {

size(1024, 768);

 bg = loadImage("003-2.jpg");

 for(int i=0; i<frames; i++) {

pg[i] = createGraphics(width, height);








void draw() {

int currFrame = frameCount % frames; // 0 .. 19

if(mousePressed) {


pg[currFrame].line(mouseX, mouseY, pmouseX, pmouseY);



 image(pg[currFrame], 0, 0);



  • I fear I don't fully understand your question.
    Perhaps you just need to call background() at the sketch level?

  • Hi PhiLho

    I'm afraid I am a bit of a novice. I'm not quite sure where to put that line of code, I've tried repeatedly.

    Also Is there anyway I can do that at timed intervals using millis()?

  • _vk_vk
    Answer ✓

    You can search forum for "timing" or millis().

    this is an example I wrote for some other question:

    PFont font;
    String time = "000";
    int initialTime;
    int interval = 1000;
    color c = color(200);
    void setup()
      size(300, 300);
      font = createFont("Arial", 30);
      initialTime = millis();
    void draw()
      if (millis() - initialTime > interval)
        time = nf(int(millis()/1000), 3);
        initialTime = millis();
      text(time, width/2, height/2);
      if (int(time) % 10 == 0){
        c = color(random(255));

    I didn't understand the rest of your question. :)

Sign In or Register to comment.