[Code][Challenge] Rainbow Text

phpBB3 and MOD challenges setup by the staff to test and challenge your phpBB3 coding skills.

[Code][Challenge] Rainbow Text

Postby Highway of Life » 29 Jun 2007, 02:22

[style].rainbow {font-family: Edwardian Script ITC, Lucida Calligraphy, Lucida Handwriting; font-size:200%;}[/style]Happy Happy Birthday, from all of us to you! ... We wish you Happy Birthday, so we can party too!!
Happy Birthday, Hank the Cowdog!!


Assuming you all are going to ask me how I did that...

Spoiler:
Code: Select all
<?php
function rainbow_text($string$bbcode false)
{
    
$colors = array('#00f5f8''#00ccf8''#00aef8''#0091f8''#006df8''#0054f8''#0132f8''#001af8''#0900f8''#3200f8''#4800f8''#6200f8''#7f06f8''#9300f8''#b100f8''#c800f8''#dc00f8''#ef00f8''#f800df''#f800c4''#f800a1''#f8008a''#f8007a''#f80060''#f80050''#f80044''#f8002c''#f8001a''#f80600''#f81a00''#f82f00''#f84400''#f85600''#f86a00''#f87d00''#f89701''#f8a800''#f8c400''#f8df00''#f8f400''#dcf800''#c0f800''#a8f800''#8bf800''#70f800''#56f800''#41f800''#26f800''#09f800''#00f812''#01f82e''#00f850''#00f86a''#00f881''#00f895''#00f8a4''#00f8b4''#00f8c6''#00f8db',);
    
    
$num_colors sizeof($colors);
    
$c 0;
    
    if (!
function_exists('str_split'))
    {
        function 
str_split($string$length 1)
        {
            return 
explode("\r\n"chunk_split($string$length));
        }
    }
    
    
$string_ary str_split($string);
    
    foreach (
$string_ary as $i => $string)
    {
        if (
$c >= $num_colors)
        {
            
$c 0;
        }
        
        if (
in_array($string, array(' '"\n""\r""\r\n")))
        {
            
$letter[$i] = $string;
        }
        else if (
$string != '')
        {
            
$letter[$i] = ($bbcode) ? '[color=' $colors[$c] . ']' $string '[/color]' '<span style="color:' $colors[$c] . ';">' $string '</span>';
            
$c++;
        }
    }
    
    
$text = (!$bbcode) ? '<span style="font-family: Edwardian Script ITC, Lucida Calligraphy, Lucida Handwriting; font-size:400%; font-weight:bold;">' '[b][size=200]';
    
// assuming fonts are by percentage. 
    
    
foreach ($letter as $string)
    {
        
$text .= $string;
    }
    
$text .= (!$bbcode) ? '</span>' '[/size][/b]';
    
    return 
$text;
}

echo 
rainbow_text('Happy Happy Birthday, from all of us to you! ... We wish you Happy Birthday, so we can party too!!
Happy Birthday, Hank the Cowdog!!'
);

?>


So what?s the challenge, you say?
Figure out how to dynamically generate the hex code for the colors. :D
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10


Re: [Code][Challenge] Rainbow Text

Postby eviL3 » 29 Jun 2007, 04:11

I was really about to ask you how you did that :rotfl:, nice challenge! :grin:
Image
User avatar
eviL3    
MOD Author
MOD Author
 
Posts: 1002
Joined: 05 Nov 2006, 08:14
Location: Cooking in the MODs kitchen
Gender: Male

Re: [Code][Challenge] Rainbow Text

Postby iWisdom » 10 Jul 2007, 20:18

Since I don't want to ruin it for myself, off to find some correlation between hex values :D
iWisdom    
phpBB Team Member
phpBB Team Member
 
Posts: 58
Joined: 10 Jul 2007, 20:01
Gender: Male
phpBB Knowledge: 10

Re: [Code][Challenge] Rainbow Text

Postby harmlessgoat22 » 23 Jul 2007, 12:21

YOU TOLD ME YOU DID IT BY HAND HIGHWAY!!!! NOW I'VE GOT NO REASON TO TRUST ANYTHING YOU SAY ANYMORE!!!

:cray: sorry...random outburst...it's alright Highway...artists use lies to tell the truth...too bad you're a programmer :( But you're still cool :grin:
User avatar
harmlessgoat22    
STG Support Team
STG Support Team
 
Posts: 2886
Joined: 13 Jul 2006, 17:38
Gender: Male
phpBB Knowledge: 8

Re: [Code][Challenge] Rainbow Text

Postby stitch626 » 24 Jul 2007, 19:57

:blush: I feel real stupid asking this but I just have to :blush: . What do you do with that code to make the rainbow text?
User avatar
stitch626    
STG Moderator Leader
STG Moderator Leader
 
Posts: 3185
Joined: 08 Feb 2007, 20:47
Location: Michigan
Favorite Team: Detroit Red Wings
Gender: Male
phpBB Knowledge: 7

Re: [Code][Challenge] Rainbow Text

Postby harmlessgoat22 » 24 Jul 2007, 20:31

stitch626 wrote::blush: I feel real stupid asking this but I just have to :blush: . What do you do with that code to make the rainbow text?

I believe you just run the file...save it as something and open it in FF or Safari, but not IE :grin:
User avatar
harmlessgoat22    
STG Support Team
STG Support Team
 
Posts: 2886
Joined: 13 Jul 2006, 17:38
Gender: Male
phpBB Knowledge: 8

Re: [Code][Challenge] Rainbow Text

Postby stitch626 » 24 Jul 2007, 20:43

Darn! It's always IE I am so sick of IE. Where can I get FF?
User avatar
stitch626    
STG Moderator Leader
STG Moderator Leader
 
Posts: 3185
Joined: 08 Feb 2007, 20:47
Location: Michigan
Favorite Team: Detroit Red Wings
Gender: Male
phpBB Knowledge: 7

Re: [Code][Challenge] Rainbow Text

Postby Highway of Life » 24 Jul 2007, 20:45

You can run it in Coda, SubEthaEdit, Eclipse, or Zend Studio.

Or, save it as a PHP file on your localhost, then run the file from any web browser.

EDIT:
Well, you can get http://ie7.com
http://www.mozilla.com/firefox/
http://getfirefox.com
or
http://firefox.com
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10

Re: [Code][Challenge] Rainbow Text

Postby stitch626 » 25 Jul 2007, 20:44

Ok, I can run it from my browser but how do I get it into a post on my board. Sorry for the dumb questions but I have never done or seen anything like this before.
User avatar
stitch626    
STG Moderator Leader
STG Moderator Leader
 
Posts: 3185
Joined: 08 Feb 2007, 20:47
Location: Michigan
Favorite Team: Detroit Red Wings
Gender: Male
phpBB Knowledge: 7

Re: [Code][Challenge] Rainbow Text

Postby stitch626 » 29 Jul 2007, 00:21

Ok, I can run it from my browser but how do I get it into a post on my board. Sorry for the dumb questions but I have never done or seen anything like this before.


can someone please explain this to me?
User avatar
stitch626    
STG Moderator Leader
STG Moderator Leader
 
Posts: 3185
Joined: 08 Feb 2007, 20:47
Location: Michigan
Favorite Team: Detroit Red Wings
Gender: Male
phpBB Knowledge: 7

Next

Return to phpBB3 Challenges at phpBB Academy

Who is online

Users browsing this forum: No registered users and 2 guests