We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I wrote this short code below. It compiles, but I don't know how to loop and re-initiate the same 3 fades again and again, any tip please?! Thanks a lot in advance. Best, L
int fadeStartTime;
int fadeDuration = 2000; // 3 seconds
int intervalTime=6000;
float f;
void setup() {
size(1920, 1080);
frameRate(25);
fadeStartTime = millis();
//f = fade(millis(), fadeStartTime, fadeDuration, 0, 255); //0->3secs = 0->255 alpha
}
void draw() {
background(255);
noStroke();
int dur = millis()-fadeStartTime;
// 1)TURKISH
if ( millis() >=dur && dur <fadeStartTime+fadeDuration ) {
f = fade(dur, fadeStartTime, fadeDuration, 255, 0); //0->3secs = 0->255 alpha : fade to black
}
if ( dur >fadeStartTime+fadeDuration+ intervalTime && dur <fadeStartTime+fadeDuration+ intervalTime +fadeDuration ) {
f = fade(dur, fadeStartTime+fadeDuration+ intervalTime, fadeStartTime+fadeDuration+ intervalTime+ fadeDuration, 0, 255);//8->10secs = 255->0 alpha : fade to black
}
if (dur >fadeStartTime+fadeDuration*2+ intervalTime && dur < fadeStartTime+fadeDuration*3+ intervalTime ) {
f = fade(dur, fadeStartTime+fadeDuration*2+ intervalTime, fadeStartTime+fadeDuration*3+ intervalTime, 255, 0);//10->12secs = 0->255 alpha :fade to text
// 2)FRENCH
}
if (dur > fadeStartTime+fadeDuration*3+ intervalTime*2 && dur < fadeStartTime+fadeDuration*4+ intervalTime*2 ) {
f = fade(dur, fadeStartTime+fadeDuration*3+ intervalTime*2, fadeStartTime+fadeDuration*4+ intervalTime*2, 0, 255);//18->20secs = 255->0 alpha: fade to black
}
if (dur > fadeStartTime+fadeDuration*4+ intervalTime*2 && dur < fadeStartTime+fadeDuration*5+ intervalTime*2 ) {
f = fade(dur, fadeStartTime+fadeDuration*4+ intervalTime*2, fadeStartTime+fadeDuration*5+ intervalTime*2, 255, 0);//20->22secs = 255->0 alpha: fade to text
// 3)ALSACIAN
}
if (dur > fadeStartTime+fadeDuration*5+ intervalTime*3 && dur < fadeStartTime+fadeDuration*6+ intervalTime*3 ) {
f = fade(dur, fadeStartTime+fadeDuration*5+ intervalTime*3, fadeStartTime+fadeDuration*6+ intervalTime*3, 0, 255);//28->30secs = 255->0 alpha: fade to black
}
if (dur > fadeStartTime+fadeDuration*6+ intervalTime*3 && dur < fadeStartTime+fadeDuration*7+ intervalTime*3 ) {
f = fade(dur, fadeStartTime+fadeDuration*6+ intervalTime*3, fadeStartTime+fadeDuration*7+ intervalTime*3, 255, 0);//30->32secs = 255->0 alpha: fade to text
}
fill(0, 0, 0, f);
rect(0, 0, 1920, 1080);
if (dur > fadeStartTime+fadeDuration*7+ intervalTime*3) {
// HOW TO LOOP?
}
}
float fade (float amt, float start1, float stop1, float start2, float stop2) {
return constrain(
map ( amt, start1, stop1, start2, stop2 ),
min(start2, stop2),
max(start2, stop2)
);
}
Answers
Please explain clearly what you want the code to do. Do you want it to:
Should this be a fade-out / fade-in, or a cross-fade? Should two different texts ever appear at the same time? Should each period of showing be the same duration, or different durations? EXPLAIN.
Hi Jeremy and thanks for answering my question...I would like to fade to black be tween each language, this is working, that each text will be screen during different Time, this should work too but after these 3 languages I' like to start over again(turkish, french and aksacian) and I don ' t find a way to do so. Thanks a lot for your help. Best, laurent
My attempt as a proof of concept and with room for improvement.
Kf
P.S. Notice your code is not properly working... Do you need to figure out the colors?
Dear kfrajer,
Thank you very much, it works better than my version for sure ;)) Strangely there is a blinck of black frame at the end of the 1rst fade and it looks as the fades in work properly, not the fades out ?! It doesn't loop properly with fadeSartTime=millis(), why? Sorry to bother with these new questions... Thanks for the help. best, L
Dear Jeremy, Yes, I would like to to this :
This should be a fade-out / fade-in at the and of the prevoious/ begining of the next text .A single text ever appear at the same time. Each period of showing should be of different durations.
I hope this time it is clear? Thank you very much for your help. best, L
Dear KFrajer, Sorry for harassing you yersteday, I had a very bad day at work (for tv) not able to focus on this issue. I really apologize for insisting without any cause. Thank you very much for your help I will remember to use 'switch' to record different states nex time. I have intergrated the code to my sketch and now it works perfectly. Best wishes, L
@lolonulu Not a problem at all. I am just having busy days. Good you got it working. Post if you have any other questions.
Kf
This is my attempt working with transition/fading between two selected colors.
Kf
Whaow ! Great piece of code dear kfrajer thank you very much for sharing, sure it will be very useful ;))