[Implemented] A sane Line command?

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

[Implemented] A sane Line command?

Post by BackupUser »

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:

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


--
It's not minimalist - I'm increasing efficiency by reducing input effort.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

[quote]
; Draw line here with stupid PB Line command syntax
w = x2 - x1 : h = y2 - y1
If w


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
I haven't tried this, but I think you can change the above code to the following
single line, and lose the test for negative numbers. Give it a try... it may be
better for what you're doing?

w=Abs(x2-x1) : h=Abs(y2-y1)
No because I need to change the start co-ordinates if the width or height is negative, so using Abs does not give any advantage.
Oh, and the Line syntax isn't stupid; it's powerful. If it didn't have the
width and height properties, then trying to draw a line with a variable width
and height would be impossible. So it's a good thing that it uses them, and
when you need to use a start/end instead you just make a procedure, as you've
done.
The way the PB Line command works has no advantages over using a line command where you specify two co-ordinates, so it's not what I would call powerful. I don't know how you come up with drawing a line with variable width and height being impossible, because all you have to do is change the second co-ordinate (and given the way images are displayed on a computer, you are more likely to have or it is easier to get sets of co-ordinates rather than widths and heights of lines).



--
It's not minimalist - I'm increasing efficiency by reducing input effort.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.
The way the PB Line command works has no advantages over using a line command where you specify two co-ordinates, so it's not what I would call powerful. I don't know how you come up with drawing a line with variable width and height being impossible, because all you have to do is change the second co-ordinate
You're right... I wasn't thinking properly when I posted that. Sorry!


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
don't know how you come up with drawing a line with variable width and height being impossible, because all you have to do is change the second co-ordinate
You're right... I wasn't thinking properly when I posted that. Sorry!
I guess you were thinking of the thickness of the line...now that would be a cool feature :wink:


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