Schloool/Boxes

Aus ProgrammingWiki

Wiki-Quelltext dieser Seite.

<language>Javascript</language>
<code id="5ddbf2e11ed12">
var canvas;
var context;
var blocks;

function Box(y, color, speed) {
  this.x = 0;
  this.a = 25;
  this.y = y;
  this.color = color;
  this.speed = speed;

  this.render = function() {
    context.fillColor(this.color);
    context.fillRect(this.x, this.y, this.width, this.width, this.color);
  }
}

function init() {
  canvas = new Canvas(1);
  context = canvas.getContext("2D");
  console.log("Lasset das wahnsinnige Spektakel beginnen.");
}

function tick() {
  blocks.forEach(function(block) {
    block["y"] += block["speed"];
  });
}

function render() {
  blocks.forEach(function(block) {
    block.render();
  });
}

function loopAnimation() {
  tick();
  render();
}

init();
runInterval("loopAnimation", 12);

</code>

<run id="5ddbf2e11edb0">

</run>

<canvas w=600, h=300> </canvas>