Log In  

I'm trying to make a tentacle using sin().
I want the base (the top circle) to be static, and the wiggle of the tentacle to get stronger until it reaches the tip (the bottom circle).
So far I have only achieved a pendulum
I'm not that good with math so I'm not sure about how to do it
here's my code

function _init()

length=20
x=64
y=40
end

function _draw()
cls()

 for i=0,length do
 circfill(x+sin(time())*i,y+i*4,length-i,14)
 end

end
P#103517 2021-12-25 10:11

1

To make it wiggle you need the circles to be swinging at different rates or with otherwise different timing. The way to do that would be to have the input for the sin() function have i in it. If you add i to time() it makes the circles have a sinusoidal offset. However, with the number of circles you're using, just i by itself will cause enough difference per circle to disconnect the circles. To solve that, just divide i by at least 10 (actual number depends on how much overall wiggling you want). Using 10, it would look like this:
cirfill(x+sin(time()+i/10)*i,y+i*4,length-i,14)

Multiplying i by a number less than 1 in the size parameter would also help, as it would make the circles not get quite so small at the end. Using .7 as an example, this would look like this:
circfill(x+sin(time()+i/10)*i,y+i*4,length-i*.7,14)

P#103522 2021-12-25 13:42

That works great! thanks!
the second solution made it lose its pointy end. I'll need to figure out how to make the circles look connected

P#103613 2021-12-27 12:53

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 06:10:48 | 0.006s | Q:14