help moving a sprite in a ellipse
#3
Here is one sprite in constant ellipse Y- and b+ constantly tilting ellipse by a degree after every orbit:
Code: (Select All)

_Title "Experiment with Ellipse draw sprite" 'b+ 2023-07-05
Type xy
    As Single x, y
End Type

Screen _NewImage(800, 600, 32)
_ScreenMove 250, 60
ReDim ell(0) As xy, ell2(0) As xy
MapEllipse 400, 300, 250, 100, ell() '  x,y track for b+
MapEllipse 400, 300, 100, 250, ell2() ' x,y track for Y-
Sprite = _NewImage(40, 40, 32)
_Dest Sprite
Line (0, 0)-(39, 39), &HFF0000FF, BF
_PrintMode _KeepBackground , Sprite
_PrintString (12, 12), "b+"
Sprite2 = _NewImage(40, 40, 32)
_Dest Sprite2
Line (0, 0)-(39, 39), &HFFFFFF00, BF
_PrintMode _KeepBackground , Sprite2
Color &HFF000000
_PrintString (12, 12), "Y-"

_Dest 0
Dim temp As xy
While _KeyDown(27) = 0
    Line (0, 0)-(_Width, _Height), &H05000000, BF
    frame = frame + 1
    If frame = 360 Then frame = 0: tilt = tilt + 1
    Rotate 400, 300, ell(frame).x, ell(frame).y, tilt, temp
    _PutImage (temp.x, temp.y)-Step(_Width(Sprite), _Height(Sprite)), Sprite, 0
    _PutImage (ell2(frame).x, ell2(frame).y)-Step(_Width(Sprite), _Height(Sprite)), Sprite2, 0
    _Display
    _Limit 120
Wend

Sub MapEllipse (xc, yc, xRadius, yRadius, a() As xy)
    ReDim a(360) As xy
    For a = 0 To _Pi(2) Step _Pi(2 / 360)
        a(i).x = xc + xRadius * Cos(a)
        a(i).y = yc + yRadius * Sin(a)
        i = i + 1
    Next
End Sub

Sub Rotate (cx, cy, x, y, degAng, a As xy)
    'cx, cy is center of rotation
    'x, y the point to rotate
    'degAng the angle in degrees to rotate
    ' output a.X, a.Y ' our point of rotation
    d = _Hypot(cx - x, cy - y) ' distance between xc and x
    ang = _Atan2(y - cy, x - cx)
    a.x = cx + d * Cos(ang + _D2R(degAng))
    a.y = cy + d * Sin(ang + _D2R(degAng))
End Sub
b = b + ...
Reply


Messages In This Thread
help moving a sprite in a ellipse - by Cobalt - 07-06-2023, 12:21 AM
RE: help moving a sprite in a ellipse - by bplus - 07-06-2023, 01:48 AM
RE: help moving a sprite in a ellipse - by bplus - 07-06-2023, 12:13 PM
RE: help moving a sprite in a ellipse - by bplus - 07-06-2023, 01:02 PM
RE: help moving a sprite in a ellipse - by Cobalt - 07-06-2023, 05:33 PM



Users browsing this thread: 5 Guest(s)