Spiral object movement

Does anybody know how to move an object in a spiral pattern?

Like starting with a small radius, then spiraling bigger and bigger?

I searched Google and the forums but couldn’t find anything

[import]uid: 50459 topic_id: 22079 reply_id: 322079[/import]

Well i found this:

Multiply the center X coordinate with sin(angle) and Z (if in 3D or Y if in 2D) coordinate with cos(angle) while you slowly change the angle in range from 0 to 2 Pi.
Note that the sine and cosine return values in the range 0-1 so you have to multiply everything with some factor which represents the distance from the spiral’s center. Thos factor should be decreased over the time so the movement gets closer to the center.

But i have no idea how to do that in Corona. Anyone? [import]uid: 50459 topic_id: 22079 reply_id: 87692[/import]

The code below will display a blue ball, and have it spiral outward until it gets near the edge of the screen, then spiral back in until it gets near the center.

Enjoy!

[lua]display.setStatusBar( display.HiddenStatusBar )

local originX = display.contentCenterX – origin x of the movement path
local originY = display.contentCenterY – origin y of the movement path
local radius = 10 – Radius of the movement path
local angle = 0 – current angle along the movement path
local spiralStep = 60/30 – move twenty pixels over 1 second
local radialStep = 180/30 – move 180 degrees around our origin every second
local direction = 1 – 1 means spiral out, -1 means spiral in

local ball = display.newCircle( originX+radius, originY, 20 )
ball:setFillColor( 0,0,255 )

function updateBallPos()
ball.x = originX + math.sin( angle )*radius
ball.y = originY - math.cos( angle )*radius
end

– Called 30 FPS
function moveBall( event )
radius = radius + spiralStep*direction
angle = angle + radialStep
updateBallPos()
if ( direction == 1 ) then
if ( ball.x < 0.1*display.contentWidth or
ball.x > 0.9*display.contentWidth or
ball.y < 0.1*display.contentHeight or
ball.y > 0.9*display.contentHeight ) then
direction = -1
end
else
if ( ( ball.x >= 0.4*display.contentWidth and ball.x <= 0.6*display.contentWidth ) and
( ball.y >= 0.4*display.contentHeight and ball.y <= 0.6*display.contentHeight ) ) then
direction = 1
end
end
end

– Set the initial position
updateBallPos()

Runtime:addEventListener( “enterFrame”, moveBall )[/lua] [import]uid: 16734 topic_id: 22079 reply_id: 87724[/import]

Thank you so much, Ken!

Awesome! [import]uid: 50459 topic_id: 22079 reply_id: 87736[/import]