Jump to content
Search Community

A better color cycle for several elements

Acccent test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hey!
 
since I've asked a couple questions I thought I'd give one of the snippets I finished working on, which actually works :)
 
So I know the new cycle feature allows HSL color manipulation, however that makes for suboptimal cycles through the whole color spectrum. I'm basing my info on this: http://basecase.org/env/on-rainbows — Basically, when using a purely hue-based cycle, you get spikes in luminosity that highlight certain colors and make others look washed out.
 
So I implemented a 'better' cycle!
 
You can find the result here:
Here's what it does:

  • it assigns a random initial value to each element (let's call it the color index); this index is used to generate an RGB color
    • an approximation of the golden ratio is used to ensure that the initial colors are as spread out around the hue spectrum as possible
  • the initial color index of each element is stored in an array
  • we then cycle through all of the elements to increase their index by 2 * Math.PI / 36 (= 10 degrees)
  • then animate all of the colors towards a new RGB color, generated from the color index we just increased

 

I initially thought I could do that using only a TimelineMax, but had no success with it; you can find the attempt there:

See the Pen avLLXm by Accent (@Accent) on CodePen

(Seems like it won't work because the values are cached, so each time the animation loops it starts from the initial color index instead of the newly increased one. If anyone has an idea to make that one work, go for it!)

 

Cheers :)

See the Pen XmeYZJ by Accent (@Accent) on CodePen

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...