#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Need help for 12-hour PM/AM clock

edited October 2013

I'm trying to make a multi-functional background watch as an Android app but I'm having a difficulty figuring out how to make a 12-hour system with PM/AM, meaning that I've no idea how to do so.

Far I've made a 24-hour digital clock (which can be seen below) but I want to make an animated background for my watch at some point so that rect() I've made really gets in the way of doing that, so I need to know of a way to make it so the numbers doesn't keep going over each other endlessly without the use of a rect().

``````void draw(){
textAlign(LEFT);

int day = day();  // Values from 1 - 31
int month = month();  // Values from 1 - 12
int year = year();   // 2003, 2004, 2005, etc.
/*
String s = String.valueOf(day);
text(s, 10, 28);

s = String.valueOf(month);
text(b, 10, 56);

s = String.valueOf(year);
text(s, 10, 84);
*/
String d = String.valueOf(day);
String m = String.valueOf(month);
String y = String.valueOf(year);
text(d, 25, 25);

noStroke();
fill(255);
rect(150,250,135,25);

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

Also is there a different between the

``````  String s = String.valueOf(day);
s = String.valueOf(month);
s = String.valueOf(year);
``````

or

``````  String d = String.valueOf(day);
String m = String.valueOf(month);
String y = String.valueOf(year);
``````

Does it take more ram/bits to run my watch with String rather than just s or doesn't it matter at all? I'm aiming for making it the most optimal regarding usage of process power / whatever.

I also want to make a normal clock with lines but I'm finding it a little difficult to place the numbers (1-12) in a round circle, any suggestions how to do that beside just putting them in random places (x,y) until I think it looks decent?

PS. how do I use this forum? Bold doesn't seem to work and it doesn't write the code in the way I write it...

Tagged:

• hey fiskefyren,

here's a simple arc-style clock that I made a while ago for a project:

``````Radian[] a;
int weight = 50;

void setup()
{
size(1400, 900);
smooth();

for (int i=0; i < a.length; i++) {
a[i] = new Radian(2*weight*i+50, color(random(255),random(255),random(255)), i);
}

}
void draw()
{
background(255);
for (int i=0; i < a.length; i++) {
a[i].update();
stroke(a[i].col);
noFill();
strokeWeight(weight);
strokeCap(SQUARE);
}
}
int distance, col, type;
float finish;

Radian (int distance, color col, int type ){
this.finish = 0;

this.distance = distance;
this.col = col;
this.type = type;
}
void update (){
int t = this.type;
switch (this.type) {
case 0:
this.finish = h();
break;
case 1:
this.finish = m();
break;
case 2:
this.finish = s();
break;
}

}
float h() {
int h = hour();
if (h >12) {
} else {
}
}
float m() {
int m = minute();
}
float s() {
int s = second();
}

}
``````

Hopefully this gets you started in the right direction.

as for code formatting, I paste my code in, then click the big 'C' at the top of the textfield. It doesn't seem to do much visually in the editor, it would be nice to get line numbers or something. I think it will code-format it once posted though. As for bold, it looks like it's using Markdown - adding two stars to either side to indicate the bolded word. There's a link to the markdown wikipedia page at the bottom to learn more about what you can use with that.

Hope this helps! ak

• Multiple declarations or only one: it doesn't matter, prefer the most readable / meaningful way...
• Code: there is a button for that, above the edit area.
• Bold: ditto...