Ulysses

General => Developers Corner => Topic started by: talmera on July 02, 2014, 01:07:03 AM

Title: color rotation?
Post by: talmera on July 02, 2014, 01:07:03 AM
So I was wondering if anyone knows of a way to have an entity smoothly rotate through the colours of the rainbow? I was thinking of having a table of colours to cycle through but i was unsure of how to set it up to do so.
Title: Re: color rotation?
Post by: Stickly Man! on July 02, 2014, 08:32:04 AM
The easiest way is to use HSV color values instead of traditional RGB. See G.HSVToColor (http://wiki.garrysmod.com/page/Global/HSVToColor). If you set up a tick/think/whatever function to set the color of the entity every frame, you'll only need to increment the Hue value based on time. You could do that by storing your own variable and incrementing it manually, or just use the current time:
Code: [Select]
HSVToColor( CurTime() % 360, 1, 1 ).. Or something like that.

EDIT: You probably want to use RealTime() instead of CurTime(), as it appears that CurTime() is synced to the server, where RealTime() is not. CurTime() therefore could get out of sync or have lag issues, RealTime() should remain smooth on the clients.
Title: Re: color rotation?
Post by: talmera on July 03, 2014, 04:03:10 AM
ooooh thanks for the reply stickly hadn't thought of HSV that makes things way more simple :3