Uncaught Range Error: Maximum call stack size exceeded and Visualization problem

edited June 2017 in JavaScript Mode

Hi everyone,

I'm trying to import a .pde sketch on a webpage using processing.js. I've already done that in the past and everything worked pretty well. Now I'm experiencing a lot of troubles with this sketch:

/* @pjs preLoad="logoprocessing.png"; */

PImage img;
int cx, cy, d;
void setup(){

size(300,300);
cx=width/2;
cy=height/2;
d=min(cx,cy);
frameRate(2);
img = loadImage("logoprocessing.png");

}

void draw() {
background(256,256,256);

drawShape(cx,cy,d,int(random(15,30)));

imageMode(CENTER);
image(img,width/2,height/2);
redraw();

}

void drawShape(float px, float py, float md, int nbrVerts) {
float[] v = new float [nbrVerts];
for (int i=0; i< v.length; i++) {
v[i] = random (0, TWO_PI);
}
v = sort (v);
beginShape();
color X = color (#0C090A);
noStroke();
fill(X);
for (int i= 0; i<v.length;i++){
float len = random (80,md);
vertex(px+lencos(v[i]), py + lensin(v[i]));
}
endShape();
rectMode(CENTER);
fill(X);
noStroke();
rect(width/2,height/2,112,47);
}

It's like some recursion is causing problems or something...

Answers

  • Answer ✓

    You cannot call redraw from inside draw that will cause infinite recursion. Also there is no need since the draw method is executed about 60 times a second.

  • Omg it was that easy :)) thank you so much!

Sign In or Register to comment.