Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There might be libs to do that. However let's get a short warm up into the general principles. In general you have following options:</p> <ol> <li>A predefined color index, e.g. <code>$coloridx=array(0=&gt;'#FFFFFF',1=&gt;'#FFEE00',...);</code></li> <li>Any algorithm, e.g. linear gradient, which is basically an iterations based adaption of all three RGB channels (R = red, G = green, B = blue).</li> <li>A combination of both, which usually puts the result of any complex algorithm to the color index and then goes from there.</li> </ol> <p>If you include algorithms in your considerations you must understand that there is no <code>true</code> or <code>false</code>. It all depends on what you would like to implement. There might be occasions where it makes sense to render variations of green into <code>n=0..10</code> and then have red to black in everything beyond <code>n&gt;10</code>. Caps and multipliers help to set accents. Things like that.</p> <p>One way of implementing a linear gradient would be:</p> <pre><code>function lineargradient($ra,$ga,$ba,$rz,$gz,$bz,$iterationnr) { $colorindex = array(); for($iterationc=1; $iterationc&lt;=$iterationnr; $iterationc++) { $iterationdiff = $iterationnr-$iterationc; $colorindex[] = '#'. dechex(intval((($ra*$iterationc)+($rz*$iterationdiff))/$iterationnr)). dechex(intval((($ga*$iterationc)+($gz*$iterationdiff))/$iterationnr)). dechex(intval((($ba*$iterationc)+($bz*$iterationdiff))/$iterationnr)); } return $colorindex; } $colorindex = lineargradient( 100, 0, 0, // rgb of the start color 0, 255, 255, // rgb of the end color 256 // number of colors in your linear gradient ); $color = $colorindex[$value]; </code></pre> <p>I UPDATED the code to add dechex, which feeds back on the comments.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload