First P5.js sketch

For Codevember, I wanted to try out P5.js – a very cool JavaScript library created by Lauren McCarthy and based on the principles of Processing. It’s actually very very similar to Processing, so it turned out to be quite easy to get used to! It’s a really cool and simple way to make interactive elements for your website.
Even so, I failed miserably at doing Codevember as I only made sketches for the first 5 days. Oh well. This was the first one and the one I like best (code below):

Nov1

function setup() {
createCanvas(1000, 500, WEBGL)
}

function draw() {
background(0);
basicMaterial(20);
translate(0, 0, -200)
rotateX(frameCount * 0.01);
rotateY(frameCount * 0.01);
torus(15, 2);
recur(13, 14, 40);
}

function mousePressed() {
var fs = fullscreen();
fullscreen(!fs);
}

function recur(b, s, col) {
if (b > 1) {
basicMaterial(col);
translate(0, 0, 20)
rotateX(frameCount * 0.01);
rotateY(frameCount * 0.01);
torus(s, 2);
recur(b – 1, s – 1, col + 20)
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s