February 8th, 2025 by Isaac Cheaz
Prof: J.H. Moon
p5.js embed of the sketch
For this mini project, we were tasked to code a self-portrait of ourselves and be as creative as possible. For mine, I used the selfie I took on Halloween, wearing a sloth onesie, and coded the face part of it.
process:
finding a reference:
I first had to find a reference to take inspiration from. This was the base of the mini project, a photo that defined myself and was simple enough to deconstruct into simple shapes to codify into P5.js. Scrolling through my gallery, a selfie of me wearing a onesie caught my attention and I decided right away that I wanted to turn that into a self portrait, or the reference for my first mini project.
2. sketching it on paper into simple shapes
Now, coding the picture and all of its details would be too time consuming and difficult at my level of P5.js. So on paper, I drew the selfie and broke it down into simple shapes. E.g. squares, circles, rectangles, semi-circles, ovals.ย
Final Sketch
First attempt
3. coding it!
The final section of the process was coding it. Since P5.js was awfully similar to Processing and I had learnt it previously on Interaction Lab, coding it was fairly easy. Although I have to admit that I needed some refreshers for some of the shape's parameters. The only tedious part of coding was the coordinates, it required a lot of mental math and imagination...
function setup() {
ย createCanvas(500, 500);
ย background(255, 218, 115);
}
function draw() {
ย noStroke();
ย fill(150, 75, 0);
ย arc(250, 220, 200, 270, 0, PI+PI);
ย triangle((width/4)+20,height-150, (width/4)+100, height-150, (width/4)+25, (height/2)-17)
ย ย triangle((width/2)+30,height-150, (width/2)+110, height-150, (width/2)+100, (height/2)-17)
ย fill(255, 253, 208);
ย circle(250,250,140);
ย rect(180,175,140,70,10);
ย rect(215,175, 70, 175, 5);
ย fill(0);
ย arc(250, 200, 145, 170, PI, 0);
ย fill(255, 253, 208);
ย triangle(230, 200, 270, 200, 250, 150);
ย fill(255);
ย arc(250, 150, 160,100, PI, 0)
ย beginShape();
ย vertex(180, 350);
ย vertex(160, 350);
ย vertex(170, 150);
ย vertex(190, 150);
ย endShape();
ย beginShape();
ย vertex(320, 350);
ย vertex(340, 350);
ย vertex(330, 150);
ย vertex(310, 150);
ย endShape();
ย fill(0);
ย arc(250, 110, 75,50, PI, 0)
ย circle(205,103,10);
ย circle(295,103,10);
ย stroke(0);
ย beginShape(LINES);
ย vertex(205,120);
ย vertex(235,130);
ย vertex(235,130);
ย vertex(265,130);
ย vertex(265,130);
ย vertex(295,120);
ย endShape();
ย fill(66, 37, 25);
ย rect(190,195,45,10);
ย rect(265,195,45,10);
ย fill(255, 253, 208);
ย circle(217,230,45);
ย circle(283,230,45);
ย fill(255);
ย circle(217,230,25);
ย circle(283,230,25);
ย fill(0);
ย circle(219,227,15);
ย circle(285,227,15);
ย beginShape(LINES);
ย vertex(305,227);
ย vertex(315,227);
ย vertex(195,227);
ย vertex(185,227);
ย vertex(240,227);
ย vertex(260,227);
ย endShape();
ย noStroke();
ย beginShape();
ย vertex(225,280);
ย vertex(275,280);
ย vertex(270,290);
ย vertex(230,290);
ย endShape();
ย fill(255, 135, 102);
ย triangle(250,240,240,265,260,265);
}
The code doesn't exactly have to be broken down into snippets. In short, everything inside "function draw()" generates shapes that come together into the self-portrait. While on the other hand, everything inside "function setup()" sets up the canvas for the shapes (the background color and canva size).
redundant sections
before
after
This is probably the only part of the code that could be "smoothened" out. I started using width and height variables since I saw Professor Moon using in class. However, I found it challenging to do operations with the variables other than divide, since I needed to use parenthesis. So for the rest of the code I stopped using width and height and instead wrote the exact coordinate.
takeaways
There wasn't much to learn since I've already played around with Processing and we all know how similar it is to P5.js. However, I didn't touch a lot of nuance shapes such as vertexes and arcs so that was something new. I also learned that its important to plan the layers and which shapes need strokes and which don't.ย LA Alex gave the suggestion of using "stroke()" in specific sections of the code in order to not mess up the layers of the shapes. In short, a lot of the fundamentals were easy since I have experience from previous classes, but some tedious problems occurred so I had to carefully find a solution for each one.