At the moment, I have dots/ellipses around the clock as marks for the numbers. I’m trying to make them as lines, like a normal analog clock has, but I’m not sure how to do this. So how do I make the dots/ellipses as lines?
int hourHand = 135;
int minHand = 210;
int secHand = 250;
int centerX = 350;
int centerY =350;
float angle;
float x;
float y;
void setup() {
size(700, 700);
}
void draw () {
stroke(255);
background(0);
float quarterCircle = PI/2;
// for the ellipse
for (int i=1; i<=60; i++) {
angle = i * PI / 30.0;
float x = (centerX + cos(angle)* secHand);
float y =(centerY + sin(angle)* secHand);
if(i % 5 != 0) {
point(x,y);
}
else {
ellipse(x, y, 5, 5);
}
}
//hour hand
strokeWeight(1);
stroke(255);
line(centerX, centerY, x, y);
angle = ((2 * PI/12) * hour()) + ((2 * PI/720) * minute()) - quarterCircle ;
x = centerX + hourHand * cos(angle);
y = centerY + hourHand * sin(angle);
//minute hand
strokeWeight(4);
stroke(255);
line(centerX, centerY , x, y);
angle = ((2 * PI/60) * minute()) - quarterCircle;
x = centerX + minHand * cos(angle);
y = centerY + minHand * sin(angle);
//second hand
strokeWeight(2);
stroke(255);
line(centerX, centerY , x, y);
angle = ((2 * PI/60) * second()) - quarterCircle;
x = centerX + secHand * cos(angle);
y = centerY + secHand * sin(angle);
}
Chrisir
February 23, 2021, 9:25am
2
Hello,
you can use the points (x,y) you already have for the new line.
Then you calculate another point x2,y2 nearer the clock’s center (just a smaller radius).
connect both points with a line : line(x, y, x2, y2);
Warm regards,
Chrisir
int hourHand = 135;
int minHand = 210;
int secHand = 250;
int centerX = 350;
int centerY =350;
float angle;
float x;
float y;
void setup() {
size(700, 700);
}
void draw () {
stroke(255);
background(0);
float quarterCircle = PI/2;
// for the ellipse
for (int i=1; i<=60; i++) {
angle = i * PI / 30.0;
float x = (centerX + cos(angle)* secHand);
float y = (centerY + sin(angle)* secHand);
float x2 = (centerX + cos(angle)* (secHand-11));
float y2 = (centerY + sin(angle)* (secHand-11));
if (i % 5 != 0) {
//point(x, y);
line(x, y,
x2, y2);
} else {
line(x, y,
x2, y2);
ellipse(x, y, 5, 5);
}
}
//hour hand
strokeWeight(1);
stroke(255);
line(centerX, centerY, x, y);
angle = ((2 * PI/12) * hour()) + ((2 * PI/720) * minute()) - quarterCircle ;
x = centerX + hourHand * cos(angle);
y = centerY + hourHand * sin(angle);
//minute hand
strokeWeight(4);
stroke(255);
line(centerX, centerY, x, y);
angle = ((2 * PI/60) * minute()) - quarterCircle;
x = centerX + minHand * cos(angle);
y = centerY + minHand * sin(angle);
//second hand
strokeWeight(2);
stroke(255);
line(centerX, centerY, x, y);
angle = ((2 * PI/60) * second()) - quarterCircle;
x = centerX + secHand * cos(angle);
y = centerY + secHand * sin(angle);
}