We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Creating an interface similar to polar clock tweak
Page Index Toggle Pages: 1
Creating an interface similar to polar clock tweak (Read 661 times)
Creating an interface similar to polar clock tweak
Mar 29th, 2010, 6:31pm
 
I'm trying to create an interface similar to how polar clock works
I'm just starting out with trying to get the seconds bit working correctly..

My code so far is:
Code:

float radius = 75;
float clockDiameter = radius * 2;
float cx, cy;

void setup() {
size(200, 200);
background(127);
cx = 100;
cy = 100;
}

void draw() {
//ellipse(cx, cy, clockDiameter, clockDiameter);
float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
stroke(255);
strokeWeight(1);
float theta = radians(s);
//arc(cx, cy, clockDiameter, clockDiameter, PI, radians(250));
//line(cx, cy, cx + cos(s) * radius, cy + sin(s) * radius);
//arc(50, 55, 80, 80, TWO_PI-PI/2, TWO_PI);
arc(cx, cy, clockDiameter, clockDiameter, TWO_PI-PI/2, theta);
}


I'm having trouble with the PI bit in the arc call I think.. I'm close I think.. Can someone shed some light? I'm trying to do it so the arc always starts at the top like on a analog clock and depending on how many seconds there are define an angle for the end position..

Thanks

Dan
Re: Creating an interface similar to polar clock tweak
Reply #1 - Apr 1st, 2010, 6:19pm
 
I've revised my code to this
Code:

float radius = 75;
float clockDiameter = radius * 2;
float cx, cy;

void setup() {
size(200, 200);
background(127);
smooth();
cx = 100;
cy = 100;
}

void draw() {
background(127);
//ellipse(cx, cy, clockDiameter, clockDiameter);
float s2 = map(second(), 0, 60, 0, PI) - HALF_PI;
int s = second();
stroke(255);
strokeWeight(1);
float theta = radians(s) * 6;
arc(cx, cy, clockDiameter, clockDiameter, -PI / 2, theta);

text(s, 20, 20);
text(s2, 40, 20);
}


It's still not working how I want it but I'm slightly closer.. I can see whats wrong with it now.. Because of something to do with the math.. 0 degrees on the circle is east.. normally where 90 degrees would be.. so when the seconds reach 60 and start back at 0 it's filling a quarter of the circle straight away... ahhhhh does anyone know a way around this?

Dan
Re: Creating an interface similar to polar clock tweak
Reply #2 - Apr 1st, 2010, 9:23pm
 
Not sure what you want to see.  If you want to shift from the 3:00 position to the 12:00 position, though, that's a shift of -PI/2...so:

float theta = radians(s) * 6;

could become

float theta = radians(s) * 6 - PI/2;
Page Index Toggle Pages: 1