programming:web_safe_colors

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
programming:web_safe_colors [2014/07/09 11:47] – creata Giuseppe Di Terlizziprogramming:web_safe_colors [2015/01/20 14:02] (current) Giuseppe Di Terlizzi
Line 1: Line 1:
 ====== Web Safe Colors ====== ====== Web Safe Colors ======
 +
 +{{https://raw.githubusercontent.com/yusukekamiyamane/fugue-icons/master/bonus/icons-32/color-swatch.png?nolink }} Questa pagina elenca i 216 colori "sicuri" che possono essere visualizzati senza problemi su macchine hanno schede video a 8-bit (max 256 colori).
 +
 +Per ricavare velocemente l'elenco dei 216 colori è possibile usare il seguente script PHP che può facilmente essere adattato per un'altro linguaggio, come ad esempio JavaScript.
 +
 +<code php>
 +$hex = array('00', '33', '66', '99', 'CC', 'FF');
 +$colors = array();
 +
 +foreach ($hex as $col1) {
 +  foreach ($hex as $col2) {
 +    foreach ($hex as $col3) {
 +      $colors[] = "$col1$col2$col3";
 +    }
 +  }
 +}
 +</code>
 +
 +===== Tabella dei colori =====
  
 <php> <php>
Line 8: Line 27:
   foreach ($hex as $c2) {   foreach ($hex as $c2) {
     foreach ($hex as $c3) {     foreach ($hex as $c3) {
-      $colors[] = "$c1$c2$c3";+      $colors[] = array('hex' => "$c1$c2$c3", 'dec' => hexdec($c1).' '.hexdec($c2).' '.hexdec($c3));
     }     }
   }   }
 } }
  
-echo '<div class="wrap_column plugin_wrap" style="width:30%"><table><thead><tr><th>HEX</th><th>Color</th></tr></thead><tbody>';+$i=0; 
 +$x=0; 
 + 
 +echo '<table style="width:100%; font-family:monospace; text-align:center"><tr><td>&nbsp;</td><td>'. implode('</td><td>', $hex) .'</td></tr><tr>';
  
 foreach ($colors as $color) { foreach ($colors as $color) {
-  $x++; 
-  if ($x <= 72) { 
-    echo "<tr><td>#$color</td><td style='background:#$color'>&nbsp;</td></tr>"; 
-  } 
-} 
  
-echo '</tbody></table></div>';+  $c_hex   = $color['hex']; 
 +  $c_dec   = $color['dec']; 
 +  $b_color = ((int)(hexdec(substr($color['hex'], 0,2)) 102) ? 'white' : 'black'); 
 +  $test    = hexdec(substr($color['hex'], 0,2)); 
 +  $x_hex   = substr($color['hex'], 0,2); 
 +  $y_hex   = substr($color['hex'], 4,2);
  
-echo '<div class="wrap_column plugin_wrap" style="width:30%"><table><thead><tr><th>HEX</th><th>Color</th></tr></thead><tbody>';+  if ($i>1 && ($i%6) == 0) { 
 +    if ($x==6) { $x=0; } 
 +    echo '<td>'.$hex[$x].'</td>'; 
 +    $x++; 
 +  }
  
-foreach ($colors as $color) { +  if (($i%6) == 0) { 
-  $y+++    echo '</tr><tr>'
-  if ($y > 72 && $y <144) { +    if ($x_tmp !== $x_hex) { 
-    echo "<tr><td>#$color</td><td style='background:#$color'>&nbsp;</td></tr>";+      echo '<td style="vertical-align:middle" rowspan="6">'.$x_hex.'</td>'; 
 +    }
   }   }
-} 
  
-echo '</tbody></table></div>';+  echo "<td style=\"width:16%; color:$b_color; background:#$c_hex;\">#$c_hex<br/>$c_dec</td>";
  
-echo '<div class="wrap_column plugin_wrap" style="width:30%"><table><thead><tr><th>HEX</th><th>Color</th></tr></thead><tbody>';+  $i++; 
 +  $x_tmp $x_hex;
  
-foreach ($colors as $color) { 
-  $z++; 
-  if ($z >144) { 
-    echo "<tr><td>#$color</td><td style='background:#$color'>&nbsp;</td></tr>"; 
-  } 
 } }
- +echo '<td>FF</td></tr></table>';
-echo '</tbody></table></div>'; +
- +
-echo '<div class="wrap_clear plugin_wrap"></div>';+
 </php> </php>
  
-{{tag>programming web colors css}}+{{tag>programming web colors php css}}
 ~~NOCACHE~~ ~~NOCACHE~~
  • programming/web_safe_colors.1404899240.txt.gz
  • Last modified: 10 years ago
  • by Giuseppe Di Terlizzi