Script: Spiral - Poyo-SSB/osu-playground GitHub Wiki
function start() {
var center = Playground.AddVector2('center', new Vector2(Playground.PLAYFIELD_WIDTH / 2, Playground.PLAYFIELD_HEIGHT / 2));
var spiralType = Playground.AddChoice('spiralType', 'Linear');
var sliderType = Playground.AddChoice('sliderType', 'Linear');
var scale = Playground.AddFloat('scale', 20);
var resolution = Playground.AddInt('resolution', 3);
var revolutions = Playground.AddInt('revolutions', 2);
Playground.AddOptionVector2(center, 'Center');
Playground.AddOptionChoice(spiralType, 'Spiral type', ['Linear', 'Log', 'Square root']);
Playground.AddOptionChoice(sliderType, 'Slider type', ['Linear', 'Bézier']);
Playground.AddOptionFloat(scale, 'Scale', 2, 5, 200);
Playground.AddOptionInt(resolution, 'Resolution', 3, 24);
Playground.AddOptionInt(revolutions, 'Revolutions', 1, 12);
}
function update() {
var center = Playground.GetValueVector2('center');
var spiralType = Playground.GetValueChoice('spiralType');
var sliderType = Playground.GetValueChoice('sliderType');
var scale = Playground.GetValueFloat('scale');
var resolution = Playground.GetValueInt('resolution');
var revolutions = Playground.GetValueInt('revolutions');
var points = [];
for (var i = 0; i < revolutions; i++) {
for (var j = 0; j < resolution; j++) {
var angle = (i * 2 * Math.PI) + (j / resolution) * 2 * Math.PI;
var multiplier = angle;
if (spiralType == 'Log') {
if (angle != 0) {
multiplier = Math.log(angle);
}
} else if (spiralType == 'Square root') {
multiplier = Math.sqrt(angle);
}
points.push(add(center, new Vector2(scale * multiplier * Math.cos(angle), scale * multiplier * Math.sin(angle))));
}
}
if (sliderType == 'Linear') {
Playground.AddSlider(CurveType.Linear, points);
} else {
Playground.AddChoice(CurveType.Bezier, points);
}
}