An issue with the background for a digital clock

Hello, I want to make a simple background clock for my Android phone but I'm a little stuck with the code. I want to program an animated background at some point but before I can do that I need to fix an issue with my code.

void setup(){
  size(300,300);
  background(0,0,255);
}

void draw(){
  smooth(); // this doesn't seem to do anything...
  //clear(); // can't use this one, it removes the background
  textSize(30);
  textAlign(LEFT);

  int day = day();     // Values from 1 - 31
  int month = month(); // Values from 1 - 12
  int year = year();   // 2003, 2004, 2005, etc.

  String d = String.valueOf(day);
  String m = String.valueOf(month);
  String y = String.valueOf(year);
  fill(255);
  text(d+"/"+m+"-"+y, 25, 25);

///// if i remove this all hell breaks lose /////
  noStroke();
  fill(255);
  rect(150,250,135,25);
/////////////////////////////////////////////////

  fill(0);
  text(nf(hour(), 2)+":"+nf(minute(), 2)+":"+nf(second(), 2),150,275);
}

As you can see I've made a box around the time/clock, I want to get rid of it so it doesn't mess with the background (that is currently blue) but if I remove it (the rect) then the time/clock overlaps itself. I tried to fix this with a clear(); but it wipes the background, so I would really like some help with this.

PS. I do intent to use classes for this but right now I would really like to know of a way to fix this issue, before I move onward.

Thanks!

Tagged:

Answers

  • If you have some drawing which you need to modify w/o affecting the rest, you gotta use a separate PGraphics for it:
    http://processing.org/reference/PGraphics.html

    And if you got a static background, you should definitely create a PImage copy of it and use it as background()! :D

  • PGraphics? I'll try to give it a shot and see what comes out of it :)

    A PImage for a static background? But I instead to program one, not make a gif or something like that.

  • By static background I mean the elements which don't animate. It's always the same!
    Animated drawings are called dynamic too!

Sign In or Register to comment.