Log In  


Hi friends,

I'm struggling to create a simple pendulum motion. I'm just trying to get a pixel to move along an arc and swing back. If I understand correctly, I need an angle variable that oscillates between .25 and .75. Right now, my angle variable ("a") oscillates between 1 and 0. How do I modulate the angle so it bounces between .75 and .25?

x,y=63,63

function _update()
         a = abs(time()/2 % 2-1) 

	 x=x+sin(a)
	 y=y+cos(a)
end

function _draw()
        cls()
	pset(x,y,7)
end


1

try this
x, y = 63, 63

function _update()
-- Generate angle oscillating between 0.25 and 0.75
a = 0.25 + 0.25 * (sin(time()/2) + 1)

-- Calculate position based on angle
-- Assuming a fixed radius, say 50 pixels
local radius = 50
local centerX, centerY = 63, 63

x = centerX + radius * sin(a * 2 * pi) -- Convert to radians if needed
y = centerY + radius * cos(a * 2 * pi)

end

function _draw()
cls()
pset(x, y, 7)
end



[Please log in to post a comment]