Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count up and down elegantly

Tags:

c++

math

logic

I'm trying to make a flashing object, i.e., increment it's alpha value from 0 to 255 (gradually) and then back down to 0, and repeat.

Is there a way I can do this without using some boolean? Getting it to increment is easy:

alpha = time.elapsed()%256;

But what's a nice way to get it to count back down again after that?

like image 891
mpen Avatar asked Mar 21 '26 18:03

mpen


1 Answers

How about using a sin function, that way the fading is more pleasant and you'll get what you want.

like image 182
Tom Avatar answered Mar 24 '26 07:03

Tom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!