thanks @jasondelaat !

is there a way i can produce a sine wave effect (not unlike celeste classic 2) but in any direction?

and in a line-like function? such as

`rotated_sine_wave(x, y, direction, length, amp, wavelength, c)`

I changed `wavelength`

to `frequency`

and added a parameter `samples`

.

Samples controls the smoothness of the curve: more samples = smoother curve but at the cost of having to do more calculations and draw more lines. It may actually be overkill though.

Anyway, here you go:

function rotated_sine_wave(x, y, direction, length, amp, frequency, samples, c) samples = mid(2, length, samples) local sa = sin(direction) local ca = cos(direction) color(c) line(x, y) for t=0, length, length/(samples - 1) do local sint = amp*sin(frequency*t) local sx = ca*t - sa*sint local sy = ca*sint + sa*t line(x + sx, y + sy) end line() end cls() rotated_sine_wave(10, 10, -0.1, 128, 10, 3, 128, 7) |

I'm sure it could be optimized to use fewer tokens but I went with readable over compact.

Incidentally, you can use this basic method to rotate any function. You just have to treat the input and output of the function as a vector — so for this particular example the vector would be `(x, amp*sin(frequency*x))`

— and then rotate those vectors and plot them.

Hope that helps!

this is cool!

(could the thread be moved to Code snippets so that people find it?)

Just realized I left something out. You can also add a `phase`

parameter to shift the wave left/right. Not in terms of where it's drawn on screen but which part of the sine wave you actually start at.

And you can use that to animate if you want.

function rotated_sine_wave(x, y, direction, length, amp, frequency, phase, samples, c) samples = mid(2, length, samples) local sa = sin(direction) local ca = cos(direction) color(c) for t=0, length, length/(samples - 1) do local sint = amp*sin(frequency*t + phase) local sx = ca*t - sa*sint local sy = ca*sint + sa*t line(x + sx, y + sy) end line() end function _draw() cls() rotated_sine_wave(20, 20, -0.1, 100, 10, 3, time(), 128, 7) end |

Also the first call to `line(x, y)`

in the original version I posted isn't needed so I got rid of it here.

You're welcome! You mentioned Celeste 2, are you referring to the snow effect on the title screen? Regardless, I'm interested to see what you do with it!

@jasondelaat you got it exactly! it was for a game jam so thank you for the quick reply!

Thats so cool, I was just asking myself that very same question a few days ago, and boom someone already has a solution, thanks :)

@Ummmm_ok

Ah, cool, happy to help! Is the jam over? (I'm assuming yes since it's been like 3 months?) Is the game linked somewhere?

@jasondelaat Took a little while, but we got the game posted! https://www.lexaloffle.com/bbs/?tid=141463

[Please log in to post a comment]