Jump to content


Photo

Rainbow Plugin (09-12-2007)


  • Please log in to reply
14 replies to this topic

#1 spongey437

spongey437
  • Members
  • 62 posts
  • Reputation:0

Posted 12 September 2007 - 04:17 PM

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:

Posted Image

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

Posted ImagePosted Image

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.go...om/rainbow3.dll
  • 0

#2 BoltBait

BoltBait

    2013 Movie Guru Award Winner

  • Administrators
  • 9,239 posts
  • LocationCalifornia, USA
  • Reputation:171

Posted 12 September 2007 - 04:29 PM

This effect can already be done with this plugin:

http://boltbait.goog...om/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
  • 0
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#3 spongey437

spongey437
  • Members
  • 62 posts
  • Reputation:0

Posted 12 September 2007 - 05:52 PM

This effect can already be done with this plugin:

http://boltbait.goog...om/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.
  • 0

#4 barkbark00

barkbark00
  • Members
  • 3,336 posts
  • Reputation:2

Posted 12 September 2007 - 06:04 PM

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
Posted Image
Take responsibility for your own intelligence. ;) -Rick Brewster

#5 Fisherman's Friend

Fisherman's Friend
  • Members
  • 490 posts
  • LocationCoruscant
  • Reputation:1

Posted 12 September 2007 - 06:29 PM

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

#6 BuzzKill

BuzzKill
  • Members
  • 1,020 posts
  • LocationCorpus Christi
  • Reputation:3

Posted 12 September 2007 - 06:47 PM

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
Posted Image
- DO NOT contact me asking for the .pdn of my avatar or the PDN logo. Thank you. Have a nice day.

#7 barkbark00

barkbark00
  • Members
  • 3,336 posts
  • Reputation:2

Posted 12 September 2007 - 06:53 PM

I third it!

...Wait, can I even do that? :lol:
  • 0
Posted Image
Take responsibility for your own intelligence. ;) -Rick Brewster

#8 usedHONDA

usedHONDA
  • Members
  • 5,738 posts
  • LocationOrlando, FL
  • Reputation:4

Posted 12 September 2007 - 07:48 PM

I fourth it (if BB00 is allowed to third)!
  • 0

"The greatest thing about the Internet is that you can write anything you want and give it a false source." ~Ezra Pound

Posted Image

twtr | dA | tmblr | yt | fb


#9 Mr Frojo

Mr Frojo
  • Members
  • 2,118 posts
  • LocationColorado
  • Reputation:2

Posted 12 September 2007 - 09:02 PM

I agree, but who'll code it?
  • 0

I'm still alive!


#10 MiguelPereira

MiguelPereira
  • Members
  • 821 posts
  • LocationPortugal
  • Reputation:1

Posted 12 September 2007 - 10:58 PM

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

#11 PythonPower

PythonPower
  • Newbies
  • 9 posts
  • Reputation:0

Posted 17 September 2007 - 04:48 PM

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

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

#12 Bob

Bob
  • Members
  • 3,033 posts
  • LocationLyon, France
  • Reputation:3

Posted 17 September 2007 - 07:35 PM

This effect can already be done with [my] plugin

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

#13 MiguelPereira

MiguelPereira
  • Members
  • 821 posts
  • LocationPortugal
  • Reputation:1

Posted 18 September 2007 - 10:55 PM

You can make those arc rainbows with Gradient? How?


Use RectToPolar plugin
  • 0

#14 BoltBait

BoltBait

    2013 Movie Guru Award Winner

  • Administrators
  • 9,239 posts
  • LocationCalifornia, USA
  • Reputation:171

Posted 18 September 2007 - 11:10 PM

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
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#15 Blooper

Blooper
  • Members
  • 2,102 posts
  • Reputation:0

Posted 08 October 2007 - 07:30 PM

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