Skip to content

Instantly share code, notes, and snippets.

@aristath
Created July 21, 2019 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aristath/e84c765da311be541ec41152d3efa471 to your computer and use it in GitHub Desktop.
Save aristath/e84c765da311be541ec41152d3efa471 to your computer and use it in GitHub Desktop.
<?php
/**
* Requires ariColor: https://aristath.github.io/ariColor/
*/
add_action( 'wp', function() {
if ( ! class_exists( 'ariColor' ) ) {
return;
}
$colors = [];
$hexes = [];
for ( $h = 0; $h <= 259; $h += 15 ) {
for ( $s = 0; $s <= 100; $s += 4 ) {
for ( $l = 0; $l <= 100; $l += 4 ) {
$hsl = "hsl($h,$s%,$l%)";
$color = ariColor::newColor( $hsl );
$lum = ( 0.2126 * $color->red ) + ( 0.7152 * $color->green ) + ( 0.0722 * $color->blue );
$color_props = [ $h, $s, $l, $lum ];
$hex = $color->toCSS( 'hex' );
if ( ! in_array( $hex, $hexes ) ) {
$hexes[] = $hex;
$colors[] = $color_props;
}
}
}
}
usort( $colors, function( $a, $b ) {
if ( $a[3] === $b[3] ) {
return 0;
}
return $a[3] > $b[3] ? -1 : 1;
});
foreach ( $colors as $i => $color ) {
$color[ 3 ] = round( $color[ 3 ] );
$colors[ $i ] = $color;
echo '<span style="width:20px;height:20px;margin:5px;border-radius:3px;background-color:hsl(' . $color[0] . ', ' . $color[1] . '%, ' . $color[2] . '%);display:inline-block;"></span>';
}
$json = json_encode( $colors );
error_log( $json );
var_dump( $colors );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment