Hi Everyone,
Today I am introducing p5.js.
For those Javascript developers who don’t know p5.js, it’s basically an abstraction library for Canvas.
(starts drawing lines on grey space.)
If you do any basic 2D Canvas interactions, p5.js makes it very simple.
(points at script, then scribbles on grey space.)
Look at this here, it’s like, ten lines or so, and you have drawing going on. Doing this in a normal canvas without this abstraction is not fun. It just takes a long time.
(selects Particle System, a starburst pattern repeats itself)
So let’s just check out a couple of examples really quickly. Let’s check out this particle system here. Cool! That’s cool.
I learned about p5.js because it is based on processing. Processing is originally in Java, and it allows you to play around with Java essentially. It incorporates a really easy visualization layer. I learned about it back in the day at the Academy of Art, when we had a section on generative art.
If I ever retire completely, I will probably become some sort of generative artist using code.
(selects Multiple Particle Systems, the Particle System pattern repeats itself)
So let’s see here. Multiple Particle Systems! So that’s kind of neat. There is a lot of different things you can do. Imagine you put a background image off of say, your webcam in here and then you can add things and then you click a button and it saves it out. Or something like that, you know. There are a lot of possibilities.
(selects the Mandelbrot Set, a basic fractal appears)
Pretty cool. Pretty cool.
(selects Snowflakes, a red background appears with white cascading snowflake pattern)
We have snowflakes? Like, that’s awesome. That’s really great. I really enjoy the artistic aspect of coding. You know, it’s really nice when you can just create without having to worry about certain specs or the budget.
(switches back to directory page, then brings up code for Collision detection in another window.)
Anyways, to get you started with p5.js, a long time ago I built a collision detection library here. Just basic ball bouncing. You know there’s the Hello World for most coding programs when you are learning. This ball bouncing is basically to me the Hello World of animation.
So, a hundred lines, it’s es5. It’s old, but you’ll learn it.
(plays Ball Bounce Script)
And in it, if we go over here for the ball bounce script…Let’s check it out. This p5.js has fantastic FPS. I actually tried to import this over to C++, so I could end up learning web assembly and I found out I really enjoy Javascript more so than C++, because in doing so I really hit less performance.
I think it was either using vectors in C++ under the hood or just not performing in the way that I was trying to convert it, or the actual 2D rendering library was not optimized. There was actually a bug in that, in Github, issues we fixed.
So yeah, this is the script. You can check it out. If you just want to learn a bit about p5.js, it’s a good little intro, and I have a two-step, two-stage on this, so I originally learned this and I thought alright, let me take up the complexity a little bit, and I will demo that video next video after this.
So check it out, p5.js. Generative art. Have a good day everybody. Bye.