'use strict';
/**
* NMLs library
*/
/**
* The great keystroke saver
*/
var $ = function (foo) {
return document.getElementById(foo);
}
/**
* Canvas object definition
*/
var Canvas = function(canvasId, color) {
this.canvas = $(canvasId);
this.context = this.canvas.getContext('2d');
this.color = color;
this.prep();
}
Canvas.prototype.prep = function() {
this.context.fillStyle = this.color;
this.context.fillRect(0,
0,
this.canvas.width,
this.canvas.height);
}
Canvas.prototype.clear = function() {
this.context.clearRect(0,
0,
this.canvas.width,
this.canvas.height);
}
Canvas.prototype.getContext = function () {
return this.context;
}
Canvas.prototype.getHeight = function () {
return this.canvas.height;
}
Canvas.prototype.getWidth = function () {
return this.canvas.width;
}
/**
* Defines a coordinate system
* with origo at canvas coordinates ox,oy
*/
var CoordinateSystem = function (ox, oy) {
this.x = ox;
this.y = oy;
}
CoordinateSystem.prototype.draw = function (bar) {
var ctx = bar.getContext();
ctx.beginPath();
ctx.strokeStyle = 'black';
ctx.moveTo(10, this.y);
ctx.lineTo(bar.getWidth() - 10, this.y);
ctx.moveTo(this.x, 10);
ctx.lineTo(this.x, bar.getHeight() - 10);
ctx.stroke();
ctx.closePath();
}
/**
* Defines a Unitcircle
* with center at canvas coordinates ox,oy
* and radius r
*/
var UnitCircle = function (ox, oy, r, el) {
this.x = ox;
this.y = oy;
this.r = r;
this.a = 0;
this.el = 0;
if (el != null)
this.el = el;
}
UnitCircle.prototype.draw = function (baz) {
var ctx = baz.getContext();
ctx.beginPath();
ctx.strokeStyle = 'black';
ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2, true);
ctx.stroke();
ctx.closePath();
}
UnitCircle.prototype.angleDraw = function (baz) {
var ctx = baz.getContext();
ctx.beginPath();
ctx.strokeStyle = 'red';
ctx.moveTo(this.x, this.y);
ctx.lineTo(this.x + this.getRadius() + 10, this.y);
ctx.moveTo(this.x, this.y);
ctx.lineTo(this.getCosEP(), this.getSinEP());
ctx.stroke();
ctx.closePath();
}
UnitCircle.prototype.getRadius = function() {
return this.r;
}
UnitCircle.prototype.getAngle = function() {
return this.a;
}
UnitCircle.prototype.getSinEP = function() {
return -Math.sin(this.a) * (this.r + this.el) + this.y;
}
UnitCircle.prototype.getCosEP = function() {
return Math.cos(this.a) * (this.r + this.el) + this.x;
}
UnitCircle.prototype.angleInc = function(deg) {
if (deg == null)
deg = 720;
this.a += Math.PI * 2 / deg;
}
/**
* Defines a Dot
* with center at canvas coordinates ox,oy
* and radius r
* meant for drawing and animation
*/
var Dot = function (ox, oy, r, color) {
this.x = ox;
this.y = oy;
this.r = r;
this.color = color;
}
Dot.prototype.draw = function (baz) {
var ctx = baz.getContext();
ctx.beginPath();
ctx.strokeStyle = this.color;
ctx.arc(this.getX(), this.getY(), this.getRadius(), 0, Math.PI * 2, true);
ctx.stroke();
ctx.closePath();
}
Dot.prototype.getX = function() {
return this.x;
}
Dot.prototype.setX = function(x) {
this.x = x;
}
Dot.prototype.getY = function() {
return this.y;
}
Dot.prototype.setY = function(y) {
this.y = y;
}
Dot.prototype.getRadius = function() {
return this.r;
}