(08-29-2023, 01:12 AM)bplus Wrote: Works for me after I make it right with QB64:
Code: (Select All)Screen _NewImage(641, 201, 32)
For X = 0 To 640 Step 10
MyLine 0, 0, X, 200
Next X
For Y = 0 To 200 Step 5
Line (0, 0)-(640, Y), _RGB(255, 255, 0)
Next Y
Sub MyLine (x1%, y1%, x2%, y2%)
' y% = m# * x% + c#
xd% = x2% - x1%
yd% = y2% - y1%
m# = yd% / xd%
c# = y2% - x2% * m#
If xd% >= yd% Then For i = x1% To x2%: PSet (i, m# * i + c#): Next i
If xd% < yd% Then For i = y1% To y2%: PSet ((i - c#) / m#, i): Next i
End Sub
And faster than my method! Nice if it works for all x, y
Ok, math seems to makes sens. I was really unsure.
Now to tackle vertical and horizontal lines.