void setup() { size(500, 500); colorMode(HSB); background(0); frameRate(1); } void draw() { float h, m, s; float radius; float cx, cy; float clockface; float hoursRadius, minutesRadius, secondsRadius; float minuteDotSize, hourDotSize; radius = min(height, width)/2.0; cx = width/2.0; cy = height/2.0; clockface = radius*0.9; hoursRadius = radius*0.50; minutesRadius = radius*0.65; secondsRadius = radius*0.72; minuteDotSize = radius*0.015; hourDotSize = radius*0.03; // get time s = second(); m = minute(); h = hour()%12; // display time // draw clock face fill(128); noStroke(); ellipseMode(RADIUS); ellipse(cx, cy, clockface, clockface); // draw the ticks for (float pos=0; pos<60; pos+=1) { drawTick(cx, cy, pos*6, secondsRadius, minuteDotSize); drawTick(cx, cy, pos*6, secondsRadius, hourDotSize); } // draw the hands drawHand(cx, cy, s*6, secondsRadius, 1); drawHand(cx, cy, m*6, minutesRadius, 2); drawHand(cx, cy, h*30, hoursRadius, 4); } float handPos(float angle) { return radians(angle-90); } color colorPos(float angle) { return color(map(angle, 0, 360, 0, 255), 255, 255); } void drawHand(float cx, float cy, float angle, float len, float weight) { stroke(colorPos(angle)); strokeWeight(weight); line(cx, cy, cx + cos(handPos(angle))*len, cy + sin(handPos(angle))*len); } void drawTick(float cx, float cy, float angle, float len, float size) { fill(colorPos(angle)); noStroke(); rectMode(CENTER); rect(cx + cos(handPos(angle))*len, cy + sin(handPos(angle))*len, size, size); }