Created
February 28, 2017 17:33
-
-
Save alexanderhenne/4cd94b0477568209f86259c3a74aaf9a to your computer and use it in GitHub Desktop.
Klockanimation i Processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() { | |
size(500, 500); | |
smooth(8); | |
generateRandomBgColors(); | |
} | |
// Cirkelns radie | |
// Konstant värde | |
int radius = 200; | |
float hour = 0; | |
float minute = 0; | |
// Fill/stroke-färger | |
int bgR = 0; | |
int bgG = 0; | |
int bgB = 0; | |
void draw() { | |
background(255); | |
translate(250, 250); | |
fill(bgR, bgG, bgB); | |
stroke(bgR, bgG, bgB); | |
strokeWeight(2); | |
point(0, 0); | |
noFill(); | |
ellipse(0, 0, pow(minute, 2) * 2, pow(minute, 2) * 2); | |
float minuteRatio = minute / 60; | |
pushMatrix(); | |
rotate(radians(-90 + 360 * minuteRatio)); | |
line(0, 0, radius * 0.8, 0); | |
popMatrix(); | |
pushMatrix(); | |
rotate(radians(-90 + (360 / 12) * hour + (360 / 12) * minuteRatio)); | |
line(0, 0, radius * 0.4, 0); | |
textAlign(RIGHT); | |
text(String.format("%02.0f:%02.0f", hour, minute), radius * 0.4, -5); | |
popMatrix(); | |
minute += 1; | |
if (minute >= 60) { | |
minute = 0; | |
hour++; | |
generateRandomBgColors(); | |
} | |
if (hour == 24) { | |
hour = 0; | |
} | |
} | |
void generateRandomBgColors() { | |
// (50, 50, 50) till (200, 200, 200) | |
// Begränsad för att inte få för mörka eller ljusa färger | |
bgR = (int) random(50, 200); | |
bgG = (int) random(50, 200); | |
bgB = (int) random(50, 200); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment