Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I cycle through hex color codes in PHP?

Tags:

php

colors

I want an array where each field in the array contains a color code

array(0 => '#4CFF00', 1 => '#FFE97F')

And I want this to go through the whole spectrum of colors starting from green to black.

green-> blue -> dark blue -> purple -> yellow -> orange -> red -> brown ->black

This order doesn't need to be exactly the same, but I think you get the picture. Can anybody help with this? Is there a website that has done this before?

like image 454
Kennethvr Avatar asked Dec 14 '22 02:12

Kennethvr


1 Answers

You should use a colour model like Hue-Saturation-Value (HSV), and cycle the hue from 0 degrees all the way around the spectrum to 360 degrees, at which whatever saturation and value suited you. (If you want to go from green->green, just start at 120 degrees)

Here's an illustration which shows the difference between RGB and HSV based gradients: the top gradient is just going from green to red in an RGB model, but the lower one uses HSV, resulting in a more pleasing effect.

alt text

like image 193
Paul Dixon Avatar answered Dec 25 '22 09:12

Paul Dixon