Hi,
I would like some help with creating code that has a sprite circling around a fixed point but its radius adjusts in and out with a key press and maintains the same time per revolution or thereabouts. I have been playing with some sin cos code found on this forum but cannot figure out how to do it and have the sprite return to its same starting point every time.
thanks
Cheers superjossy
Graphics 640,480
SetBuffer BackBuffer()
timer=CreateTimer(30)
amplitude=10
HidePointer
Repeat
WaitEvent()
If EventID()=$4001
If KeyDown(203) amplitude=amplitude+1
If KeyDown(205)
amplitude=amplitude-1
If amplitude<10 amplitude=10
EndIf
Cls
pointx=MouseX()
pointy=MouseY()
path=(path+5) Mod 360
objx=Sin(path)*amplitude
objy=Cos(path)*amplitude
Color 255,255,255
Oval pointx-2,pointy-2,5,5
Color 255,0,0
Oval pointx+objx-2,pointy+objy-2,5,5
Text 0,0,"use cursor left/right"
Flip
EndIf
Until KeyHit(1)
End
Thanks CS_TBL
The code is just perfect for what I want!
Can you explain the Mode 360? why is it needed?
regards superjossy
mod returns the remainder when the left hand value is divided by the right hand value e.g. 400 Mod 360 will return 40. 3601 Mod 360 will return 1 etc.
You don't need mod if you only use it for a short amount of time. In theory path could go up to the billions before it wraps to -billions. I'm sure that jump wouldn't look nice, so by modulo'ing I make sure the path-value *always* stays within the range of a circle, whatever happens.
Make sure tho that if you circle the other way (path=path-5) that you actually ADD 360-5 rather than -5. This makes sure the path value stays within 0..360, negative values are different when modulo'ing them. I made an ultimate mod (tm) once which also accepts negative values and keeping them in the 'same line' with positive values, dunno where it is atm.. :P
Thanks for that!
I have played with the code to get it to circle the other way when the space bar is pressed.
Thanks CS_TBL and Grey Alien for your help.