The P5JS editor is very laggy when it has to handle projects around 100 lines of code. And by “very”, I mean that the editor takes around a minute to run the code, and typing a character takes a few seconds for the character to appear in the editor.
My code so far is 95 lines, if you were wondering.
thanks, I think the problem is not editor in itself but the code is lagging. You have a lot of loops that slows down the process. I tried adding
console.log(frameRate())
to the draw function and set frameRate in setup to default 60. On my computer the result is around 4, which means it’s drawing 4 times per second although it was trying to draw at 60 because of the complexity of the code.
You have multiple directions from here - one is to accept it and every time you run a sketch, make sure to stop it (the stop button or ctrl+shift+enter) so the editor runs smoothly. Another direction is to optimize the code to make it run faster, but it requires a lot of work and I’m not even sure if this sketch can be optimized. One last suggestion may be to make the grid smaller (canvas size at 99x99 for example) while debugging to reduce the complexity, and once you are happy with the code you can try it at the original resolution (300x300).
it depends. it may handle a loop for 1000 times efficiently but it doesn’t mean it can also handle a loop with 1000000 times or 1000000000 times
I looked at your code and I guess you want to create a game of life, don’t you? If so, there are a couple of problems. The cells should be initialized in the setup function and not in draw. Also you need a “buffer” to save the last state. Dan made a great tutorial so it would be helpful: