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