Logo
Filmmaskiner.dk

Define object

function dot(ctx, x, y){
	this.ctx = ctx;
	this.x = x;
	this.y = y;
	this.r = 3;
	this.color = "#0f0";
	this.draw = drawDot;
	this.newColor = newDotColor;
}

function drawDot(){
	var myctx = this.ctx;
	myctx.beginPath();
	myctx.arc(this.x, this.y, this.r, 0, 2*Math.PI, true);
	myctx.strokeStyle = this.color;
	myctx.stroke();
}

function newDotColor(color){
	this.color = color;
}

Use object (simple)

dot = new dot(ctx, 150, 150);
dot.radius = 10;
dot.draw();

Use object (in array)

var dots = new Array();

var dots_n = 20;

for(var d = 0; d < dots_n; d++){
	dots.push(new dot(ctx, 20+d*15, 50+d*10));
	dots[d].radius = 5;
	dots[d].draw();
}

Creative Commons License
Filmmaskiner.dk by Kasper Lauritzen is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
(unless other is noted)