function pub_html($d) { list($p, $o) = split_right('§', $d); $r = explode_k($o, ' ', '='); $ra = array('css' => 'class', 'font' => 'font-family', 'size' => 'font-size'); $rb = colors(); foreach ($r as $k => $v) { if ($k == 'color') { $v = $rb[$v] ? $rb[$v] : '#' . $v; } $atb .= ($ra[$k] ? $ra[$k] : $k) . ':' . $v . '; '; } return bts($atb, $p); }
function colors($hex) { return ['p' => ['#' . str_pad(dechex(hexdec($hex)), 3, '0', STR_PAD_LEFT), '#' . str_pad(dechex(hexdec($hex) - hexdec('#222')), 3, '0', STR_PAD_LEFT)], 'd' => ['#' . str_pad(dechex(hexdec($hex) - hexdec('#111')), 3, '0', STR_PAD_LEFT), '#' . str_pad(dechex(hexdec($hex) - hexdec('#333')), 3, '0', STR_PAD_LEFT)], 'l' => $hex === '#fff' ? colors('#35b')['p'] : ['#fff', '#fefefe']]; }
<?php require_once "../Utilities/functions.php"; error_reporting(E_ALL); ini_set('display_errors', 1); session_start(); header("Access-Control-Allow-Origin: *"); $cmd = getValue("cmd"); if ($cmd == "colors") { $response = colors(); header('Content-type: application/json'); echo json_encode($response); } else { echo "\n <html>\n <body>\n <h1>API</h1>\n <ul>\n <li>\n <h2>Generates a specified number of random colors</h2>\n\n <h3>Parameters:</h3>\n <ul>\n <li>cmd=colors</li>\n <li>num=num_of_colors</li>\n </ul>\n\n <h3>Returns:</h3>\n <p>An array of random colors</p>\n\n <h3>Example:</h3>\n <p><a href='randomColors.php?cmd=colors&num=5'>?cmd=colors&num=5</a></p>\n <pre>\n ['tan','green','purple','grey']\n </pre>\n </li>\n </ul>\n </body>\n </html>\n "; } function colors() { $response = []; $num = getValue("num"); $colors = ["red", "green", "blue", "pink", "yellow", "orange", "cyan", "purple", "black", "white", "grey", "brown", "tan"]; for ($i = 0; $i < $num; $i++) { $choice = rand(0, count($colors) - 1); $response[] = $colors[$choice]; } return $response; }
function rand_clr() { $r = colors(); $rb = array_keys_r($r, 0); sort($rb); $n = rand(0, count($rb)); return $rb[$n]; }