[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 Highway of Life » 24 Jun 2008, 09:33

Owen wrote:Great little script, why cant bbcodes parse php out of the box

Can you imagine what kind of exploits I could make if I could parse PHP, HTML, JavaScript, or even CSS? ... HTML is not even half as bad as PHP, I could do all kinds of nasty things with PHP to not only exploit users, but the server as well.
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




phpBB Academy at StarTrekGuide
Support STG
Using PayPal Donate

Re: [Code][Challenge] Rainbow Text

Postby Dark R0gue » 11 Aug 2008, 06:12

but thats u. lol. also very nice rainbow text. i love it
Dark R0gue    
Crewman
Crewman
 
Posts: 2
Joined: 11 Aug 2008, 05:15
Gender: Male
phpBB Knowledge: 2

Re: [Code][Challenge] Rainbow Text

Postby beggers » 11 Aug 2008, 19:42

Mighty Gorgon wrote: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]


Where do you put the function? We seem to be having a little trouble getting a working BBcode here. Thanks. :scratch:
User avatar
beggers    
Supporter
Supporter
 
Posts: 166
Joined: 25 Jan 2008, 23:46
Favorite Team: Oakland Raiders
Gender: Male
phpBB Knowledge: 4

Re: [Code][Challenge] Rainbow Text

Postby RMcGirr83 » 30 Aug 2008, 11:22

Highway of Life wrote:It has a problem though, I need to find another way to split by characters. str_split(); does not support UTF-8. :think:


Code: Select all
function rainbow($s) {
   $colors = array(
      "0" => "FF0000",
      "1" => "ff9900",
      "2" => "FFFF00",
      "3" => "66FF00",
      "4" => "66FFFF",
      "5" => "0000FF",
   );

   $c = 0;
   for ($i = 0; $i <= strlen($s); $i++) {
      if ($c > 5) {
         $c = 0;
      }

      if ($s[$i] != " ") {
         $str .= '<span style="color:#' . $colors[$c] . '">' . $s[$i] . '</span>';
         $c++;
      } else {
         $str .= " ";   
      }
   }

   return $str;
}


?

:)

I've had it for a while on my live 3 year old forum ;)
Image
RMcGirr83    
Supporter
Supporter
 
Posts: 97
Joined: 23 Feb 2008, 07:03
Location: East Lyme, CT
Favorite Team: NY FOOTBALL Giants
Gender: Male
phpBB Knowledge: 10

Re: [Code][Challenge] Rainbow Text

Postby Tuvok » 22 Apr 2009, 04:43

Fancy Script Highway, But can you beat this?
User avatar
Tuvok
Supporter
Supporter
 
Posts: 66
Joined: 19 Feb 2009, 22:25
Location: Unimatrix Zero
Favorite Team: The Borg.
Gender: Male
phpBB Knowledge: 10

Re: [Code][Challenge] Rainbow Text

Postby stitch626 » 20 May 2009, 08:22

Here is a bbcode I found at phpbb3bbcodes.com and cirtapk
The effects are the same

Code: Select all
<script type="text/javascript">
    function MakeArray(n){
      this.length=n;
      for(var i=1; i<=n; i++) this[i]=i-1;
      return this
    }

    hex=new MakeArray(16);
    hex[11]="A"; hex[12]="B"; hex[13]="C"; hex[14]="D";
    hex[15]="E"; hex[16]="F";

    function ToHex(x){
      var high=x/16;
      var s=high+"";
      s=s.substring(0,2);
      high=parseInt(s,10);
      var left=hex[high+1];
      var low=x-high*16;
      s=low+"";
      s=s.substring(0,2);
      low=parseInt(s,10);
      var right=hex[low+1];
      var string=left+""+right;
      return string;
    }

    function fadeout(text){
      text=text.substring(3,text.length-4);
      color_d1=255;
      mul=color_d1/text.length;
      var j=1;
    for(i=0;i<text.length;i++){
       color_d1=255*Math.sin(i/(text.length/3));
       color_h1=ToHex(color_d1);
       color_d2=mul*i;
       color_h2=ToHex(color_d2);
       color_d3=mul*(text.length-i);
       color_h3=ToHex(color_d3);

          j = i;

      if (text.substring(i,i+1) == '&')
      {
            for (j = i+1; j < text.length; j++)
            {
                   if (text.substring(j,j+1) == ';') { break; }
            }
            if (j == text.length) { j = i; }
      }

      if (text.substring(i,i+1) == '<')
      {
            for (j = i+1; j < text.length; j++)
            {
                   if (text.substring(j,j+1) == '>') { break; }
            }
            if (j == text.length) { j = i; }
      }

       document.write("<FONT COLOR='#"+color_h3+color_h1+color_h2+"'>"+
                      text.substring(i,j+1)+'</FONT>');
             i = j;
    }
    }
    </script>

    <script language="JavaScript"><!--
          {fadeout("-->{TEXT}<!__");}
        //--></script>

Code: Select all
[rainbow]{TEXT}[/rainbow]
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

Previous

Return to phpBB3 Challenges at phpBB Academy

Who is online

Users browsing this forum: Magpie Crawler and 3 guests