Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Line Points
#1
Small utility for calculating points in line.

Code: (Select All)

Type LinePoints
    X As Integer
    Y As Integer
End Type
ReDim Shared LP(0) As LinePoints

Screen _NewImage(800, 600, 32)

Line (40, 399)-(100, 199)
GETPOINTS 40, 399, 100, 199, LP()
Sleep
'if all points in array are calctulated correctly, all points in LINE are draw yellow


For D = 0 To UBound(LP)
    PSet (LP(D).X, LP(D).Y), &HFFFFFF00
Next D


Sub GETPOINTS (x1, y1, x2, y2, A() As LinePoints)
    Dim lenght As Integer
    lenght = _Hypot(x1 - x2, y1 - y2) 'Fellippe Heitor show me using this great function.
    ReDim A(lenght) As LinePoints
    For fill = 0 To lenght
        If x1 > x2 Then A(fill).X = x1 - fill * ((x1 - x2) / lenght)
        If x1 < x2 Then A(fill).X = x1 + fill * ((x2 - x1) / lenght)
        If x1 = x2 Then A(fill).X = x1
        If y1 > y2 Then A(fill).Y = y1 - fill * ((y1 - y2) / lenght)
        If y1 < y2 Then A(fill).Y = y1 + fill * ((y2 - y1) / lenght)
        If y1 = y2 Then A(fill).Y = y1
    Next
End Sub


Reply
#2
Hey that's handy. Thank you.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#3
Nice snippet.  Thanks.

- Dav

Find my programs here in Dav's QB64 Corner
Reply




Users browsing this thread: 1 Guest(s)