Random Date Generator
in
Programming Questions
•
2 years ago
I'm trying to create a random date generator (borrowed some code from
here) that generates dates in the future but I'm encountering a few problems. With my current code (below) the random dates sometimes are in the past or have the value "00". IS there a way to get around this, perhaps with using day() seconds() etc?
- PFont reloj;
int h; // hour
int m; // minute
int s; // second
int d; // day
int mo; // month
int y; // year
int lastsecond = 0;
void setup() {
frameRate(60);
reloj = loadFont("Commodore_64_Angled-48.vlw");
size(700,100);
loop();
textFont (reloj);
}
void draw() {
h = int(random(24));
m = int(random(60));
s = int(random(60));
d = int(random(31));
mo = int(random(12));
y = int(year()+random(2));
if (lastsecond != s) {
background(0);
String y2 = nf(y,2);
String y3 = y2.substring(2,4);
String date = nf(h,2)+":"+nf(m,2)+":"+nf(s,2)+" "+nf(d,2)+"/"+nf(mo,2)+"/"+y3;
println (date);
// print text on screen
fill(114,234,183);
text(date,23,60);
filter(DILATE);
filter(BLUR,8);
fill(176,242,215);
text(date,20,60);
filter(BLUR,1);
// horizontal lines
for (int y = 0; y <= height; y+= 5) {
strokeWeight(0.1);
stroke(20,200,20,20);
line (0, y, width, y);
}
saveFrame("fecha-####.png");
}
lastsecond = s;
fill(0,random(0,3));
rect(0,0,width,height);
//To select a date
if((keyCode == ENTER)) {
noLoop();
}
}
1