Processing Polar Clock Minute Arc.. Just need a second pair of eyes to look at..
in
Programming Questions
•
3 years ago
I'm trying to recreate polarclock in processing, I've got so it displays the arcs according to the correct time, but I'm trying to make the second arc update in every frame (24 frames a second) instead of just every second (1 frame a second) to create a very smooth animation. I trying to use millis() to do this, but just can't figure it out for the life of me, the specific line of code is on line 42/43.
Any help would be appreciated.
Thanks
Dan
- int diameter;
- int arc_x;
- int arc_y;
- float degrees_0;
- float degrees_90;
- float degrees_180;
- float degrees_270;
- float degrees_360;
- PFont font;
- void setup() {
- size(640, 480); // Sets the size of the application
- frameRate(24); // Sets the frame rate of the appliation
- smooth(); // Anti Aliasing on
- strokeCap(SQUARE); // Sets the edges of the arc to square instead of round
- font = loadFont("BauhausStd-Medium-42.vlw");
- textFont(font);
- diameter = 200;
- arc_x = width / 2; // Arcs aligned to the centre of the screen
- arc_y = height / 2; // Arcs aligned to the centre of the screen
- degrees_0 = map(0, 0, 360, 0, TWO_PI) - HALF_PI;
- degrees_90 = map(90, 0, 360, 0, TWO_PI) - HALF_PI;
- degrees_180 = map(180, 0, 360, 0, TWO_PI) - HALF_PI;
- degrees_270 = map(270, 0, 360, 0, TWO_PI) - HALF_PI;
- degrees_360 = map(360, 0, 360, 0, TWO_PI) - HALF_PI;
- }
- void draw() {
- background(200);
- noFill();
- strokeWeight(20);
- text("The time is: " + hour() + ":" + minute() + ":" + second(), 20, 50);
- text("The date is: " + day() + ":" + month() + ":" + year(), 20, 460);
- float secondAngle = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;
- //float secondAngle = map(second() + norm(millis(), 0, 1000), 0, 60, 0, TWO_PI) - HALF_PI;
- float minuteAngle = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI;
- float hourAngle = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI) - HALF_PI;
- float dayAngle = map(day(), 1, 31, 0, TWO_PI) - HALF_PI;
- float monthAngle = map(month(), 1, 12, 0, TWO_PI) - HALF_PI;
- float monthDiameter = diameter * 1.8;
- float dayDiameter = diameter * 1.6;
- float secondDiameter = diameter * 1.4;
- float minuteDiameter = diameter * 1.2;
- float hourDiameter = diameter;
- // Second Arc
- stroke(255);
- arc(arc_x, arc_y, secondDiameter, secondDiameter, degrees_0, secondAngle);
- // Minute Arc
- stroke(245);
- arc(arc_x, arc_y, minuteDiameter, minuteDiameter, degrees_0, minuteAngle);
- // Hour Arc
- stroke(235);
- arc(arc_x, arc_y, hourDiameter, hourDiameter, degrees_0, hourAngle);
- // Day Arc
- stroke(225);
- arc(arc_x, arc_y, dayDiameter, dayDiameter, degrees_0, dayAngle);
- // Month Arc
- stroke(215);
- arc(arc_x, arc_y, monthDiameter, monthDiameter, degrees_0, monthAngle);
- if(second() == 0) {
- stroke(255);
- ellipse(arc_x, arc_y, secondDiameter, secondDiameter);
- }
- }
1