09-25-2024, 07:10 PM
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