Jump to content
How to Install Plugins ×

Simple Lines Plugin


spongey437

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 don't 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 toe_head2001
Formatting
Link to comment
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

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

Link to comment
Share on other sites

Well, there's one thing better on this one. It respects your brush colour. The lines are always black with your plugin.

EDIT: ...

And the line spacing goes up to 100...

 

Take responsibility for your own intelligence. 😉 -Rick Brewster

Link to comment
Share on other sites

Nice, simple plugin, but can't this be achieved with Paint.NET's fill modes?

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

twtr | dA | tmblr | yt | fb

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

Link to comment
Share on other sites

  • 2 months later...

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;
       }
   }
}

"Be who you are and say what you feel because those who mind don't matter and those who matter don't mind."

~Dr. Seuss

Link to comment
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)

siggiecj5.png

Some links: | Personal Website | Alien Attack |

Try out my plugins: | Antialias | Diagonal Lines |

Link to comment
Share on other sites

The new Paint.NET plugin interface has an angle chooser in it, there should be a way to use that instead of a slider, but don't ask me how coz I really don't know.

dA

Son, someday you will make a girl happy for a short period of time. Then she'll leave you & be with men that are ten times

better than you can imagine. These men are called musicians. :D

Link to comment
Share on other sites

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...