Essay - Published: 2015.07.28 |
DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)
This example will show you how I built and displayed a P5.js sketch inside an Angular application. The application I built uses the standard Angular Route Provider to handle routing and one of the pages displays my P5.js sketch with the help of its controller.
Here’s an example of the sketch running on my site. The sketch itself is something I created using Processing last year before deciding I’d rather use P5 and switching over.
P5.js
P5.js is a JavaScript library that acts a lot like Processing. However, since it is JavaScript, you can run it in pretty much any browser, provided you’ve included the library and your sketch in the page.
The Sketch and Angular
Here are the pertinent files in gist form:
[[https://gist.github.com/SIRHAMY/146f9069ccbe951efb1d](https://gist.github.com/SIRHAMY/146f9069ccbe951efb1d)]Some things to notice:
Conclusion
P5.js looks like a great library with simple functions that allow you to completely alter your site/app. However, there isn’t that much community support from what I’ve seen. There are posts that explain some of the more technical things of the library, but there aren’t as many examples that actually show you how things have been done in the past. This is my attempt (probably one of many) to fill that void.
That being said, I would bet that this is not an optimal configuration for P5.js with Angular. But, as I said, there wasn’t much to go off of, so my main goal was simply to get it working – and I at least accomplished that.
I hope this was helpful. Let me know if you’ve created anything cool with P5.js and/or if you’ve found a better way to get your sketches online.
-Hamilton
The best way to support my work is to like / comment / share for the algorithm and subscribe for future updates.