tags:

views:

578

answers:

10

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?

A: 

http://www.visibone.com/colorlab/

Ed Guiness
A: 

http://colorschemedesigner.com/

santiiiii
+1  A: 

00FF00 is Green 000000 is Black. all you have to do it increment one color at a time while decrementing the other colors. Stick it in a loop, where it be php, javascript or whatever and go.

EDIT: Here is a link to code that shows how to loop through Hex color codes.

WolfmanDragon
A: 

You need some color schemes? I think it depends on the color scheme of the rest of your page. You can google "Color scheme generators" and you can find at least 10. Examples provided by @edg and @santiiiii above.

If you have a photo, there is a tool which can get colors from the photo to fit your site.

http://www.atalasoft.com/31apps/ColorSchemeGenerator/
Lukasz Lysik
A: 

I recommend writing a function to do this. If you need to go between multiple colors, just call it multiple times and concatenate the arrays.

Psuedocode: `colorRange(arrayReference, startColor, endColor, numSteps)`

Get {R, G, B} startColor and endColor
Get R_diff, G_diff, and B_diff

for i in 0 to numSteps {
   arrayReference.append(
          i => {min(startR, endR) + (R_diff * (i / numSteps)),
                min(startG, endG) + (G_diff * (i / numSteps)),
                min(startB, endB) + (B_diff * (i / numSteps))}
          )
}
Steven
A: 

Look at hexdec, dechex and this snippet:

for ($i = 0; $i < 255; $i++) {
    # here happens some colour-magic
}

Cheers,

Boldewyn
if `// here happens some *** magic` was the answer to everything, the world would be a better place -.-
knittl
Yep, because that would mean, that people wanting to accomplish some task would google "hex color code" and try and learn themselves instead of just asking as the first option.
Boldewyn
A: 
function dechexpad($i){
$s="";
if($i<16) $s="0";
$s.=dechex($i);
return $s;
}
function hexcolor($r,$g,$b){
return "#".dechexpad($r%255).dechexpad($g%255).dechexpad($b%255);
}

$xx=array();
for($i=0;$i<255;$i++){
$xx[]=hexcolor($i*4,$i*2,$i);
}
n00b32
A: 
function list_colours($start, $end, $steps = 5)
{
    $ret = array();

    $start_r = hexdec(substr($start, 1, 2));
    $start_g = hexdec(substr($start, 3, 2));
    $start_b = hexdec(substr($start, 5, 2));
    $end_r = hexdec(substr($end, 1, 2));
    $end_g = hexdec(substr($end, 3, 2));
    $end_b = hexdec(substr($end, 5, 2));

    $shift_r = ($end_r - $start_r) / $steps;
    $shift_g = ($end_r - $start_r) / $steps;
    $shift_b = ($end_r - $start_r) / $steps;

    for ($i = 0; $i < $steps; $i++)
    { $ret[] = "#".dechex($start_r + i * $shift_r).dechex($start_g + i * $shift_g).dechex($start_b + i * $shift_b); }

    return $ret;
}

$spectrum = array();
array_push($spectrum, "#00FF00", "#0000FF"); // green to blue
array_push($spectrum, "#0000FF", "#000066"); // blue to dark blue
// etc...

Disclaimer: not tested in the least.

Matthew Scharley
A: 

I guess if you need all of those colors you could build the 16776960 element array as follows:

<?php
    $end = 'FFFFFF';

    $arrMassiveColor = array();

    for($curr = 0; $curr <= dechex($end); $curr++) {
        $arrMassiveColor[] = '#'.hexdec($curr);
    }
?>

It seems a bit odd though...

Buggabill
+3  A: 
Paul Dixon