Jump to content
How to Install Plugins ×

Rainbow Plugin (09-12-2007)


spongey437

Recommended Posts

Still playing around with the Codelab and thought I would try to create a rainbow effect. Here is what I came up with. Run on just a blank page it will create something like this:

rainbow.jpg

But my use for it was to do something like this.

pumpkin_field.jpgpumpkin_field2.jpg

Right now it just creates the rainbow as you see it here with the colors stretching vertically down the page. It works for selections as well, but only rectangular ones. It still creates something with weird shaped selections, but it is all screwed up and I cant seem to wrap my hands around how to program around it. Also, if I had more programming experience I would have liked to have set this up like a gradient tool, but at least for now it just does the rainbow.

I have set up three selection bars for Red, Green and Blue starting colors. You can create different rainbow effects by playing with the starting colors, but the default settings will give you your standard rainbow (though for some reason the size of the image can affect how far down the color scale it gets. For example on an 800x600 image it seems to stop at light blue, but for a smaller images reaches purple and even sometimes makes it back to red - which was the intent when programming it).

Here is the code in case anyone is interested.

int Amount1=255;	//[0,255]Red Start
int Amount2=0;	//[0,255]Green Start
int Amount3=0;	//[0,255]Blue Start

void Render(Surface dst, Surface src, Rectangle rect)
{
   PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);

   // Delete any of these lines you don't need
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();

   long CenterX = (long)(((selection.Right - selection.Left) / 2)+selection.Left);
   long CenterY = (long)(((selection.Bottom - selection.Top) / 2)+selection.Top);
   ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
   ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
   int BrushWidth = (int)EnvironmentParameters.BrushWidth;

   int l = 1;
   int p = 1530 / rect.Right;
   int r = Amount1;
   int g = Amount2;
   int b = Amount3;

   ColorBgra CurrentPixel;
   for(int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
           if (selectionRegion.IsVisible(x, y))
           {
               CurrentPixel = src[x,y];
               // TODO: Add pixel processing code here
               if (x == rect.Left)
               {
                   r = Amount1;
                   g = Amount2;
                   b = Amount3;
               }

               switch(l)
               {
               case 1:

                   g = g + p;
                   if (g > 255)
                   	{
                       g = 255;
                       l = 2;
                       }
                   break;                

               case 2:

                   r = r - p;
                   if (r < 0)
                   	{
                       r = 0;
                       l = 3;
                       }
                   break;                

               case 3:

                   b = b + p;
                   if (b > 255)
                   	{
                       b = 255;
                       l = 4;
                       }
                   break;

               case 4:

                   g = g - p;
                   if (g < 0)
                   	{
                       g = 0;
                       l = 5;
                       }
                   break;                

               case 5:

                   r = r + p;
                   if (r > 255)
                   	{
                       r = 255;
                       l = 6;
                       }
                   break;                

               case 6:

                   b = b - p;
                   if (b < 0)
                   	{
                       b = 0;
                       l = 1;
                       }
                   break;
               }



               // Access RGBA values this way, for example:
                  CurrentPixel.R = (byte)r;
                  CurrentPixel.G = (byte)g;
                  CurrentPixel.B = (byte)b;
               // CurrentPixel.A = (byte)PrimaryColor.A;
               dst[x,y] = CurrentPixel;
           }
       }
   }
}

Thanks to Miguel for showing me the 'switch' routine to use (which apparently runs faster than a bunch of if statements). I incorporated it into this and remembered to add an icon this time.

Let me know what you think. here is the link to the plugin http://Spongey437.googlepages.com/rainbow3.dll

Link to comment
Share on other sites

This effect can already be done with this plugin:

http://boltbait.googlepages.com/Gradient.dll

Choose the ending colors for primary and secondary, then run the effect and choose the Long HSV method.

Description of this effect can be found here: viewtopic.php?t=2294

Link to comment
Share on other sites

This effect can already be done with this plugin:

http://boltbait.googlepages.com/Gradient.dll

Choose the ending colors for primary and secondary, then run the effect and choose the Long HSV method.

Description of this effect can be found here: viewtopic.php?t=2294

My bad. I didnt have that one and I really had thought I had downloaded all the plugins.

Link to comment
Share on other sites

What we really need is a gradient plugin where we can load a PdN palette file (or xml like Curves+ and Shape 3D) which would specify the colors and the order that we want the colors blended...like a custom rainbow with all of the options from BB's gradient plugin! :D

Edit:

^^that's a long sentence!

 

Take responsibility for your own intelligence. 😉 -Rick Brewster

Link to comment
Share on other sites

My bad. I didnt have that one and I really had thought I had downloaded all the plugins.

Well, your plugin can be moved to "color" (via source). So it's useful for me as it doesn't blow up my effects menu. Thank you. :)

Also I don't see that another plugin which can do the same is a reason to stop sharing your work. Some people like this one, some that one. I prefer yours.

Link to comment
Share on other sites

What we really need is a gradient plugin where we can load a PdN palette file (or xml like Curves+ and Shape 3D) which would specify the colors and the order that we want the colors blended...like a custom rainbow with all of the options from BB's gradient plugin! :D

I second that.

BK_BloodSaw_sig.png

- DO NOT contact me asking for the .pdn of my avatar or the PDN logo. Thank you. Have a nice day.

Link to comment
Share on other sites

This effect can already be done with [my] plugin

Does Spongey's code looks good, dear C# Master?

No. Way. I've just seen Bob. And... *poof!*—just like that—he disappears into the mist again. ~Helio

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...