Sign in to follow this  
spongey437

Simple Lines Plugin

Recommended Posts

I was looking for a way to make vertical or horizontal lines across a whole image (or a selected region) and who knows, maybe this is already out there somewhere but I also wanted to play around with the Codelab so i thought I would write it up myself.

So here is what it will create -

lines.jpg

Pretty simple, and even with my limited knowledge of programming I was able to use codelab to come up with it. The effect has two slider bars. The first sets the width between the lines (defaults to 10, and I maxed it out at 100, minimum is one but that actually just paints the whole page one color). It uses whatever your primary color selected is as the color of the lines. The second slider is just to determine whether you want Vertical or Horizontal lines (1 for vertical, 2 for horizontal).

Here is the source code in case anyone was interested - like I said it is a pretty simple code but it might help some new people see how codelab works. Thanks to Boltbait for his tutorials on writing codelab plugins as well, they were very helpful. Looking at the code below, all it does is check to see if you want it horizontal or vertical. Then it goes through every pixel and calculates whether that pixel is a factor of the width that you have set. If it is, it writes to that pixel, if not it does nothing.

int Amount1=10; //[1,100]Width
int Amount2=2; //[1,2]X - Y


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;

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(Amount2 == 1)
{
if (x % Amount1 == 0)
{
// Access RGBA values this way, for example:
CurrentPixel.R = (byte)PrimaryColor.R;
CurrentPixel.G = (byte)PrimaryColor.G;
CurrentPixel.B = (byte)PrimaryColor.B;
CurrentPixel.A = (byte)PrimaryColor.A;
}
}

if(Amount2 == 2)
{
if (y % Amount1 == 0)
{
// Access RGBA values this way, for example:
CurrentPixel.R = (byte)PrimaryColor.R;
CurrentPixel.G = (byte)PrimaryColor.G;
CurrentPixel.B = (byte)PrimaryColor.B;
CurrentPixel.A = (byte)PrimaryColor.A;
}
}

dst[x,y] = CurrentPixel;
}
}
}
}


Well, that's it - my first plugin.

Here is the link to the dll - http://Spongey437.googlepages.com/lines.dll


Also, this effect will appear in the Render submenu in PdN. I dont know about you guys but I wish all the effects were subgrouped in some way as there are a ton of them now and they go off the page.

Lines.zip

Edited by Ego Eram Reputo
Added ZIP file.

Share this post


Link to post
Share on other sites

this can come in handy

Just one thing

I think that even if it's a quick rendering plugin It should use the Switch function like this

               switch(Amount3)                
               {              
                   case 1:

                   if (x % Amount2 == 0)
                   {
		               CurrentPixel.R = (byte)PrimaryColor.R;
                       CurrentPixel.G = (byte)PrimaryColor.G;
                       CurrentPixel.B = (byte)PrimaryColor.B;
                       CurrentPixel.A = (byte)PrimaryColor.A;
                    }
                   break;

                   case 2:

                   if (y % Amount2 == 0)
                   {
                       CurrentPixel.R = (byte)PrimaryColor.R;
                       CurrentPixel.G = (byte)PrimaryColor.G;
                       CurrentPixel.B = (byte)PrimaryColor.B;
                       CurrentPixel.A = (byte)PrimaryColor.A;
                    }
                   break;
               }

It might be better for high-res images (really high-res)

anyway i was trying to put a line width function. nice work

Lines.zip

Share this post


Link to post
Share on other sites

Ok I see, thats cool, it can be handy.

There is an interlace plugin, I think it does the same as this.

It doesn't let the space between to be chosen, this one does.

This one doesn't have the line width option.

Share this post


Link to post
Share on other sites
this can come in handy

Just one thing

