This repository has been archived by the owner on Dec 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Script: Star
Poyo edited this page May 10, 2018
·
2 revisions
function start() {
var center = Playground.AddVector2('center', new Vector2(Playground.PLAYFIELD_WIDTH / 2, Playground.PLAYFIELD_HEIGHT / 2));
var majorRadius = Playground.AddFloat('majorRadius', 130);
var minorRadius = Playground.AddFloat('minorRadius', 70);
var rotation = Playground.AddFloat('rotation', 180);
var ngon = Playground.AddInt('ngon', 5);
Playground.AddOptionVector2(center, 'Center');
Playground.AddOptionFloat(majorRadius, 'Major radius', 0, 40, 200);
Playground.AddOptionFloat(minorRadius, 'Minor radius', 0, 40, 200);
Playground.AddOptionFloat(rotation, 'Rotation', 1, 0, 360);
Playground.AddOptionInt(ngon, 'N-gon', 3, 16);
}
function update() {
var center = Playground.GetValueVector2('center');
var majorRadius = Playground.GetValueFloat('majorRadius');
var minorRadius = Playground.GetValueFloat('minorRadius');
var rotation = Playground.GetValueFloat('rotation');
var ngon = Playground.GetValueInt('ngon');
var points = [];
var offset = rotation / 180 * Math.PI;
var majorBase = add(center, new Vector2(0, majorRadius));
var minorBase = add(center, new Vector2(0, minorRadius));
for (var i = 0; i < 2 * ngon + 1; i++) {
if (i % 2 == 0) {
points.push(rotate(majorBase, center, offset + i * Math.PI / ngon));
}
else {
points.push(rotate(minorBase, center, offset + i * Math.PI / ngon));
}
}
Playground.AddSlider(CurveType.Linear, points);
}