sync on : sync rate 0
`Specify the first start point (the end point is always the mouse pointer)
SX = 320
SY = 240
do
`Clear the screen
cls
`Draw a line from a point to the mouse
ink rgb(255, 255, 255), 0
line SX, SY, mousex(), mousey()
`Draw the line where the angle is 0 (below the point)
ink rgb(255, 0, 0), 0
line SX, SY, SX, 0
`Calculate the angle using atanfull
ang# = atanfull( mousex() - SX, (screen height() - mousey()) - SY)
`Wrap the angle
ang# = wrapvalue(ang#)
`Display that angle
ink rgb(255, 255, 255), 0
text 5, 5, "Current angle: " + str$(ang#)
`If you press your mouse button, the starting point will be at the mouse pos
if mouseclick() > 0
SX = mousex()
SY = mousey()
endif
sync
loop
There's only one thing I should explain, and that is why I did
atanfull(mousex() - SX, (screen height() - mousey()) - SY)
The reason why I did that, is because mousey() starts counting from the top of your screen. So, if your mouse is all the way above on your screen, mousey() = 0, if it is on the bottom, then it will be the screens height (
screen height()).
To invert this, I substracted the mouse y position from the screens height.
It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.