I don't know the reason of this error

hi. I want to make ‘matrix rain’ in p5js
but…

let symbols = [];
let symbolSize = 26;

function setup() {
  createCanvas(window.innerWidth, window.innerHeight);
  background(0);
  let x = 0;
  for (let i = 0; i <= width / symbolSize; i++) {
    let symbol = [];   
    
    symbol = new Symbol(x, random(-1000, 0));
    symbol.generateSymbols();
    symbols.push(symbol);
    x += symbolSize;
  }
  textSize(symbolSize);
}

function draw() {
  background(0, 150);
  symbols.forEach(function(symbol) {
    symbol.render();
  });
}

class Symbol {
  constructor(x, y, speed) {
    this.x = x;
    this.y = y;
    this.value='';
    this.speed = speed || random(5, 20);
    this.switchInterval = round(random(2, 20));
  }

  generateSymbols() {
    this.value = String.fromCharCode(
      0x30A0 + round(random(0, 96))
    );
  }

  render() {
    fill(0, 255, 70);
    text(this.value, this.x, this.y);
    this.rain();
    if (frameCount % this.switchInterval == 0) {
      this.generateSymbols();
    }
  }

  rain() {
    this.y = (this.y >= height) ? 0 : this.y += this.speed;
  }
}

symbol = new Symbol(x, random(-1000, 0));
Here is an error message in the code
Why? ㅜㅜ I don’t know the reason…

TypeError: Cannot read properties of undefined (reading ‘_report’)
at undefined:2:37105

Pleas help me~~

1 Like

https://xie-emily.com/generative_art/green_rain.html

1 Like

The number of parameters is wrong
You forgot speed

2 Likes

It must match the number of parameters that you have here

2 Likes

Hello @silverhee,

You did not format your code.

Please read:

I get these errors in the p5.js Web Editor:

Try changing the class name to something other than Symbols (I used Zymbols) and got the following:

There may have been a conflict with the name of the class you used:
Symbol.iterator - JavaScript | MDN

Keep at it!

:)

3 Likes