We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I made a clock sketch that displays the time from my computer, but I was wondering if there was a way I could use arrays to make the numbers cycle through at random. (My knowledge of processing is sort of limited at the moment)
My code for my current project is here
DigitalClock digitalClock;
void setup() {
size(1080, 720);
digitalClock = new DigitalClock(40, width/2, height/2+15);
}
void draw() {
background(0);
digitalClock.getTime();
digitalClock.display();
}
class DigitalClock extends Clock {
int fontSize;
float x, y;
DigitalClock(int _fontSize, float _x, float _y) {
fontSize = _fontSize;
x = _x;
y = _y;
}
void getTime() {
super.getTime();
}
void display() {
textSize(100);
textAlign(CENTER);
text (h + ":" + nf(m, 2) + ":" + nf(s, 2), x, y);
}
}
class Clock {
int h, m, s;
Clock() {
}
void getTime() {
h = hour();
m = minute();
s = second();
}
}
Answers
Sorry, just to clarify, you want to just have random numbers be put on the clock everytime it updates?
Yeah, like I want the format to stay looking like a clock, but I wanted the actual numbers to cycle through 1-9 at random, like the clock is haphazardly running out of control. Maybe somehow I could use an array or the random() coding?
Code I changed -
digitalClock.randomizeTime();
And I added the randomizeTime() method
It's probably not the exact effect you want but hopefully it's a starting place!
That's pretty darn close! Thank you so much! One last noob question tho: how do I slow down the rate at which the clock randomizes?
Never mind, I just adjusted the frame rate! Bless you and thank you for helping me out!
Yeah no problem! Additionally, if you wanted to keep the framerate the same, you could say
in the draw loop, which would make it change every other frame! Just another idea :)