Bonjour,
je voulais une petite horloge sur mon bureau dont je voulais pouvoir modifier la taille
alors j'ai légèrement modifié le programme d'horloge donné sur le site de Processing.
La voilà si ça peut être utile à quelque chose
Le code Processing :
int cx, cy;
float secondsRadius;
float minutesRadius;
float hoursRadius;
float clockDiameter;
float oldWidth,oldHeight;
int radius;
void setup() {
size(100,100);
stroke(255);
smooth();
setParam();
frame.setResizable(true);
}
void draw() {
background(0); // noir
if(width != oldWidth || height != oldHeight) {
setParam();
}
// Draw the clock background
fill(#E185F0);
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(255);
strokeWeight(1*radius/70+1);
stroke(#F0E8A7,188); // jaune
line(cx, cy, cx + cos(s) * secondsRadius, cy + sin(s) * secondsRadius);
strokeWeight(3*radius/70+1);
stroke(#2CA04D,188); // vert
line(cx, cy, cx + cos(m) * minutesRadius, cy + sin(m) * minutesRadius);
strokeWeight(6*radius/70+1);
stroke(#3750C9,100); // bleu
line(cx, cy, cx + cos(h) * hoursRadius, cy + sin(h) * hoursRadius);
stroke(255);
// Draw the minute ticks
strokeWeight(int(radius/11));
beginShape(POINTS);
for (int a = 0; a < 360; a+=30) {
float x = cx + cos(radians(a)) * secondsRadius;
float y = cy + sin(radians(a)) * secondsRadius;
vertex(x, y);
}
endShape();
}
void setParam() { // Les paramètres à remettre à jour quand on change la taille de la fenêtre
radius = min(width, height) / 2;
secondsRadius = radius * 0.72;
minutesRadius = radius * 0.60;
hoursRadius = radius * 0.40;
clockDiameter = radius * 1.8;
println(radius);
cx = width / 2;
cy = height / 2;
oldWidth = width;
oldHeight = height;
}
Hors ligne