Some Dots and Lines crap without a scene
by Admiral Potato
JavaScript
var DotAndLineHolder = function(){
var t = this, requiredType = 'DotAndLineHolder';
if(t.type !== requiredType){
throw 'The ' + requiredType + ' Constructor must be invoked using the `new` keyword.';
}
t.dots = [];
t.lines = [];
s.add(t);
return t;
};
DotAndLineHolder.prototype = {
type: 'DotAndLineHolder',
addDot: function (dot){
this.dots.push(dot);
},
addLine: function (line){
var t = this, prevLine;
t.lines.push(line);
if(t.lines.length > 1){
prevLine = t.lines[t.lines.length -2];
prevLine.setNext(line);
line.setPrev(prevLine);
}
},
update: function(){
var t = this, i;
for(i = 0; i < t.lines.length; i += 1){
t.lines[i].update();
}
for(i = 0; i < t.dots.length; i += 1){
t.dots[i].update();
}
}
};
var Dot = function(args){
var t = this, requiredType = 'Dot';
if(t.type !== requiredType){
throw 'The ' + requiredType + ' Constructor must be invoked using the `new` keyword.';
}
args = args || {};
t.args = args;
t.pos = args.pos || new Vec2();
if(!args.parent){throw 'Dots MUST have a parent DotAndLineHolder specified!';}
t.parent = args.parent;
t.parent.addDot(t);
if(args.motion){
t.vel = new Vec2(Math.random() * 0.5,0);
}
return t;
};
Dot.prototype = {
type: 'Dot',//only for constructor checking
color: '#EF3F38',
radius: 3,
numFrames: 100,
drawCircle:function(vec,radius,color,fill,lineWidth){
var t = this, c = s.c, pos = vec;
radius = radius || 8;
c.beginPath();
c.strokeStyle = color || '#0f0';
c.lineCap = 'round';
c.lineJoin = 'round';
c.lineWidth= lineWidth || t.lineWidth || t.scene.lineWidth || 2;
c.arc(pos.x,pos.y, radius, 0, tau, false);
if(fill){
c.fillStyle= color || '#0f0';
...