Animation / アニメーション

円が動きます。

move update loop
Hello P5 Animation

View Source Code

/*
 * @name Animation
 * @arialabel Light grey background with a dark grey circle that is traveling up from the middle of the bottom of the screen as it moves slightly side-to-side
 * @description The circle moves.
 */
// Where is the circle
let x, y;

function setup() {
  // createCanvas(720, 400);
  createCanvas(windowWidth, windowHeight);
  // Starts in the middle
  x = width / 2;
  y = height;
}

function draw() {
  background(200);
  
  // Draw a circle
  stroke(50);
  fill(100);
  ellipse(x, y, 24, 24);
  
  // Jiggling randomly on the horizontal axis
  x = x + random(-1, 1);
  // Moving up at a constant speed
  y = y - 1;
  
  // Reset to the bottom
  if (y < 0) {
    y = height;
  }
}

License

Source code is available on GitHub p5.js website legacy.

All examples are licensed under CC BY-NC-SA 4.0.