Sign in to follow this  
Followers 0
spongey437

Rainbow Plugin (09-12-2007)

15 posts in this topic

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

0

Share this post


Link to post
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!

0

Share this post


Link to post
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.

0

Share this post


Link to post
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.

0

Share this post


Link to post
Share on other sites

well this one wont render in a image with high res. I'm working on a pic with 2048x1536 it wont render the rainbow

0

Share this post


Link to post
Share on other sites

YAAAAAAAAY!! Now I can make rainbows! *huggles creator*

*glances around at other comments* You can make those arc rainbows with Gradient? How?

0

Share this post


Link to post
Share on other sites
This effect can already be done with [my] plugin

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

0

Share this post


Link to post
Share on other sites
You can make those arc rainbows with Gradient? How?

Use RectToPolar plugin

...and if that doesn't work :roll:

try Effects > Distort > Polar Inversion

:D

0

Share this post


Link to post
Share on other sites

Or tube oblique. I like BB's plug-in better, but it's no reason to not publish your work indeed.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0