; Tan Example
; -----------

Graphics 640,480,0,2
SetBuffer BackBuffer()

; Blitz3D trig works in DEGREES. Tan(angle)=Sin(angle)/Cos(angle) is
; the SLOPE of the rotating arm. Where the arm's line crosses a wall at
; distance r, the crossing height is r*Tan(angle) - it shoots off to
; infinity as the angle nears 90 or 270.

cx=240
cy=240
r=120

angle#=20

While Not KeyDown(1)

    ; Left/Right arrows steer the angle; it also drifts on its own
    If KeyDown(203) Then angle=angle-1
    If KeyDown(205) Then angle=angle+1
    angle=angle+0.2
    If angle>=360 Then angle=angle-360
    If angle<0 Then angle=angle+360

    ; The documented command: the slope for the current angle
    t#=Tan(angle)

    Cls

    ; The circle and a blue "wall" at distance r to the right
    Color 70,70,70
    Oval cx-r,cy-r,r*2,r*2,False
    Color 0,150,255
    Line cx+r,0,cx+r,479

    ; The rotating arm
    Color 255,255,0
    Line cx,cy,cx+r*Cos(angle),cy+r*Sin(angle)

    ; Red mark on the wall: the arm's line crosses it r*Tan(angle)
    ; below the centre height (skipped when Tan is huge near 90/270)
    If Abs(t)<10 Then
        Color 255,0,0
        Line cx+r,cy,cx+r,cy+r*t
        Oval cx+r-4,cy+r*t-4,8,8,True
    EndIf

    Color 255,255,255
    Text 0,0,"Left/Right: change angle   Esc: exit"
    Text 0,20,"angle = "+angle
    Text 0,40,"Tan(angle) = "+t

    Flip

Wend

End
