function Phosphor(d) {
	this.display = null;
	this.ctx = null;
	this.drawList = [];
	this.updateFunc = null;

	if (d)
		this.connectDisplay(d);
}

Phosphor.prototype.connectDisplay = function(d) {
	this.display = d;
	this.ctx = display.getContext('2d');

	this.ctx.fillStyle = 'black';
	this.ctx.fillRect(0, 0, display.width, display.height);
	this.ctx.fillStyle = 'rgba(0,0,0,0.075)';
	this.ctx.strokeStyle = '#00FF00';
}

Phosphor.prototype.setUpdate = function(f) {
	this.updateFunc = f;
}

Phosphor.prototype.drawSegments = function(pointlist) {
	for (var i = 0; i < pointlist.length; i++) {
		this.drawList.push(pointlist[i]);
	}
	this.drawList.push(null);
}

Phosphor.prototype.drawTriangle = function(p1, p2, p3) {
	this.drawList.push(p1, p2, p3, p1, null);
}

Phosphor.prototype.drawPoint = function(p) {
	this.drawList.push(p, [p[0] + 1, p[1] + 1], null);
}

Phosphor.prototype.draw = function() {
	if (this.drawList.length <= 1) return;

	var i, nl = false;

	this.ctx.fillRect(0, 0, this.display.width, this.display.height);
	this.ctx.beginPath();
	this.ctx.moveTo(this.drawList[0][0], this.drawList[0][1]);
	for (i = 1; i < this.drawList.length; i++) {
		if (this.drawList[i] == null) {
			this.ctx.stroke();
			nl = true;
		} else if (nl) {
			this.ctx.beginPath();
			this.ctx.moveTo(this.drawList[i][0], this.drawList[i][1]);
			nl = false;
		} else {
			this.ctx.lineTo(this.drawList[i][0], this.drawList[i][1]);
		}
	}
	if (!nl)
		this.ctx.stroke();
	this.drawList = [];
}

Phosphor.prototype.startEngine = function() {
	this.engineHandle = setInterval((function(obj) {
		return function() {
			obj.engine()
		}
	})(this), 20);
}

Phosphor.prototype.engine = function() {
	if (this.updateFunc)
		this.updateFunc();
	this.draw();
}

