We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I try using setInterval() but idk. Here is my code before messing with it:
var dark = true; function setup() { createCanvas(250, 250); createP(''); createButton('click me').mousePressed(swap); } function draw() { dark ? background(0) : background(0,255,0); } function swap() { dark = !dark; }
Answers
Maybe look at colorLerp but you need additional vars to tell you how far the process of color change is
The code is avaialble in Java (Processing). Maybe you can find it in JS. It is related to fading, transition between two images, etc. Check it out: https://forum.processing.org/two/search?Search=fade
Kf
Need a little bit more help here :/
Two posts that are relevant:
https://forum.processing.org/two/discussion/22354/text-fade-to-black-with-mouse-click/p1
https://forum.processing.org/two/discussion/comment/96814/#Comment_96814
Did you have a look at those ones? Are you familiar with tint p5.js version? https://p5js.org/reference/#/p5/tint
Kf
Hi Banana,
I'm new to P5* myself, I worked your code into the following:
Hope this helps, but as I say I am a novice myself and the links above make good reading. Hope this helps answer your question.
Snapper
Thanks yall two for putting up with me and helping me. Snapper, I like how you work with my code. I would change your swap function with:
We can use boolean here too. I know that from Coding Train youtube tutorials. Right now, I am trying to understand why fadeColour stops at 255 and does not keep going...
Hi Banana,
Yes your updated swap function is the best (shortest / faster) way. fadeColour is set by the two "if" conditions under draw(). In RGB the range is (0 - 255 or old skool - one byte !) Anything above 255 still works but does nothing more to the colour visually it's at the maximum level of, in this case Green. Once Green > 255 the incremental fadeColour+=5; instruction gets ignored because the "if" conditions are no longer true.
Check https://p5js.org/reference/#/p5/colorMode
Kf