jeudi 21 novembre 2019

p5.js cannot read random values of arrays

Hello!

I'm trying to make something in p5.js, and the program gets stuck when it tries to get a random value of array. Here is a simple program I made to demonstrate:

var arr = [100, 200];
var a;

function setup() {
  createCanvas(400, 400);
  a = random(0, 1);
}

function draw() {
  background(220);
  ellipse(arr[a], 20, 20, 20);
}

The program returns a message saying that the ellipse function wanted a number, but got a variable. It works if say arr[0] or arr[1], but not arr[a].

I'm using the p5.js Web Editor. I have no idea why this is happening. If you have a solution, please respond. Thanks!




Aucun commentaire:

Enregistrer un commentaire