Jump to content

My first plugin (dimention problems)


Panhead

Recommended Posts

hello, its Panhead (no duh)

ive been messing around with codelab trying to make a plugin that creates a simple X on the canvas, so far i can only create an X on a square even dimensioned canvas, i know its simple

void Render(Surface dst, Surface src, Rectangle rect)
{
   // 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 CurrentPixel;
   for(int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
           long middleX = CenterX;
           long middleY = CenterY;
           long oddIdentifierY = (middleY % 2);
           long oddIdentifierX = (middleX % 2);

           CurrentPixel = src[x,y];
           // TODO: Add pixel processing code here
           if ((oddIdentifierY == 1) && (oddIdentifierX == 1))
           {
           	if ((x == y - (y - x)) && (y == (( CenterY * 2) - x)))
           	{
           	// 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 (x == y)
         	{
         		CurrentPixel.R = (byte)PrimaryColor.R;
               	CurrentPixel.G = (byte)PrimaryColor.G;
               	CurrentPixel.B = (byte)PrimaryColor.B;
               	CurrentPixel.A = (byte)PrimaryColor.A;
          	}

           }

           if ((oddIdentifierY == 0) && (oddIdentifierX == 0))
           {
           	if ((x == y - (y - x)) && (y == (( CenterY * 2) - (x + 1))))
          	 {
         	  // 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 (x == y)
           	{
               	CurrentPixel.R = (byte)PrimaryColor.R;
               	CurrentPixel.G = (byte)PrimaryColor.G;
               	CurrentPixel.B = (byte)PrimaryColor.B;
               	CurrentPixel.A = (byte)PrimaryColor.A;
           	}
           }



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

ok the first if statement isnt running, because when i run it on an odd canvas it still runs only the forth if statement,

did i code the first one right?

im not sure, if i can get this done, i will work on being able to do it on a rectangular canvas.

any help would be appreciated

1000sigwithout1000.png

My deviantART iGraphix

~96% of teens won't stand up for God. Put this on your page if you're one of the 4% who will.

skilletism (n.) - The abnormal liking of the band "Skillet". (see PANHEAD)

panhead n. - an individual who shows extreme enthusiasm for the band Skillet. Generally driving for hours to concerts with frying pans riding shotgun.

Link to comment
Share on other sites

For a rectangle you need the ratio between height and width...

I didn't get the odd stuff...

And you could simplify it (if you want it centered):

void Render(Surface dst, Surface src, Rectangle rect)
{
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 CurrentPixel;
for(int y = rect.Top; y < rect.Bottom; y++)
{
for (int x = rect.Left; x < rect.Right; x++)
{
CurrentPixel = src[x,y];
if ((Math.Abs(x - CenterX)) == (Math.Abs(y - CenterY)))
{
CurrentPixel = PrimaryColor;
}
dst[x,y] = CurrentPixel;
}
}
}

Link to comment
Share on other sites

the odd thing has to do with the top right corner, the code i tried was to figure out a different equation for when the canvas has dimensions like 801x801, and then run it only when the canvas had odd dimensions, which i know is rare to have a canvas like that, but still i would like to be efficient, i think i just need to learn the different resources that are available in the PDN program, like Math.Abs....i dont know what that is, i knew i had to know a ratio, but i just didnt know what the variables name was.

ill try this code out in a little, i got to go do something

1000sigwithout1000.png

My deviantART iGraphix

~96% of teens won't stand up for God. Put this on your page if you're one of the 4% who will.

skilletism (n.) - The abnormal liking of the band "Skillet". (see PANHEAD)

panhead n. - an individual who shows extreme enthusiasm for the band Skillet. Generally driving for hours to concerts with frying pans riding shotgun.

Link to comment
Share on other sites

the odd thing has to do with the top right corner, the code i tried was to figure out a different equation for when the canvas has dimensions like 801x801, and then run it only when the canvas had odd dimensions, which i know is rare to have a canvas like that, but still i would like to be efficient

Why run two equations based on odd/even canvas size?

Why not run the same code on both with the rider that the odd sized canvas will be perfect and the even sized canvas will have a 1 pixel column (or row) unused at the right edge (or bottom edge)?

(I haven't tried your code so I'm only guessing to the effect you're after.)

Link to comment
Share on other sites

i dont know, i dont have much experience with C# so i think i am going to hold off on the plugins, but thanks for the help

1000sigwithout1000.png

My deviantART iGraphix

~96% of teens won't stand up for God. Put this on your page if you're one of the 4% who will.

skilletism (n.) - The abnormal liking of the band "Skillet". (see PANHEAD)

panhead n. - an individual who shows extreme enthusiasm for the band Skillet. Generally driving for hours to concerts with frying pans riding shotgun.

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