Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. <?php
  2.  
  3.     function hextorgb ($hex) {
  4.         $hex = str_replace("#", "", $hex);
  5.  
  6.         $return['r'] = hexdec(substr($hex, 0, 2));
  7.         $return['g'] = hexdec(substr($hex, 2, 2));
  8.         $return['b'] = hexdec(substr($hex, 4, 2));
  9.  
  10.         return $return;
  11.     }
  12.  
  13.     function rgbtohex ($r, $g, $b) {
  14.         return "#" . dechex($r) . dechex($g) . dechex($b);
  15.     }
  16.  
  17.  
  18.     $hex['from'] = '000000';
  19.     $hex['to'] = 'FFFFFF';
  20.  
  21.  
  22.     $ursprung = hextorgb($hex['from']);
  23.     $ziel = hextorgb($hex['to']);
  24.  
  25.     $width = 5;
  26.     $height = 5;
  27.  
  28.  
  29.  
  30.  
  31.  
  32.     $sum = ($width * $height);
  33.  
  34.     $calc['r'] = (($ziel['r'] - $ursprung['r']) / $sum);
  35.     $calc['g'] = (($ziel['g'] - $ursprung['g']) / $sum);
  36.     $calc['b'] = (($ziel['b'] - $ursprung['b']) / $sum);
  37.  
  38.  
  39.     for ($i = 0; $i < $width; $i++) {
  40.         for ($x = 0; $x < $height; $x++) {
  41.             echo '<inline style="width:50px; height:50px; background:rgb(' . round(((($i * $width) + $x) * $calc['r']) + $ursprung['r']) . ',' . round(((($i * $width) + $x) * $calc['g']) + $ursprung['g']) . ',' . round(((($i * $width) + $x) * $calc['b']) + $ursprung['b']) . ')">' . $i . ' . ' . $x .  '</inline>';
  42.         }
  43.         echo '<br />';
  44.     }
  45.  
  46.  
  47.  
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement