Answers for "create many items from an array to canvas"

0

create many items from an array to canvas

function ball(){
    this.x = Math.random() * 100;
    this.y = Math.random() * 100;
    this.radius = Math.random() * 10;
    this.color = "#" + (Math.random() * 16777215).toString(16);

    this.draw = function(){
        ctx.beginPath();
        ctx.arc(this.x, this.y, this.radius, 0, 2*Math.PI, false);
        ctx.fillStyle = color;
        ctx.fill();
        ctx.closePath();
    }
}

var balls = [];

for(var i = 0; i < 4; i++) {
    balls[i] = new ball();
    balls[i].draw();
}
Posted by: Guest on June-30-2020

Code answers related to "create many items from an array to canvas"

Code answers related to "Javascript"

Browse Popular Code Answers by Language