Hey everyone!
Couple of newbie question here, I’ve look trough the forum but I didn’t find what I was looking for.
I’m writing a simple countdown for a specific day.
Question 1:
Why processing doesn’t update the image? It doesn’t update the value in the texts.
Question 2:
I would have to countdown to a specific day (1 of June, 152 day of the year) what’s the best way to calculate the day of the year everyday? (int e in the sketch).
Thank you!
PFont font;
int a = day();
int b = (24 - hour());
int c = (60 - minute());
int d = (152); //1 June start day
int e = (78); //19 march
void setup()
{
size(1920, 1080);
font = createFont("ARIAL", 1000);
background(52, 152, 219);
fill(0);
frameRate(1);
}
void draw()
{
background(52, 152, 219);
textSize(100);
text("COUNTDOWN TO UEFA UNDER21:", width/12,height/5);
textSize(200);
text((d - e)+" giorni ", width/6,height/2);
textSize(200);
text(b+" ore ", width/6,height/1.4);
textSize(200);
text(c+" minuti", width/6,height/1.1);
println(second());
}
import java.util.*;
Calendar c = new GregorianCalendar();
Date countTo;
Date today;
long diff, diff_sec, diff_min, diff_hou, diff_day;
void update() {
c.set(Calendar.YEAR, 2019);
c.set(Calendar.MONTH, 6); // 6 = june
c.set(Calendar.DAY_OF_MONTH, 1); // 2019-06-01
countTo = c.getTime();
today = new Date();
diff = countTo.getTime() - today.getTime();
diff_sec = diff / (1000L); // convert to sec
diff_min = diff / (1000L*60L); // convert to min
diff_hou = diff / (1000L*60L*60L); // convert to hour
diff_day = diff / (1000L*60L*60L*24L); // convert to days!
println("days "+diff_day+" or hours "+diff_hou+" or minutes "+diff_min+" or seconds "+diff_sec);
}
void setup() {
frameRate(1);
}
void draw() {
update();
}
prints:
days 103 or hours 2495 or minutes 149759 or seconds 8985597
days 103 or hours 2495 or minutes 149759 or seconds 8985596
days 103 or hours 2495 or minutes 149759 or seconds 8985595
You can also check examples related to java.time.LocalDateTime if you what to explore other options. Because Processing is Java, you can always use any previously implemented solution in that language.
Thank you all!
So, I’ve solved in an easier and more “dumb” way.
-I take the value from “month ()”
-I use the “if” to associate the month to the number of the days present in that month e.s for Jannuary (1=31).
-Then I do a simple sum.
I’ll post the complete sketch asap.
If that approach works for you, go for it. I recommend you also try using an available library. This will give you the opportunity to read documentation and it will open the challenge to implement it in your own code. The nice thing about libraries is that it will handle oddities like leap years. With minor adjustments, you can also adjust your code to a time zone, if you were to include time information.