Translating Processing classes to js classes

Hi all! Getting practice with p5js and translating Processing code into js. Struggling with this one in particular, especially the move() method. Does anyone mind giving me some pointers as to where it might not be working? I am just getting a stationary white dot, on a black background for now. Thank you!

class Spot {
  constructor() {
let x;
let y;
let speed;
let diameter;
let direction = 1;
  }
  display() {
    ellipse(spot.x, spot.y, spot.diameter, spot.diameter);
  }

  move(x, y, speed, height,  diameter, direction) {
//let x;
//let y;
//let speed;
//let diameter;
    direction = 1;
    y += speed * direction;
    if (y > height - diameter / 2 || y < diameter / 2) {
      direction *= -1;
    }
  }

  // Spot(xpos, ypos, dia, sp) {
  //   x = xpos;
  //   y = ypos;
  //   diameter = dia;
  //   speed = sp;
  // }
}

let spot = new Spot();

   function setup() {
 createCanvas(100, 100);
 noStroke();
 spot = new Spot(33, 50, 30, 1.5);
 console.log(spot);

  //sp = new Spot(33, 50, 30);

  spot.x = 33;
  spot.y = 50;
  spot.diameter = 30;
}

function draw() {
  spot.move();
  fill(0, 15);
  rect(0, 0, width, height);
  fill(255);

  //background(0);
  spot.display();
}

Answers

Sign In or Register to comment.