[Code][Challenge] Rainbow Text

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

Re: [Code][Challenge] Rainbow Text

Postby harmlessgoat22 » 29 Jul 2007, 12:01

You copy and paste the output into the posting page.
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 » 29 Jul 2007, 12:42

harmlessgoat22 wrote:You copy and paste the output into the posting page.


Ok, so I am not as dumb as I thought I was :blush: That is what I was trying to do but all my post was displaying is the code and NOT the actual message in rainbow text. Hmm I wonder :scratch:
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 Mighty Gorgon » 15 Sep 2007, 05:27

Nice shoot Highway of Life!

I did code something similar for me a while ago...

Here is the code to obtain a gradiented text, starting from a color, ending into another... even with random color capabilities.

Spoiler:
Code: Select all
function gradient($text, $color1, $color2, $mode = 'random', $iterations = 10)
{
   //
   // Returns text highlighted in random gradient colours
   //
   if ($mode == 'random')
   {
      $colors = load_random_colors();
   }
   else
   {
      $colors = load_gradient_colors($color1, $color2, $iterations);
   }
   $text = trim(stripslashes($text));
   $length = strlen($text);
   $result = '';
   $color_counter = 0;
   $TAG_OPEN = false;
   for ( $i = 0; $i < $length; $i++ )
   {
      $char = substr($text, $i, 1);
      if ( !$TAG_OPEN )
      {
         if ( $char == '<' )
         {
            $TAG_OPEN = true;
            $result .= $char;
         }
         elseif ( preg_match("#\S#i", $char) )
         {
            $color_counter++;
            $result .= '<span style="color: ' . $colors[$color_counter] . ';">' . $char . '</span>';
            $color_counter = ( $color_counter == $iterations ) ? 0 : $color_counter;
         }
         else
         {
            $result .= $char;
         }
      }
      else
      {
         if ( $char == '>' )
         {
            $TAG_OPEN = false;
         }
         $result .= $char;
      }
   }
   return $result;
}

function rand_color()
{
   $color_code = mt_rand(0, 255);
   if ($color_code < 16)
   {
      return ('0' . dechex($color_code));
   }
   else
   {
      return dechex($color_code);
   }
}

function load_random_colors($iterations = 10)
{
   $random_color = array();
   for ( $i = 0; $i < $iterations; $i++ )
   {
      $random_color[$i + 1] = '#' . rand_color() . rand_color() . rand_color();
   }
   return $random_color;
}

function load_gradient_colors($color1, $color2, $iterations = 10)
{
   $col1_array = array();
   $col2_array = array();
   $col_dif_array = array();
   $gradient_color = array();
   $col1_array[0] = hexdec(substr($color1, 1, 2));
   $col1_array[1] = hexdec(substr($color1, 3, 2));
   $col1_array[2] = hexdec(substr($color1, 5, 2));
   $col2_array[0] = hexdec(substr($color2, 1, 2));
   $col2_array[1] = hexdec(substr($color2, 3, 2));
   $col2_array[2] = hexdec(substr($color2, 5, 2));
   $col_dif_array[0] = ($col2_array[0] - $col1_array[0]) / ($iterations - 1);
   $col_dif_array[1] = ($col2_array[1] - $col1_array[1]) / ($iterations - 1);
   $col_dif_array[2] = ($col2_array[2] - $col1_array[2]) / ($iterations - 1);
   for ( $i = 0; $i < $iterations; $i++ )
   {
      $part1 = round($col1_array[0] + ($col_dif_array[0] * $i));
      $part2 = round($col1_array[1] + ($col_dif_array[1] * $i));
      $part3 = round($col1_array[2] + ($col_dif_array[2] * $i));
      $part1 = ($part1 < 16) ? ('0' . dechex($part1)) : (dechex($part1));
      $part2 = ($part2 < 16) ? ('0' . dechex($part2)) : (dechex($part2));
      $part3 = ($part3 < 16) ? ('0' . dechex($part3)) : (dechex($part3));
      $gradient_color[$i + 1] = '#' . $part1 . $part2 . $part3;
   }

   return $gradient_color;
}


Example here:
http://www.icyphoenix.com/viewtopic.php?f=4&t=1604

Search for gradient in the page.
Code: Select all
[gradient cols=#FF8866 cole=#336699 iterations=8]Text[/gradient]
Luca
User avatar
Mighty Gorgon    
Style Author
Style Author
 
Posts: 20
Joined: 04 Jul 2007, 16:50
Location: Italy
Favorite Team: Juventus
Gender: Male

Re: [Code][Challenge] Rainbow Text

Postby stitch626 » 21 Sep 2007, 19:17

I still don't know how this is done :(
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 Sniper_E » 21 Sep 2007, 20:38

I've seen how he does it.... :P but I want tell. :beee:
No is NEVER an Option and NEVER is the only Option when it comes to Giving Up!
User avatar
Sniper_E    
STG Jedi Master
STG Jedi Master
 
Posts: 7006
Joined: 31 May 2006, 06:29
Location: Shreveport, LA
Favorite Team: The STG Team
Gender: Male
phpBB Knowledge: 6

Re: [Code][Challenge] Rainbow Text

Postby Highway of Life » 21 Sep 2007, 21:16

Sniper_E wrote:I've seen how he does it.... :P but I want tell. :beee:
Now the test will be to see if you can reproduce. :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 stitch626 » 10 Oct 2007, 19:01

I found This Gradient text generator but I am wondering...Is there a way to make a custom bbcode for this?
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 Sniper_E » 10 Oct 2007, 19:16

Highway of Life wrote:
Sniper_E wrote:I've seen how he does it.... :P but I want tell. :beee:
Now the test will be to see if you can reproduce. :D
Are we talking about copy and paste? That would be the only way I could reproduce anything. :rotfl:
[style].rainbow {font-family: Edwardian Script ITC, Lucida Calligraphy, Lucida Handwriting; font-size:200%;}[/style]
No is NEVER an Option and NEVER is the only Option when it comes to Giving Up!
User avatar
Sniper_E    
STG Jedi Master
STG Jedi Master
 
Posts: 7006
Joined: 31 May 2006, 06:29
Location: Shreveport, LA
Favorite Team: The STG Team
Gender: Male
phpBB Knowledge: 6

Re: [Code][Challenge] Rainbow Text

Postby stitch626 » 10 Oct 2007, 21:24

Haaa, In your face! I think I got it but would lis to covert it to a custom bbcode.
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 » 10 Oct 2007, 21:36

Innerface, huh? well! very nice! very nice indeed. But can you beat this!!?
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

PreviousNext

Return to phpBB3 Challenges at phpBB Academy

Who is online

Users browsing this forum: No registered users and 1 guest

cron