自画像を動かす

by 山口みづき

2025-05-26 21:13:16

sketch.js

let speedX = 1;
let x = 200;
let speedY = 1;
let y = 330;

function setup() {
  createCanvas(600, 600); //ウィンドウサイズの指定
  background(255, 255, 135); //背景色を指定して1回だけ塗る。
  stroke(0, 0, 255);
  fill(0, 255, 0);
  noStroke();
  fill(105, 235, 0);
  ellipse(200, 250, 220, 100);
  ellipse(400, 250, 220, 100);
  fill(0, 0, 0);
  circle(200, 240, 30);
  circle(330, 240, 30);
  rect(250, 260, 20, 20);
  stroke(255, 255, 255);
  fill(105, 235, 0);
  noStroke();
  rect(285, 270, 30, 230);
}

function draw() {
  // background(0, 0, 0); //背景色を指定して1回だけ塗る。
  fill(105, 235, 0);
  stroke(0, 0, 0);
  circle(x, 240, 30);
  x = x + speedX;
  if (x > 300) {
    speedX = -1;
  }
  if (x < 200) {
    speedX = 2;
  }
  fill(105, 235, 0);
  stroke(0, 0, 0);
  circle(y, 240, 30);
  y = y + speedY;
  if (y > 300) {
    speedY = -1;
  }
  if (x < 200) {
    speedY = 2;
  }
}

function mousePressed() {
  //マウスのボタンが押し下げられた時の処理
}

function mouseReleased() {
  //マウスのボタンが離された時の処理
}

function keyPressed() {
  if (key == "s") {
    saveCanvas();
  }
}

ファイル一覧

  • index.html
  • p5.min.js
  • p5.sound.min.js
  • sketch.js
  • style.css

ファイルを再アップロード


サムネイル画像を変更