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


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


@AtomicPico to the rescue again!


1

ok, im sorry to tell you this. I literally just put your questions into an ai, im not that smart.


1

@AtomicPico LOL, well thanks for caring enough to do that. And now I know I can ask Ai bots and potentially get a proper solution.


1

I made a sample to better understand it.

x,y=63,63

px,py=0,0
from,to=0.25,0.75
radius=16
rate=4

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

	--angle [1 0 -1] exchange to:
	---  between [-0.25 : 0.25] *(from-to)/2
	---- between [ 0    : 0.50] -(from-to)/2
	---- between [ 0.25 : 0.75] (+from)

	local d=(from-to)/2
	a=cos(time()/rate)*d-d+from

	px=x+cos(a)*radius
	py=y+sin(a)*radius
end

function _draw()
 cls()
	pset(px,py,7)

	-- angle:from
	circ(x+cos(from)*radius,y+sin(from)*radius,2,8)
	-- angle:to
	circ(x+cos(to)*radius,y+sin(to)*radius,2,12)
	?a,48,32,6

end

Hi @shiftalow,

Somehow I missed your reply. Thank you so much! Checking out the cart/code now.



[Please log in to post a comment]