Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ugh. Is my math (and logic) right?
#8
(08-29-2023, 02:00 AM)bplus Wrote: Oh I hadn't setup my method correctly it's fast too comparing bLine to MyLine
Code: (Select All)
Screen _NewImage(800, 600, 32)
bLine 300, 30, 300, 500
bLine 300, 30, 500, 30
For X = 0 To 640 Step 10
    Color &HFFFF0000
    MyLine 0, 0, X, 200
Next X
For Y = 0 To 200 Step 5
    Color &HFF0000FF
    bLine 0, 0, 640, Y
Next Y

Sub bLine (x1, y1, x2, y2)
    dx = x2 - x1
    dy = y2 - y1
    dist = Sqr(dx * dx + dy * dy)
    dx = dx / dist
    dy = dy / dist
    For i = 0 To dist
        PSet (x1 + dx * i, y1 + dy * i)
    Next
End Sub
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

I had started with something more like bline, but I was really not sure of myself, and went the other way.

I much prefer bline.  I will steal that.
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 bplus - 08-29-2023, 02:00 AM
RE: Ugh. Is my math (and logic) right? - by CharlieJV - 08-29-2023, 02:31 AM
RE: Ugh. Is my math (and logic) right? - by bplus - 08-29-2023, 12:26 PM



Users browsing this thread: 11 Guest(s)