// set up code;
var canvas = document.getElementById("canV");
var ctx = canvas.getContext("2d");
var cw = canvas.width;
var ch = canvas.height
ctx.clearRect(0,0,cw,ch)
ctx.globaleAlpha = 1;
// function to draw a arc with two radius wr the width radius
// and hr the height radius; start end are the start and end angles
function arc2(x, y, wr, hr, start, end){
var i, xx, yy, step;
step = 2 / Math.max(wr,hr); // get number of steps around
for(i = start; i <= end; i+= step){ // from start to end
if(i > end -step / 2){ // ensure that there is no floating
i = end; // point error at end of sweep
}
xx = Math.cos(i) * wr + x; // calculate point on circle
yy = Math.sin(i) * hr + y;
if(i === start){ // if first Point move to
ctx.moveTo(xx,yy);
}else{
ctx.lineTo(xx,yy);
}
}// all done return;
}
// demo to draw circles till the cows come home
var circleDraw = function () {
var x, y, rw, rh;
// get some randoms numbers for circles
x = Math.random() * (cw / 2) + cw / 4;
y = Math.random() * (ch / 2) + ch / 4;
rw = Math.random() * ch / 4 + 20;
rh = Math.random() * ch / 4 + 20;
ctx.strokeStyle = "hsl(" + Math.floor(Math.random() * 260) + ",100%,50%)";
ctx.fillStyle = "hsl(" + Math.floor(Math.random() * 260) + ",100%,50%)";
ctx.lineWidth = Math.random() * 10;
ctx.beginPath();
// draw the arc with new function
arc2(x, y, rw, rh, 0, Math.PI * 2);
ctx.closePath(); // close the path
// fill and or stoke it
if (Math.random() > 0.5) {
ctx.fill();
}
if (Math.random() > 0.5) {
ctx.stroke();
}
setTimeout(circleDraw, 200);
}
setTimeout(circleDraw, 200);
.canC {
width:256px;
height:256px;
}
<canvas class="canC" id="canV" width=256 height=256></canvas>