Skip to content

Instantly share code, notes, and snippets.

@xBeastMode
Created August 20, 2018 03:13
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 xBeastMode/2922b427978a0c951bcc5dfee528ca2f to your computer and use it in GitHub Desktop.
Save xBeastMode/2922b427978a0c951bcc5dfee528ca2f to your computer and use it in GitHub Desktop.
Functions that can generate a sequence of ROYGBIV text for HTML or Minecraft using it's formatting codes.
<?php
/**
*
* @param string $text
* @param int $amount
*
* @return array
*
*/
function generate_ROYGBIV_HTML(string $text, int $amount = -1): array{
$return = [];
$colors = ["#FF0000", "#FF7400", "#FFD400", "#00FF00", "#00FFEC", "#0000FF", "#D800FF"];
$amount = ($amount < 1) ? strlen($text) : $amount;
$split = str_split($text);
for($i = 0; $i < $amount; ++$i){
$out = "";
$loop = 0;
foreach($split as $part){
$out .= "<p style='color: " . $colors[$loop++] . "'>" . $part . "<p/>";
if($loop > (count($colors) - 1)){
$loop = 0;
}
}
$color = array_shift($colors);
$colors[] = $color;
$return[] = $out;
}
return $return;
}
/**
*
* @param string $text
* @param int $amount
*
* @return array
*
*/
function generate_ROYGBIV_MC(string $text, int $amount = -1): array{
$return = [];
$colors = ["&c", "&6", "&e", "&a", "&b", "&9", "&5"];
$amount = ($amount < 1) ? strlen($text) : $amount;
$split = str_split($text);
for($i = 0; $i < $amount; ++$i){
$out = "";
$loop = 0;
foreach($split as $part){
$out .= $colors[$loop++] . $part;
if($loop > (count($colors) - 1)){
$loop = 0;
}
}
$color = array_shift($colors);
$colors[] = $color;
$return[] = $out;
}
return $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment