[Implemented] A sane Line command?
Posted: Sat Apr 27, 2002 7:31 pm
Restored from previous forum. Originally posted by tinman.
Hi, I was playing around with line drawing today, and was not having fun.
I have lines to draw and the data comes as co-ordinates for the start and end of a line. No problem, I thought, just do x2-x1 and y2-y1 to get the width and height and then correct them if they are negative.
Which works OK up to a point (pun intended
. However, I also noticed that I needed to add 1 to get the line drawn up to the exact pixel position I want. For example, the line needs to go from 0,5 to 20,5 so I need to draw 21 pixels wide.
Again, it's not that simple, because vertically you do not want the height to have 1 added or the line goes at an angle incorrectly. And it gets even worse, because the component (width or height) which you need to add 1 to changes with the angle of your line.
(Implemented as 'LineXY()')
Anyway, this is the code I use for drawing lines now:
And I'm still not sure if it handles all possibilities of line sizes. Of course, it would be much nicer to have this done inside PB's Line command 
--
It's not minimalist - I'm increasing efficiency by reducing input effort.
Hi, I was playing around with line drawing today, and was not having fun.
I have lines to draw and the data comes as co-ordinates for the start and end of a line. No problem, I thought, just do x2-x1 and y2-y1 to get the width and height and then correct them if they are negative.
Which works OK up to a point (pun intended

Again, it's not that simple, because vertically you do not want the height to have 1 added or the line goes at an angle incorrectly. And it gets even worse, because the component (width or height) which you need to add 1 to changes with the angle of your line.
(Implemented as 'LineXY()')
Anyway, this is the code I use for drawing lines now:
Code: Select all
Procedure MyLine(x1.w, y1.w, x2.w, y2.w)
DefType.l w
DefType.l h
; Draw line here with stupid PB Line command syntax
w = x2 - x1 : h = y2 - y1
If wh
w=w+1
Else
h=h+1
If w=h : w=w+1 : EndIf
EndIf
Line(x1, y1, w, h)
EndProcedure

--
It's not minimalist - I'm increasing efficiency by reducing input effort.