Animation 2

Beispiel aus dem Kapitel Processing in JavaScript.

Code

var x = 10;
var s = 2;

function setup() {
  createCanvas(200, 200);
}

function draw() {
  background(0);
  ellipse(x, height/2, 20, 20);
  x = x + s;
  if (x > width-10 || x < 10) {
    s = -s;
  }
}