so299150

Canvas beginPath

by Alexandre Gomiero de Oliveira

JavaScript

(function(){
  var c = document.createElement("canvas");
  var ctx = c.getContext('2d');
  var fps = 30;
  var height = 300;
  var width = 300;
  var Bloco = new bloco();
  c.width = 300;
  c.height = 300;
  document.body.appendChild(c)

  setInterval(draw(), 1000/fps)

  function draw(){
    background("black");

    Bloco.put();

  }
  function bloco(x, y, size, color){
    this.size = size;
    this.x = x;
    this.y = y;
    this.color = color;

    this.put = function(){
      quadrado(10, 10, 10, "white");
    }
  }
  function quadrado(x, y, size, color){
  	ctx.beginPath(); // AQUI! Colocar o beginPath
    ctx.rect(x, y, size+x, size+y);
    ctx.fillStyle = color;
    ctx.fill();
  }
  function background(color){
  	ctx.beginPath(); // AQUI! Colocar o beginPath
    ctx.rect(0, 0, width, height);
    ctx.fillStyle = color;
    ctx.fill();
  }
})();