Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ugh. Is my math (and logic) right?
#6
(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.
Reply


Messages In This Thread
Ugh. Is my math (and logic) right? - by CharlieJV - 08-29-2023, 12:47 AM
RE: Ugh. Is my math (and logic) right? - by bplus - 08-29-2023, 01:12 AM
RE: Ugh. Is my math (and logic) right? - by CharlieJV - 08-29-2023, 01:43 AM
RE: Ugh. Is my math (and logic) right? - by bplus - 08-29-2023, 02:00 AM
RE: Ugh. Is my math (and logic) right? - by bplus - 08-29-2023, 12:26 PM



Users browsing this thread: 1 Guest(s)