I know there is probably a way easier way to do this but i am trying to make a function that makes a color fade back and forth from two colors. Example, black and blue
Color(0, 255, 255)
and
Color(0, 0, 0)
i am using timer.Create() to run the function every 0.01 seconds, i want a derma frame to change colors base on the functions output. I just cant seem to find a way to set a range between two values and once a max value is reached subtract till the min value is reached then back and forth. Sorry if this is confusing.
I am currently using if statements because i am trash at Lua but i cant seem to get it to work. Anyone have some special tricks? Help is much appreciated!
logic of the go till something and subtract to where it came is done with sine/cosine function since they are repeative or something am not good on terms. using a timer for that is not good, you have to use panel.Paint and call the function in there.
Amazing that helps a lot actually, is there a way to make it faster? The code snippet you gave at the bottom i believe is ran with RealTime meaning it is ran with "real time" instead of a set interval. I am trying to make it fade pretty quick. Thanks for the help still, helped me understand a lot of the math stuff i don't really pay attention too but should haha
Code Snippet im refering too
math.abs(math.sin(RealTime())) * 255
I did not try, but following thing comes logical to me:
math.abs(math.sin(RealTime()*2)) * 255
i would recommend using this instead:
255 * (1 + math.sin(RealTime() * speedfactor))/2
using abs will result in a sharp, sudden change in colour at the end of every cycle
if you want it to start at zero instead of 0.5 you can change 1 + math.sin to 1 - math.cos
Sorry, you need to Log In to post a reply to this thread.