I think that even if it's a quick rendering plugin It should use the Switch function like this

               switch(Amount3)                
               {              
                   case 1:

                   if (x % Amount2 == 0)
                   {
		               CurrentPixel.R = (byte)PrimaryColor.R;
                       CurrentPixel.G = (byte)PrimaryColor.G;
                       CurrentPixel.B = (byte)PrimaryColor.B;
                       CurrentPixel.A = (byte)PrimaryColor.A;
                    }
                   break;

                   case 2:

                   if (y % Amount2 == 0)
                   {
                       CurrentPixel.R = (byte)PrimaryColor.R;
                       CurrentPixel.G = (byte)PrimaryColor.G;
                       CurrentPixel.B = (byte)PrimaryColor.B;
                       CurrentPixel.A = (byte)PrimaryColor.A;
                    }
                   break;
               }

It might be better for high-res images (really high-res)

anyway i was trying to put a line width function. nice work

You can get some interesting results with this is if you combine the two scripts together....

    int Amount1=10;   //[1,100]Width
   int Amount2=2;   //[1,2]X - Y
   int Amount3=2;  //[1,2]Switch


   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;

       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(Amount2 == 1)
                   {
                      if (x % Amount1 == 0)
                      {
                      // Access RGBA values this way, for example:
                           CurrentPixel.R = (byte)PrimaryColor.R;
                           CurrentPixel.G = (byte)PrimaryColor.G;
                           CurrentPixel.B = (byte)PrimaryColor.B;
                           CurrentPixel.A = (byte)PrimaryColor.A;
                      }
                   }

                   if(Amount2 == 2)
                   {
                      if (y % Amount1 == 0)
                      {
                      // Access RGBA values this way, for example:
                           CurrentPixel.R = (byte)PrimaryColor.R;
                           CurrentPixel.G = (byte)PrimaryColor.G;
                           CurrentPixel.B = (byte)PrimaryColor.B;
                           CurrentPixel.A = (byte)PrimaryColor.A;
                      }
                   }
                   switch(Amount3)               
                   {             
                       case 1:

                       if (x % Amount2 == 0)
                       {
                           CurrentPixel.R = (byte)PrimaryColor.R;
                           CurrentPixel.G = (byte)PrimaryColor.G;
                           CurrentPixel.B = (byte)PrimaryColor.B;
                           CurrentPixel.A = (byte)PrimaryColor.A;
                        }
                       break;

                       case 2:

                       if (y % Amount2 == 0)
                       {
                           CurrentPixel.R = (byte)PrimaryColor.R;
                           CurrentPixel.G = (byte)PrimaryColor.G;
                           CurrentPixel.B = (byte)PrimaryColor.B;
                           CurrentPixel.A = (byte)PrimaryColor.A;
                        }
                       break;
                   }

                   dst[x,y] = CurrentPixel;
               }
           }
       }
   }

Have a little look for yourself.... although you might have to compile it first.

Share this post


Link to post
Share on other sites

Thanks!! Nice first try at CodeLab! :D

Just a cleanup and a small enhancement to your code, as it seemed to me (from your code) that you were trying to use BrushWidth:

int Amount1=10;  //[2,100]Line Spacing
int Amount2=1;   //[1,2]Vertical <-> Horizontal


void Render(Surface dst, Surface src, Rectangle rect)
{
   ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
   int       BrushWidth   = (int)EnvironmentParameters.BrushWidth;

   for(int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
           ColorBgra CurrentPixel = src[x,y];

           if(Amount2 == 1)
           {
              if ((x % Amount1) < BrushWidth)
                   CurrentPixel = PrimaryColor;
           }
           else
           {
              if ((y % Amount1) < BrushWidth)
                   CurrentPixel = PrimaryColor;
           }

           dst[x,y] = CurrentPixel;
       }
   }
}

Share this post


Link to post
Share on other sites

If anybody is interested, go to my Diagonal Lines Plugin thread page 2. I've got the script that allows different angles for the lines. The problem is that I cannot compile a 4-slider plugin with Codelab. It would be very helpful if anybody can help me create the interface. (Then, instead of having 1000 plugins about lines, you only need 1)

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