Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
lineFT - draw a thick line
#1
It's not fancy but it draws lines over 1 pixel in thickness.
Code: (Select All)
'draw_lineFT
' By James D. Jarvis August 21,2023
'draw a line with a defined thickness
Screen _NewImage(400, 500, 32)
Dim Shared tk&
tk& = _NewImage(3, 3, 32)
'*********************************************
'demo
'*********************************************
x1 = 100: y1 = 100
x2 = 300: y2 = 300
x3 = 100: y3 = 200
lineFT x1, y1, x2, y2, 10, _RGB32(200, 100, 0)
lineFT x2, y2, x3, y3, 10, _RGB32(200, 100, 0)
lineFT x1, y1, x3, y3, 10, _RGB32(200, 100, 0)

'*************** routines **********************
'lineFT - draw a thick line constructed from 2 mapped triangles
'DegTo - return angle (in degrees) between two points , used as an internal function in lineFT
'*********************************************
Sub lineFT (x1, y1, x2, y2, thk, klr As _Unsigned Long)
    'draw a line of thickness thk on color klr from x1,y1 to x2,y2
    'orientation of line is set in the middle of line thickness
    _Dest tk&
    Line (0, 0)-(2, 2), klr, BF 'set the color for the line
    _Dest 0
    cang = DegTo(x1, y1, x2, y2) 'get the angle from x1,y1 to x2,y2
    ta = cang + 90
    tb = ta + 180
    tax1 = x1 + (thk / 2) * Cos(0.01745329 * ta)
    tay1 = y1 + (thk / 2) * Sin(0.01745329 * ta)
    tax4 = x1 + (thk / 2) * Cos(0.01745329 * tb)
    tay4 = y1 + (thk / 2) * Sin(0.01745329 * tb)
    tax2 = x2 + (thk / 2) * Cos(0.01745329 * ta)
    tay2 = y2 + (thk / 2) * Sin(0.01745329 * ta)
    tax3 = x2 + (thk / 2) * Cos(0.01745329 * tb)
    tay3 = y2 + (thk / 2) * Sin(0.01745329 * tb)
    _MapTriangle (0, 0)-(0, 2)-(2, 0), tk& To(tax1, tay1)-(tax2, tay2)-(tax4, tay4)
    _MapTriangle (0, 0)-(0, 2)-(2, 0), tk& To(tax2, tay2)-(tax3, tay3)-(tax4, tay4)
End Sub
Function DegTo! (x1, y1, x2, y2)
    '========================
    ' returns an angle in degrees from point x1,y1 to point x2,y2
    aa! = _Atan2((y2 - y1), (x2 - x1)) / 0.01745329
    DegTo! = aa!
End Function
Reply




Users browsing this thread: 1 Guest(s)