Slow render in WebGL

Hey, I want to make a terrain generator in p5. So, I need WebGL to rotate the canvas on X axis. But, even trying to render 500 lines makes the whole sketch extremely slow. If I remove the WEBGL, the sketch runs pretty fast. Can someone please help?

let l = []

function setup() {
  	createCanvas(windowWidth, windowHeight, WEBGL);
  	for(let i=0; i<500; i++){
  		l.push([random(width), random(height)])

function draw() {
    //WebGL translates everything to the middle of the screen. This is to fix that
	translate(-width, -height)
    // I want the shape to follow my mouse
	translate(mouseX, mouseY)

	for (i of l){
		vertex(i[0], i[1])
		ellipse(i[0], i[1], 10, 10)

Not sure about ellipse statement within beginShape

You can make the full PShape in setup and in draw just say shape(s);


Examples here:

I did get a steady frameRate of 60 when I changed the scale.


I could not find a PShape reference for P5.js



1 Like

Since you are not changing data in draw(), construct a p5.Graphics with createGraphics() in setup() and move the resulting image() in draw().