#### Howdy, Stranger!

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

# I need help with my project. (timezones)

edited May 2017

So i have a school project for tomorow but i dont know how to make clocks with different time zones and i dont really have much time so i would appreciate any help making three digital clocks in each corner with different time zones. Here is the code.

``````PImage bg;
int y;
int cx, cy;
float clockDiameter;
int timer;
int minutter;
int sekunder;

void setup() {
size(480, 360);
stroke(255);

size(480, 360);

int radius = min(width, height) / 2;

cx = width / 2;
cy = height / 2;
}

void draw() {
background(bg);

if (sekunder == 10) {
}
if (sekunder == 15) {
}
stroke(226, 204, 0);

y++;
if (y > height) {
y = 0;
}

timer = hour();
minutter = minute();
sekunder = second();

fill(#40ff00);
textSize(32);
text(timer +":" + minutter + ":" + sekunder, 20, 30);

fill(80);
noStroke();
ellipse(cx, cy, clockDiameter, clockDiameter);

float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI;
float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI;

stroke(255);
strokeWeight(1);
line(cx, cy, cx + cos(s) * secondsRadius, cy + sin(s) * secondsRadius);
strokeWeight(2);
line(cx, cy, cx + cos(m) * minutesRadius, cy + sin(m) * minutesRadius);
strokeWeight(4);
line(cx, cy, cx + cos(h) * hoursRadius, cy + sin(h) * hoursRadius);

strokeWeight(2);
beginShape(POINTS);
for (int a = 0; a < 360; a+=6) {
float x = cx + cos(angle) * secondsRadius;
float y = cy + sin(angle) * secondsRadius;
vertex(x, y);
}
endShape();
}
``````
Tagged:

• ``````PImage bg;
int y;
int cx, cy;
float clockDiameter;
int timer;
int minutter;
int sekunder;

void setup() {
size(1480, 360);
stroke(255);

int radius = min(width, height) / 2;

cx = width / 2;
cy = height / 2;
}

void draw() {

if (sekunder == 10) {
}
if (sekunder == 15) {
}

if (bg!=null)
background(bg);
else
background(0);

stroke(226, 204, 0);

clock (hour()-6, -490);
clock (hour(), 0);
clock (hour()+6, 490);
}

void clock (int timer, float xtr) {

pushMatrix();

translate(xtr, 0);

y++;
if (y > height) {
y = 0;
}

minutter = minute();
sekunder = second();

fill(#40ff00);
textSize(32);
text(timer +":" +  nf(minutter, 2) + ":" +  nf( sekunder, 2), cx-hoursRadius*2-44, 30);

fill(80);
noStroke();
ellipse(cx, cy, clockDiameter, clockDiameter);

float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI;
float h = map(timer + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI;

stroke(255);
strokeWeight(1);
line(cx, cy, cx + cos(s) * secondsRadius, cy + sin(s) * secondsRadius);
strokeWeight(2);
line(cx, cy, cx + cos(m) * minutesRadius, cy + sin(m) * minutesRadius);
strokeWeight(4);
line(cx, cy, cx + cos(h) * hoursRadius, cy + sin(h) * hoursRadius);

strokeWeight(2);
beginShape(POINTS);
for (int a = 0; a < 360; a+=6) {
float x = cx + cos(angle) * secondsRadius;
float y = cy + sin(angle) * secondsRadius;
vertex(x, y);
}
endShape();

popMatrix();
}
``````
• Thanks for the help @Chrisir but is it possible to make all those digital clocks in one square and remove the normal clocks. And what country or city the time zones are.

Do you see what he's done? Made a method to print one clock and called it three times with different offsets.

For digital clocks you just need to print the time. Use text(). And nf() to add leading zeroes.

• Could someone please give me an easy explenation of how to do different time zones i cant figure it out.

• ???

It's all in my example

Just strip it down and kill what is not needed

• The thing is that i have to explain my code at school so i need to understand what the code does and stuff and i dont understand barely any of your code. Mostly because its our first year with programming. So i would like to know if there is a command that u can type in to do a offset from the time that is on my computer.

• I really want to know how to do this code: `clock (hour()-6, -490);` without to much extra code to do it. Because i tried it and i really couldnt get it to work

• Post what you have.

And don't load images in draw - draw runs 60 times a second and load image is expensive.

• what I did was that I moved your clock into a function.

It is the block from

``````    void clock (int timer, float xtr) {

....

} // inline 106 above
``````

Think of a function as a small factory. This factory shows a clock. You can also pass parameters to the clock.

I pass `hour()-6` or `hour()` or `hour()+6` to it. This value gets into the variable `timer` (name from your original code) and is used then in the function. That's how we get our time zones!!!

Just call the same function 3 times with different values for the hours.

I also pass -490, 0 and 490 as a 2nd parameter to the function, to determine where this clock has to be drawn on the screen.

I use `pushMatrix` / `popMatrix` to isolate the drawing of each clock from the others and then `translate` to move it left by 490, or right by 490 or not at all (0).

Since this is homework, it would be cheating, if I did that for you

And what country or city the time zones are.

Invent a additional parameter `city` and pass it to the function

"Amsterdam"

or "New York"

``````void clock (int timer, float xtr, String city) {
``````

remove the normal clocks.

I want you to do that and post your resulting sketch.

Just show SOME code.

• if there is a command that u can type in to do a offset from the time that is on my computer.

that's what I did with `clock (hour()-6, -490);`

`hour()` is the time on your computer and `hour()-6` is 6 times zones east / 6 hours back

• I appreciate all the help i got but i dont have more time left so it is what it is. I hope i can remember what all the different codes do.

• But atleast i know all this next time im making something.

• And i understand that u cant just give the perfect finished code to me. That is cheating.