Skip to content

Instantly share code, notes, and snippets.

@johnstew
Last active December 12, 2015 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnstew/4748299 to your computer and use it in GitHub Desktop.
Save johnstew/4748299 to your computer and use it in GitHub Desktop.
Canvas Circle Object. Looking for advice as to improve this.
window.onload = function(){
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
canvas.width = 500;
canvas.height = 500;
function Circle(posX,posY,r,c,lw,s){
this.x = posX;
this.y = posY;
this.radius = r;
this.color = c;
this.lineWidth = lw;
this.strokeStyle = s;
context.beginPath();
context.arc(this.x,this.y,this.radius, 0, 2 * Math.PI, false);
context.fillStyle = '#'+this.color;
context.fill();
context.lineWidth = this.lineWidth;
context.strokeStyle = '#'+this.strokeStyle;
context.stroke();
}
var circle = new Circle(50,50,20, "0000ff", 2, "ff0000");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment