Script: Wave - Poyo-SSB/osu-playground GitHub Wiki
function start() {
var start = Playground.AddVector2('start', new Vector2(Playground.PLAYFIELD_WIDTH / 2 - 100, Playground.PLAYFIELD_HEIGHT / 2));
var end = Playground.AddVector2('end', new Vector2(Playground.PLAYFIELD_WIDTH / 2 + 100, Playground.PLAYFIELD_HEIGHT / 2));
var frequency = Playground.AddInt('frequency', 1);
var amplitude = Playground.AddFloat('amplitude', 90);
Playground.AddOptionVector2(start, 'Start');
Playground.AddOptionVector2(end, 'End');
Playground.AddOptionInt(frequency, 'Frequency', 1, 8);
Playground.AddOptionFloat(amplitude, 'Amplitude', 2, -200, 200);
}
function update() {
var start = Playground.GetValueVector2('start');
var end = Playground.GetValueVector2('end');
var frequency = Playground.GetValueInt('frequency');
var amplitude = Playground.GetValueFloat('amplitude');
var points = [];
var angle = Math.atan2(end.y - start.y, end.x - start.x) + Math.PI / 2;
for (var i = 0; i < frequency; i++) {
var vStart = lerp(start, end, i / frequency);
var vEnd = lerp(start, end, (i + 1) / frequency);
var crest = lerp(vStart, vEnd, 0.25);
var center = lerp(vStart, vEnd, 0.5);
var trough = lerp(vStart, vEnd, 0.75);
points.push(vStart);
points.push(rotate(add(crest, new Vector2(0, amplitude)), crest, angle + Math.PI / 2));
points.push(center);
points.push(center);
points.push(rotate(add(trough, new Vector2(0, amplitude)), trough, angle - Math.PI / 2));
points.push(vEnd);
}
Playground.AddSlider(CurveType.Bezier, points);
}