We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to create my own instances of the p5 "class". If I go to https://p5js.org/reference/ , open the JS console and type p5, I get the 3-argument function. But if I include p5.min.js into my own page, open the JS console, and type p5, I get an undefined variable error.
I'm very likely missing something simple...
Answers
Okay I tried the empty-example bundled with p5 and it works. So I guess I need to be more specific here...
I'm actually trying to include p5.js into a Jupyter notebook.
I'm using the following Julia code to do that:
HTML("""<script language="javascript" type="text/javascript">"""*readstring("libraries/p5.js")*"""</script>""")
It basically inserts the HTML snippet
<script ...> contents of p5.js </script>
into the page. It's only in this case that I can't access the p5 function. I tried inserting<script ...> contents of p5.js; alert('it works')</script>
just to make sure the JavaScript does get inserted, and sure enough I do get the alert box.This is the only way one can include external libraries into Jupyter notebooks I think. Apart from including
<script src="..."></script>
where src points to a publicly hosted file. Which I did try, and the problem still persists.I'll be very happy to help anyone set up a Jupyter notebook with Julia if you want to help debug this. juliabox.com has done most of the work for us.
<script src=http://p5js.org/assets/js/p5.min.js></script>
p5.MyClass = class {}
.This is not quite working in my case.
I found a minimal way to reproduce the problem I'm trying to solve:
<head>
and<body>
tagsdocument.body.innerHTML = '<script src="http://p5js.org/assets/js/p5.min.js"></script>';
p5
to try and access the p5 constructor. (it doesn't work...)http://StackOverflow.com/a/19737116