UNPKG

cdf

Version:

A library for creating oldschool demo-like animations with JavaScript

30 lines (27 loc) 914 B
var Points = require('class/Points'); var utils = require('utils'); var shapes = { ngon: function(n){ var points = new Points(); var step = utils.TWO_PI/n; for (var i = 0; i <= n;i += 1) { points.push([Math.sin(i*step), Math.cos(i*step)]); } return points; }, rect: function(){ return new Points().push([-0.5,-0.5]).push([0.5,-0.5]).push([0.5,0.5]).push([-0.5,0.5]); }, circle: function(endAngle, sidesNumber, close){ var points = new lib.Points(); endAngle = ((endAngle % 360 || 360) * lib.utils.DEG_TO_RAD); sidesNumber = sidesNumber || Math.ceil(360 * endAngle / lib.utils.TWO_PI); var step = endAngle / sidesNumber; for (var i = 0; i <= sidesNumber; i++) { points.push([Math.sin(i*step+lib.utils.PI_BY_TWO), Math.cos(i*step+lib.utils.PI_BY_TWO)]); } if(close)points.push(points[0]); return points; } }; module.exports = shapes;