Jump to content

Cannot make Perfect lines (in 2x1)


Recommended Posts

Holding Shift

Green=how it must be

justtheproblembs6.png

PS: I can make perfect lines with mspaint .-.

I was about to mention various and sundry things about slopes and those lines' slopes being different, etc, but then I tries to do what (I think) the poster is trying to do.

He's right (to my surprise)...If I make a 200 x 100 px image and try to carefully draw a non-antialiased line from corner to corner, it has a varying slope.

drakaan sig jan 2020.png

Link to comment
Share on other sites

Holding shift constrains the line to an angle that is a multiple of 15 degrees. The angle you want, if you build the triangle and solve it (opposite edge is 1, adjacent edge is 2, hypotenuse is sqrt(5)), is not a multiple of 15 degrees.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Repro:

Draw a 1px non-AA diagonal line 200px across and 100px down in MSPaint.

Then do the same thing in PdN.

Results don't match... :?

Wow...this just hit me.

Are we *seriously* saying that we wish PDN was more like MS Paint? :shock:

For a while I was a serious "fanboy" of MS Paint's skew option...until MadJik put the Oblique Effect Plugin out there!

 

Take responsibility for your own intelligence. ;) -Rick Brewster

Link to comment
Share on other sites

Repro:

Draw a 1px non-AA diagonal line 200px across and 100px down in MSPaint.

Then do the same thing in PdN.

Results don't match... :?

Wow...this just hit me.

Are we *seriously* saying that we wish PDN was more like MS Paint? :shock:

For a while I was a serious "fanboy" of MS Paint's skew option...until MadJik put the Oblique Effect Plugin out there!

lol, another bore way to make perfect lines XD

Do it's impossible to create a plugin with "Paint Lines" ? :P

Link to comment
Share on other sites

Short solution using CodeLab and based on the Drawline function from BoltBait:

int Amount1=1; //[0,1] Orientation 0=up-down;1=down-up
void Render(Surface dst, Surface src, Rectangle rect) 
{ 
 PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); 
 Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); 

 int x1,y1,x2,y2;

 if (Amount1==0)
 {
   x1=selection.Left; 
   y1=selection.Top; 
   x2=selection.Right; 
   y2=selection.Bottom; 
 }
 else
 {
   x1=selection.Left; 
   y2=selection.Top; 
   x2=selection.Right; 
   y1=selection.Bottom; 
 }

 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++) 
     if (selectionRegion.IsVisible(x, y)) 
       dst[x,y] = src[x,y]; 

 DrawLine(x1,y1,x2,y2, dst, PrimaryColor, selectionRegion); 
} 
void DrawLine(int x1, int y1, int x2, int y2, Surface dst, ColorBgra LineColor, PdnRegion selectionRegion) 
{ 
 int i; 
 double roundx,roundy,xi,yi,dx,dy,x,y,l; 

 dx=Math.Abs(x2-x1); 
 dy=Math.Abs(y2-y1); 

 if(Math.Abs(dx)>Math.Abs(dy)) l=dx; else l=dy; 

 xi=2*dx/l; 
 yi=2*dy/l; 
 if ((x2  { 
   if (xi>=1.5) {xi=2;yi=-1;} else if (yi>=1.5) {xi=1;yi=-2;} 
 } 
 else 
 { 
   if (xi>=1.5) {xi=2;yi=1;} else if (yi>=1.5) {xi=1;yi=2;} 
 } 
 x=x1; 
 y=y1; 

 if (selectionRegion.IsVisible((int)x, (int)y)) 
 { 
   dst[(int)x, (int)y] = LineColor; 
 } 

 for(i=1;i<=l;i++) 
 { 
   x = x + xi / 2.0; 
   y = y + yi / 2.0; 

   roundx = x + 0.5; 
   roundy = y + 0.5; 
   if (selectionRegion.IsVisible((int)roundx, (int)roundy)) 
   { 
     dst[(int)roundx, (int)roundy] = LineColor; 
   } 
 } 
}

EDIT:Amount1 to change the orientation...

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.

 Share

×
×
  • Create New...