We are about to switch to a new forum software. Until then we have removed the registration on this forum.
If I wanted to make a clock where the minute and hour hands are invisible, but appear whenever the hand that precedes it passes over it, (i.e. Minute hand appears when second hand passes over it and then disappears, and the hour hand appears when minute hand is over it then disappears) what lines would I have to input at each angle that they meet??? (I am an absolute beginner)
int cx, cy; float secondsRadius; float minutesRadius; float hoursRadius; float clockDiameter;
void setup() { size(1300, 690); stroke(255);
int radius = min(width, height) / 2; secondsRadius = radius * 0.72; minutesRadius = radius * 0.60; hoursRadius = radius * 0.50; clockDiameter = radius * 1.8;
cx = width / 2; cy = height / 2; }
void draw() { background(0);
// Draw the clock background fill(255); stroke(0); noStroke(); ellipse(cx, cy, clockDiameter, clockDiameter);
// Angles for sin() and cos() start at 3 o'clock; // subtract HALF_PI to make them start at the top 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;
// Draw the hands of the clock stroke(0); strokeWeight(2); line(cx, cy, cx + cos(s) * secondsRadius, cy + sin(s) * secondsRadius); strokeWeight(4); stroke(255,0,0); fill(255,0,0); line(cx, cy, cx + cos(m) * minutesRadius, cy + sin(m) * minutesRadius); // print(cx); strokeWeight(5.5); stroke(2,10,198); fill(2,10,198); line(cx, cy, cx + cos(h) * hoursRadius, cy + sin(h) * hoursRadius);
// Draw the minute ticks stroke(0); strokeWeight(3); beginShape(POINTS); for (int a = 0; a < 360; a+=6) { float angle = radians(a); float x = cx + cos(angle) * secondsRadius; float y = cy + sin(angle) * secondsRadius; vertex(x, y); } endShape(); }
Answers
Start with a clock. Figure out which functions you will need to get the current time. If you don't know them already, look in the reference to see what you can find. Hint: One of them is hour().
Now try drawing a basic clock. You'll need to draw lines. At the right angles. You might be interested in the functions translate(), rotate(), and line(). You might also care to set the stroke() and background().
Post your clock code once you have it working.
Not drawing the hands unless certain conditions are met should be easy to add after you have a working clock.
int cx, cy; float secondsRadius; float minutesRadius; float hoursRadius; float clockDiameter;
void setup() { size(1300, 690); stroke(255);
int radius = min(width, height) / 2; secondsRadius = radius * 0.72; minutesRadius = radius * 0.60; hoursRadius = radius * 0.50; clockDiameter = radius * 1.8;
cx = width / 2; cy = height / 2; }
void draw() { background(0);
// Draw the clock background fill(255); stroke(0); noStroke(); ellipse(cx, cy, clockDiameter, clockDiameter);
// Angles for sin() and cos() start at 3 o'clock; // subtract HALF_PI to make them start at the top 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;
// Draw the hands of the clock stroke(0); strokeWeight(2); line(cx, cy, cx + cos(s) * secondsRadius, cy + sin(s) * secondsRadius); strokeWeight(4); stroke(255,0,0); fill(255,0,0); line(cx, cy, cx + cos(m) * minutesRadius, cy + sin(m) * minutesRadius); // print(cx); strokeWeight(5.5); stroke(2,10,198); fill(2,10,198); line(cx, cy, cx + cos(h) * hoursRadius, cy + sin(h) * hoursRadius);
// Draw the minute ticks stroke(0); strokeWeight(3); beginShape(POINTS); for (int a = 0; a < 360; a+=6) { float angle = radians(a); float x = cx + cos(angle) * secondsRadius; float y = cy + sin(angle) * secondsRadius; vertex(x, y); } endShape(); }
one empty line before one empty line after
select the block of code
hit ctrl-c or the 'C' button.
done. code readable : )
yes, go back, edit your post and format the code correctly
as has been said