Search code examples
jsfiddlep5.js

This JSFiddle is not loading p5.js correctly


This code I have written in my JSFiddle works well in my computer, and it creates a button and loads a sketch each time I press the button. I "loaded" p5.js, p5.dom.js via CDNJS cause p5.js is not available in the javascript frameworks and extensions options. But the behaviour is not being reproduced correctly. What is wrong with it?

Link: https://jsfiddle.net/truxx/uf7y9meq/5/

I tried:

<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.11/p5.js"></script>


<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.11/addons/p5.dom.js"></script>

Solution

  • You've got a few things going on here. First of all you should really fix your HTML. You've got mismatched and illegal tags all over the place. Please try to fix all of these problems, and properly format your HTML while you're at it.

    It also seems pretty strange that you're trying to mix instance and global mode. Why do you have a setup() and mousePressed() function outside of the sketch function, and another setup() function inside the sketch function? What do you expect that to do?

    To fix those problems, you need to choose either instance or global mode. This might require you to rewrite some of your code, but your goal should be to make everything consistent instead of using two different modes in one sketch.