Created
August 20, 2018 03:13
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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