Cant figure this out/help with code ASAP

Hello, I need Help with some code, I want The record to move around freely on the canvas and go to a random x and y and repeat constantly. is there a way I can do this? here is the link to y project

https://editor.p5js.org/astromdahl01/sketches/81BgndIS5

Hi @Astromdahl01 ,

Welcome to the forum! :wink:

The p5js reference is very good, you should take a look at it :

https://p5js.org/reference/

You talked about randomness so this is for you :

Then it’s just a matter of using random values to display your circles randomly and use the draw() function to constantly change that!

Hi @josephh I’ve looked at Radnomd() and it was somewhat helpful. when I try and enter random on line 27 or create a line that says: x = random(width) and both times it made multiple records, I just want one record that jumps around and random locations. Thanks for the response!

Ok so you want one record that moves at random locations each time but in your code you are creating them inside a for loop (with the number of records) :

for(var b=0;b<numrows;b++) {
  let newRecord = new vinyl(x, y);
  records.push(newRecord);
}

So you still want to keep that?

Also the way you are defining your “vinyl” class is not really the right way to do it in JavaScript.
If you want to keep that functional style, you should use Object prototypes for that :

// Constructor
function Vinyl(x, y) {
  this.x = x;
  this.y = y;
}

Vinyl.prototype.display = function() {
  // Display
}

// Create a new vinyl
const vinyl = new Vinyl(500, 200);
vinyl.display();

Now since ES5, you can use more standard OOP syntax to declare a class (see the MDN doc about that, it’s roughly equivalent, it’s a syntactic sugar) :

class Vinyl {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }

  display() {
    // ...
  }
}

Also note that most often in programming, classes names have the first letter uppercase (PascalCase).