Script: Polygon - Poyo-SSB/osu-playground GitHub Wiki

function start() {
	var center = Playground.AddVector2('center', new Vector2(Playground.PLAYFIELD_WIDTH / 2, Playground.PLAYFIELD_HEIGHT / 2));
	var radius = Playground.AddFloat('radius', 100);
	var rotation = Playground.AddFloat('rotation', 180);
	var ngon = Playground.AddInt('ngon', 10);
	var sideCount = Playground.AddInt('sideCount', 5);

	Playground.AddOptionVector2(center, 'Center');
	Playground.AddOptionFloat(radius, 'Radius', 0, 40, 200);
	Playground.AddOptionFloat(rotation, 'Rotation', 1, 0, 360);
	Playground.AddOptionInt(ngon, 'N-gon', 3, 16);
	Playground.AddOptionInt(sideCount, 'Side count', 1, ngon);
}

function update() {
	var center = Playground.GetValueVector2('center');
	var radius = Playground.GetValueFloat('radius');
	var rotation = Playground.GetValueFloat('rotation');
	var ngon = Playground.GetValueInt('ngon');
	var sideCount = Playground.GetValueInt('sideCount');

	var points = [];

	var offset = rotation / 180 * Math.PI;

	var basePoint = add(center, new Vector2(0, radius));

	for (var i = 0; i < sideCount + 1; i++) {
		points.push(rotate(basePoint, center, offset + i * 2 * Math.PI / ngon));
	}

	Playground.AddSlider(CurveType.Linear, points);
}