Week 1: Self Portrait

Concept

For my self portrait I wanted something that represented a few aspects of my personality in ways that I don’t normally think about them. I tried to think of puns/inside jokes within my life that would add to the self portrait both visually and conceptually. I also knew that I wanted to add some interactive component/movement in the portrait but was unsure as to what exactly I wanted when I got started.

Components

To walk you through some of these components lets starts with the most obvious, the color changing background and sun-emoji mouse. I am a visiting student from New York, and have spent the last 10 years in Harlem, NYC but am originally from Florida. Florida is often referred to as “the Sunshine State” and although I consider myself a New Yorker, still believe that being born there is important to who I am. I found implementing the color tracking background components and sunshine mouse to be relatively simple but spent a lot of time working on this piece because of the color theory aspect. I had a very difficult time match the colors of the background to a “Floridian sunrise” but ended up on settling with this blue (representing night) to orange (daytime) transition.

let c = color(mouseX-200, 100, 100);
  background(c);
//sun
 textSize(48);
 text("☀️", mouseX, mouseY);

An aspect I am proud of

Another component I would like to highlight is the camera/flash feature. A big hobby of mine if film photography so I thought I’d add in a little camera around my neck to capture some beautiful scenery. I added the flash mainly because I wanted something interactive but also thought of it as a joke because I am quite bad at taking photos with flash. Although this code is also quite simple, it is what I would like to highlight as what I am particularly proud of because I had quite a bit of difficulty trying to get it to work. I was having a lot of trouble distinguishing the uses between mousePressed(), mouseClicked(), and mouseIsPressed() but ended up solving the problem by finding a tutorial on the click-event feature.

//camera flash
  if (mouseIsPressed){
    //referenced vidianindhita's tutorial
    noStroke();
    fill('white');
    ellipse(380, 550, 50, 50);
  }

My final product

Reflection

All in all, I really enjoyed this assignment and was excited to work with something new. I found manipulating the shapes to make different images more difficult than I expected it to be and enjoyed the challenge of trying to figure out what shapes could make what facial features. In the future, I would like to fix the color issue with the sunrise because I think it is a super cool feature that just needs a bit of tinkering. I’d also like to try and figure out what other dynamic pieces I could add. For instance maybe moving clouds or a sun that rises on it’s own without the mouse. Also, I did attempt to track my pupils onto the mouse within the parameters of the whites of my eyes but didn’t make much progress so hopefully I can figure that out too.

Week 1- Music: The Remedy

I have always considered music to be an essential part of my life. Whenever I want to get something done or need to lift my mood, I turn to music. So, for the self-portrait assignment, I decided to design a portrait that interacts with music. The life and happiness of my portrait depend on music: when there is no music, it reflects a very bad mood, and the heart stops beating. I used different shapes to draw the portrait, but drawing the heart was particularly challenging. Initially, I tried using the Heart equation, but it was difficult. Fortunately, I found an easier method online. To make the portrait react to music, I used p5.AudioIn to capture my computer’s microphone input, which I then used to alter parts of the portrait as the amplitude changes. If the user presses the mouse, the background color changes to simulate disco lights. The final design is decent but still needs some improvements.  

NOTE: Seems like I can’t use the mic on WordPress. Run the code on the P5 editor

The following part of the code is interesting but challenging to implement. To create the disco light effect, I needed to incorporate a time delay. Unfortunately, I couldn’t find a direct way to implement the delay. After some research, I discovered that I could use frameCount to achieve the delay and, consequently, the disco lights.

//function to turn on the disco light (One second cycle)
function discoLight() {
  let level = map(mic.getLevel(), 0, 1, 50, 255);

  if (frameCount % 60 < 10) {
    background(level, 0, 0);
  } else if (frameCount % 60 < 20) {
    background(0, level, 0);
  } else if (frameCount % 60 < 30) {
    background(0, 0, level);
  } else if (frameCount % 60 < 40) {
    background(level,0 , level);
  }
  else if (frameCount % 60 < 50) {
    background(0, level, level);
  }
  else if (frameCount % 60 < 60) {
    background(level, level, level);
  }
}

Overall, working with p5 has been an interesting learning experience. I faced some challenges, especially with the coordinate system. I was so used to working with the standard coordinate system, so adjusting to the inverted system was somewhat difficult. However, I believe that with time, I will overcome these challenges. The portrait may require further enhancements: future work might involve analyzing the sound so that the mouth moves when someone sings or talks, instead of merely reacting to the beat. Since some parts move relative to the music level and I haven’t tested the code with very loud sounds, I’m concerned that certain elements might move further than expected, causing disorientation of the entire portrait. To address this, I plan to map the sound input so that everything works smoothly regardless of the amplitude. Additionally, another improvement could be ensuring that every part of the portrait remains proportional to the whole. This way, whenever I change one element, the entire portrait adjusts accordingly without becoming disoriented.

Assignment 1. Self-Portrait

For my first assignment, I decided to start with the basic shapes to make sure that I was comfortable with the foundations. I did not want to be too meticulous about the details; rather, I used my imagination and spatial thinking to draw fun yet precise face features that would properly display what game/social media avatars usually do.

Basic shapes – the avatar itself.

In the first stage of my work, I created a head, eyes, eyeballs, ears, and nose using straightforward ellipse() and circle() commands. I searched the Web for the most real-looking skin color RGB code and used it.

The next step was to find out the way to draw mouth, eyebrows, and hair. Again, I wanted my sketch to be similar to the real person’s features, so I decided to spend more time searching for proper code options. Looking at the examples from the past students’ work and watching the videos from The Coding Train helped me to get the idea of using arc() and quad() functions. The lesson that I learned from using these two functions is that you should be very precise with values and pay attention to details, otherwise you might mess up the drawing. It is especially important to learn how PI values work.

Moving on to the torso and the tank top, I used a little trick to visually separate the head and make it look like the neck (thanks to the arc() function that I had just learned).  I used rect() and ellipse() to create the torso and then used triangle() to visually separate the body from the arms.  Inspired by one of the works from previous years I also decided to add sunglasses and create a shape similar to the sunglasses that I usually wear using arc(), and use Alpha value  fill() to make my eyes still visible through the lenses.

Background and animations.

To add more entertainment to my self-portrait, I first decided to add some interactivity. As I had just learned about random() and mouseClicked(), I decided to combine them to make the top tank color change with every click. Next, I created the background using rectangular shapes – the beach, the sea, and the sky. I searched for the most realistic RGB color codes, and I think colors look pretty good.

Lastly, I decided to challenge myself a little bit by trying to implement techniques I used in Python here in p5.js. To catch up with the syntax differences, I watched a couple of YouTube videos and searched the Reference on the p5.js website. The thing I am most proud of is the sun movements that I implemented using a Bezier curve. First, I drew the sun’s movement trajectory using bezier(), and then I followed the instructions written in the Reference to use bezierPoint() and make the sun move back and forth. This is a part of the code I am the most proud of.

//Curve for Sun Movement
x1 = 0
x2 = 100
x3 = 300
x4 = 400
y1 = 150
y2 = 0
y3 = 0
y4 = 150
noFill()
 

let x = bezierPoint(x1, x2, x3, x4, t)
let y = bezierPoint(y1, y2, y3, y4, t)

t += 0.001 * move_sun_dir //regulating the speed of the sun
if (t > 1 || t < 0) {
  move_sun_dir *= -1
} //not letting the sun to go away from the screen
  


//Sun
fill(255,255,112)
noStroke()
circle(x, y, 50)



//Beach
fill(255, 234, 200)
noStroke()
rect(200, 400, 400, 200)

//Sea
fill(0, 105, 148)
noStroke()
rectMode(CORNER)
rect(0, 280, 400, sea_level)

sea_level += 0.05 * move_sea_dir //regulating the speed of the sea level

if (sea_level > 40) {
  move_sea_dir = -1;
} 

else if (sea_level < 30) {
  move_sea_dir = 1;
} // keeping the sea level between the rectangle size values

As you might notice, just for the fun of it, I decided to use a similar coding technique to make the sea level rise and fall (in fact it is just the size of the rectangle that changes :)).

Conclusion.

I enjoyed working on my self-portrait, and I am satisfied with the result. I created a nice-looking sketch and already started to integrate some animations and interactivity into my work. Of course, there is tons to learn, and my self-portrait could be even more advanced. I was thinking of adding moving clouds to the sky, drawing palm trees on the beach, or adding ships going back and forth in the sea. I could add many more details, and I am looking forward to learning new tools and features to implement it. The coolest thing that I wanted to add but couldn’t is the change between day and night. As I made the sun move, I realized that it would look awesome if the brightness dimmed every time the sun went down, and vice-versa. I could also add the moon and the stars at night, and make them disappear in the morning.

Overall, this assignment was a great start to my journey in Interactive Media, and I can’t wait to see where this journey will lead me.

 The Whole Code:

let r, g, b;
let t = 0;
let move_sun_dir = 1;
let move_sea_dir = 1;
let sea_level = 30;

function setup() {
  createCanvas(400, 400);
  r = random(255)
  g = random(255)
  b = random(255);
}

function draw() {
  background(135, 206, 235);
  
  
  //Curve for Sun Movement
  x1 = 0
  x2 = 100
  x3 = 300
  x4 = 400
  y1 = 150
  y2 = 0
  y3 = 0
  y4 = 150
  noFill()
 
  
  let x = bezierPoint(x1, x2, x3, x4, t)
  let y = bezierPoint(y1, y2, y3, y4, t)
  
  t += 0.001 * move_sun_dir //regulating the speed of the sun
  if (t > 1 || t < 0) {
    move_sun_dir *= -1
  } //not letting the sun to go away from the screen
    
  
  
  //Sun
  fill(255,255,112)
  noStroke()
  circle(x, y, 50)

  
  
  //Beach
  fill(255, 234, 200)
  noStroke()
  rect(200, 400, 400, 200)
  
  //Sea
  fill(0, 105, 148)
  noStroke()
  rectMode(CORNER)
  rect(0, 280, 400, sea_level)
  
  sea_level += 0.05 * move_sea_dir //regulating the speed of the sea level
  
  if (sea_level > 40) {
    move_sea_dir = -1;
  } 
  
  else if (sea_level < 30) {
    move_sea_dir = 1;
  } // keeping the sea level between the rectangle size values
  
  
  // Head
  fill(255,205,148)
  noStroke()
  ellipse(200, 200, 120, 150);
  
  // Eyes
  fill('white')
  circle(175, 185, 15);
  circle(225, 185, 15);
  
  //Eyeballs
  fill('black')
  circle(175, 185, 5);
  circle(225, 185, 5);
  
  //Mouth
  fill('white')
  stroke('rgb(255,189,201)')
  strokeWeight(4)
  arc(200, 235, 35, 25, 0, PI, CHORD);
  
  //Nose
  fill(224,172,105)
  noStroke()
  ellipse(200, 210, 10, 20);
  
  //Ears
  fill(255,205,148)
  ellipse(140, 190, 20, 30);
  ellipse(260, 190, 20, 30);
  
  //Side Hair
  fill('black')
  quad(145, 145, 165, 150, 160, 185, 145, 180);
  quad(248, 140, 235, 145, 240, 185, 257, 180);
  
  //Top Hair
  fill('black')
  ellipse(width / 2 - 5, 135, 110, 50);
  
  //Eyebrows
  noFill()
  stroke('black')
  arc(175, 180, 16, 16, PI + 0.6, TWO_PI - 0.5)
  arc(225, 180, 16, 16, PI + 0.6, TWO_PI - 0.5)
  
  //Tank top and Torso
  noStroke()
  fill(255,205,148)
  ellipse(150, 370, 100, 200)
  ellipse(250, 370, 100, 200);
  
  rectMode(CENTER)
  fill(r, g, b)
  rect(200, 370, 115, 200);
  
  stroke(255, 234, 200)
  strokeWeight(5)
  triangle(137, 400, 140, 325, 140, 400)
  triangle(260, 400, 260, 325, 263, 400)
  
  //Neck
  noStroke()
  fill(255,205,148)
  arc(200, 270, 50, 50, 0, PI, CHORD);
  
  //SunGlasses
  fill(0, 0, 0, 100)
  stroke('black')
  strokeWeight(0.2)
  arc(175, 178, 22, 37, 0, PI, CHORD)
  arc(225, 178, 22, 37, 0, PI, CHORD)
  strokeWeight(2)
  line(143, 175, 164, 185)
  line(236, 185, 257, 175)
  line(186, 185, 214, 185)
  
}

// Changing color of the tank top
function mouseClicked() { 
  r = random(255)
  g = random(255)
  b = random(255)

}


Week 1: My Portrait (The smoker)

Background
As I was learning how to draw using P5.js, I initially experimented by arranging shapes and figures randomly.
I found myself drawing a robotic face because it was easy to arrange boxes and shapes, even if they didn’t resemble a familiar human face. As I became more comfortable with using various shapes and gained an understanding the coordinate system, thanks to the detailed references on the P5.js website, I wanted to create something more human-like. I started by sketching a simple drawing (below) of a man wearing a tie in my notebook.

I managed to complete the drawing in P5.js  and it appeared better than I expected. I also added some features including dynamic objects and mouse inputs. However, I was not fully pleased with ‘my almost portrait’ as I did not like how the lower part turned out. I faced challenges in filling  the colours  on the lower body and arms because my drawing had a lot of independently connected lines as seen below. So I wanted to make the lower part look better.

My Final Portrait
Despite the fact that I was very impressed with how my portrait had turned, I did not like the fact that everything below the head had to remain with the background colour.
So I decided to come up with a simpler design by changing the lower body and adding a neck and a small chain and I could now colour it different from my background.
I had added some a Moon and Sun emoji which simultaneously passed indicating day and night. I set some offsets for the smoke from the man’s cigarette so it appears to ascend upwards.
Lastly but not least, I was curious to explore  mouse input functions, so I added blinking on pressing the mouse.
My final Portrait can be seen below:

Achievements I am most proud of

I have managed to learn so much in such a simple assignment.  One achievement I am most proud of is how I managed to add some dynamic objects and features in my portrait. One of them being the moving smoke, where I added some offset to move the smoke upwards and some ‘Shake’ variable to make the smoke shaking as it ascends. Below is the code for that:

// Drawing Ciagerette tip 
circle(220, 375, 10);
// Drawing Cigarette smoke 
fill(12, 12, 12);
// Used this shape/Curve from (https://p5js.org/examples/repetition-bezier/)
bezier(220, 375, 200, 350, 250, 320, 230, 300);
bezier(222, 380, 210, 355, 260, 330, 240, 310);
noFill();
// Adding Movable smoke to make it dynamic
fill(fade, fade, fade)
bezier(220+shake, 375+Smokeoffset, 200-shake, 350+Smokeoffset, 250+shake, 320+Smokeoffset, 230-shake, 300+Smokeoffset);
bezier(222+shake, 380+Smokeoffset, 210-shake, 355+Smokeoffset, 260+shake, 330+Smokeoffset, 240-shake, 310+Smokeoffset);
noFill();

Reflections and ideas for future works

Creating a portrait has  been a very nice assignment. I have gained understanding on working with P5.js. I have also experiences the importance of properly commenting my code as it was easier to navigate the code and see what to improve, which could have been very difficult without proper comments.
For future, I would love to add more functionality and make use of many other  features that I was not able to use in this assignment such as the 3D objects, loading images, rotation and many other.

 

Week 1: Self – Portrait

My Concept:

As the first assignment, I thought to keep things simple but also to add some personality into it. The background is a beach. One thing about me is that I absolutely cannot tolerate the beach – it is one of those outings I just cannot stand and enjoy. So as I started to create this piece, I thought to implement that (which is why I look so unhappy haha)

In terms of code, I decided to include some user interactivity. If you do click on me, then I end up blushing for as long as you press on the mouse.  I was quite happy with this part of the code because it took me some time to decide on what particular user interactivity I wanted.

// BLUSH
if (mouseIsPressed) {
  fill('pink');
  ellipse(460, 400, 40, 40); // blush on the right cheek
  ellipse(300, 400, 40, 40); // blush on the left cheek
}

Reflection:

This first assignment was quite an enjoyable one, because I liked getting the opportunity make something both creative and having a technical element into it. I suppose the most time consuming thing was editing the circles for the eyes and pupils, deciding where exactly they go and their sizes. I think this assignment helped me to have a solid understanding in how p5.js operates. I had hit a wall when I was drawing the hair on the character. It just looked awkward, especially as there was none present at the forehead, hence I decided to give her a fringe. If I had another opportunity, perhaps I would elevate the work by adding facial expressions and adding some text.

Week 1 – Self-Portrait: The Sword of Damocles

Intro

Sometimes I wonder if there is indeed some force behind coincidence – especially when those coincidences are of my favorability.

Right before I set off for my adventurous journey to Abu Dhabi, I visited an exhibition in Shanghai, in which a collection of portraits and self-portraits were borrowed from Centre Pompidou. From those who devoted their efforts to whether capture the subject faithfully or replicate their physical appearance to those who indulged their artistic preference, streaks of character, habits, and egos into the paints, the portraits collectively reminded me of that recurrent theme in every art form, I presume – the tension between the art and the artist. Aside from the cliche saying from Oscar Wild (although his definitive statement is, even for an ambivalent person like I am, attractive enough), I would stick to leaving the answer for now.

On the other hand, even if I cannot answer the big question for now (and, in fact, it could be forever), I can indeed establish a bit of myself under this daunting siding game. One of my takeaways from my first acting class today is that as a narrator, despite our habits of storytelling and the eventual manner we picked, it is our responsibility to Stay True in terms of this present moment, the soul of our story. I’ll not delve into the other takeaway of being courageous to leave others the right to tell our stories for now but make use of the first one promptly.

That being said, when it comes to composing my own self-portrait, which I’ve never tried, I’d be glad to take full responsibility for representing myself at this moment. To me, this is something that demands great courage as well. Looking back at how I could probably gain this courage, I’d say it’s the fact that I, at the end of the day, tried to admit the lack of it for so many years – from representing myself, playing music, to speaking up when I’d love to, dealing with interpersonal relationships, and to live and love, had brought me that serenity and tranquility to seeking for courage. It seems for many of us, at least many people I know, as soon as the concept of being courageous and brave was instilled into our heads, we started to self-exert as well as receive external expectations to “be courageous and brave” right away. And simply, it is impossible. It is impossible to develop that true courage and bravery by merely being told how a courageous person would possibly behave instead of honing oneself step by step and again and again in this world of reality.

Product Concept

Despite my rationale (or more of like my self-prep talk), it’s time to tackle the problem (if not the question), and I’ll try to put it as plainly as possible. At this moment, I’d be willing to conceptualize myself into a set of symbols, figures, or whatever you may call some figurative representations that could be found in real life. Although I could make a list of the symbols I’m about to include in this portrait right here, I’d like to leave it till the end and see if my conceptualization and abstraction make sense to you.

Nevertheless, the overall concept is MEs versus an ideological black hole that I’ve found as the Sword of Damocles in my life. That being said, whenever the mouse is pressed, my hovering incarnations in this blended world of 2D and 3D shapes will initiate their attack toward the black hole despite their shaky, timid, and hyped state, setting off on a journey with no way back.

Technically speaking, my using 2D shapes as my personal representatives while letting the black hole be 3D results from the simple attempt to utilize both 2D and 3D drawing/shaping functions somewhere around this project (plus, it would be quite time-consuming if I used basic 3D shapes to abstract the symbols I’d like to include). However, I can indeed also justify this choice in terms of its symbolic connotation. To reflect the nature of this colossal hazard, bain of insecurity, and ineffable abyss that lies completely out of my mortal control, I placed the threat one dimension higher than myself.

Metaphorically, MEs’ attacking the black hole embodies the courage I’d like to attain despite what comes next. As for the ending of this one-act play, maybe it’s MEs’ begone from this world? Or maybe it’s MEs entering a brand-new universe. At least if the black hole could be gone from this particular universe, it would be a happy ending for both me and the rest.

coding highlight

Despite the fact that I was not familiar with js, I would self-reckon as someone who is used to product-oriented coding; in other words, I tried to utilize as much as possible at this moment from the source to get to my ideal product as closely as possible. Although, from time to time, this mindset could lead me to a hasty organization and poor-looking codes, I do believe it’s beneficial for me to realize (at least part of) my vision quickly.

In this product, I took the black hole as a starting point. While calling the function shpere() is rather an easy deal, it did take me some time to figure out how to maintain both 2D and 3D shapes on the same canvas. The answer turned out to be using push()/pop() to create an individual drawing group. Another takeaway is the general approach to creating animation with p5js – thinking from a perspective of frame generation, specifying the animation frame by frame. And this led me to use variables to store the current status and then update the variables to achieve animation (see the usage of rotateX()/rotateY()). On top of that, to add texture() to the sphere, I tried with loadImage() in the preload() function (and thus used an image as the background as well).

*: all image files used in this project are generated with DALL-E3

// draw the sphere with texture
function blackhole() {
  // Increment the rotation angles
  angleXrotate += 0.005; // Adjust the speed by changing this value
  angleYrotate += 0.005; // Adjust the speed by changing this value

  push(); // save the current state
  
  translate(0, -200, 0); // translate the coordinate system temporarily to place the sphere
  
  rotateX(angleXrotate); // Rotate around X-axis
  rotateY(angleYrotate); // Rotate around Y-axis
  
  texture(imgBlackhole); // adding texture to the sphere
  
  stroke('white'); // contour the sphere
  strokeWeight(0.25);
  
  sphere(100); // placing the sphere on the canvas with r = 100
  
  pop(); // return to the previous state

}
let imgBlackhole; // variable to hold image texture for the sphere
let imgUniverse; // variable to hold image for the background

function preload() {
  // load image files
  imgBlackhole = loadImage('blackhole.jpg');
  imgUniverse = loadImage('the universe.jpg');
}

As for the ME representatives, I break it down into two parts: the static drawing and the animation. Initially, I adopted the animation approach mentioned in the black hole section, only used functions to hold the drawing operations and called them in the draw() function. However, as my drawings are rather complex (although they have abstract appearances), I found that the code performance had started to decline. Therefore, I reorganized the code by placing the drawings into p5.Graphics object (that provides a dedicated drawing surface), in order to improve efficiency. This also enabled me to process the objects individually as a whole later on. Following is one example of my utilizing p5.Graphics object to draw an abstract guitar.

function drawGuitar() {
  let c = color('#bd6d36');
  let c1 = color('#592c0e');
  let c2 = color('#814116');
  
  // Create a graphics object guitar
  guitar = createGraphics(100, 150);

  // Draw to the graphics object guitar
  // Body of the guitar
  guitar.fill(c); // Brown color
  guitar.noStroke()
  guitar.beginShape();
  guitar.vertex(25, 100); // Start at bottom left
  guitar.bezierVertex(10, 75, 10, 50, 25, 25); // Left curve
  guitar.bezierVertex(75, 0, 75, 50, 25, 25); // Right curve
  guitar.bezierVertex(90, 50, 90, 75, 25, 100); // Bottom curve
  guitar.endShape(CLOSE);

  // Neck of the guitar
  guitar.fill(c2); // Mid-dark brown color
  guitar.rect(25, 5, 8, 80); // Neck
  
  // Sound hole
  guitar.fill(c1); // Dark sound hole
  guitar.ellipse(25, 50, 10, 25); // Draw sound hole

  // Strings
  guitar.stroke('white'); // White color for strings
  guitar.strokeWeight(1);
  for (let i = 0; i < 6; i++) {
    guitar.line(25 + 2 * i, 0, 25 + 2 * i, 60); // Draw strings
  }
  
}

That being said, as I started working on the animation for MEs, p5.Graphics objects made it easier for me to instantiate them in class in order to define different behaviors (aka. hovering around the mouse and attacking the black hole). While I will not delve into every function I wrote for the MEs, I would like to briefly outline its operation logic. As the centerpiece, a class called Hoveringme includes six variables as parameters and two methods. The X/Y variables are used to track the relative coordinate of the object to the mouse and its absolute coordinate on the canvas. The show() method is my version of the draw() function for this particular class and will be called in the draw() function in every frame. The attack() method only updates the instance status (whether it’s ‘hovering’ or ‘attacking’), which, as a condition, determines the exact operation in the show() method.

// the hovering MEs' class
class Hoveringme {
  constructor(relativeX, relativeY, shape, status) {
    this.relativeX = relativeX;
    this.relativeY = relativeY;
    this.shape = shape;
    this.status = 'hovering';
    this.displayedX = 0
    this.displayedY = 0;
  }
  
  // show the MEs
  show() {
    push();
    /*
    ...
    */
    pop();
    
  }
  
  // ME to attack the blackhole
  attack() {
    this.status = 'attacking';
    
  }
  
}

Just to add a bit about my animations, which are broken down into two statuses as mentioned. First, the hovering status includes random() in the coordinates added on mouseX/Y

if (this.status === 'hovering') {
      // Update the ME's position around the mouse
      this.displayedX = mouseX + this.relativeX + random(-10, 10) * 0.05; 
      this.displayedY = mouseY + this.relativeY + random(-10, 10) * 0.05; 
      
    }

On the other hand, to achieve the attacking effect, the mouseX/Y has to be excluded (otherwise, the translation/movement of the object will always be relative to the mouse’s position).

else if (this.status === 'attacking') {
      let spherePosition = createVector(0, -200, 0); // Sphere's position
      let targetX = spherePosition.x + width / 2; // Sphere's X position in 2D
      let targetY = spherePosition.y + height / 2; // Sphere's Y position in 2D
      
      // Update the ME's position towards the target
      this.displayedX += (targetX - (this.displayedX)) * 0.05; // Move towards target X
      this.displayedY += (targetY - (this.displayedY)) * 0.05; // Move towards target Y
}

The other part of the attacking process is to decide if the object has collided with the black hole and, if so, remove it from the canvas. I achieved this by holding all ME instances in an array and then, when needed, removing them along with removing elements from the array (splice ()). (For clearer demonstration, I’ve also placed the instantiating function callingme() here.) In fact, whenever the code deals with the instances, it accesses them by calling the first item in the array objectsme.

let objectsme = []; // array to hold ME graphics objects

// create ME instances, add to array objectsme, and create graphics objects
function callingme() {
  guitarObject = new Hoveringme(20, 20, 'guitar');
  racketObject = new Hoveringme(-40, -60, 'racket');
  rectObject1 = new Hoveringme(-70, -10);
  rectObject2 = new Hoveringme(-80, 90);
  rectObject3 = new Hoveringme(60, -60);
  objectsme.push(guitarObject, racketObject, rectObject1, rectObject2, rectObject3); 
  drawGuitar();
  drawRacket();
 }

// in Hoveringme.show() method
if (((this.displayedX - targetX)**2 < 200) & ((this.displayedY - targetY)**2 < 200)) {
   objectsme.splice(objectsme[0], 1);
}

reflections, and so on

I would say I’m quite satisfied with this production for now, whether in terms of technical tryouts or basically achieving my message-conveying intention. Still, there is much room for improvement – both technically and beyond. I could have tried with more 3D features, alpha channel, typography, etc. I could have also designed a better disappearing for the black hole when MEs had made the attacks. But overall, I believe this is quite an interesting exploration.

Continue reading “Week 1 – Self-Portrait: The Sword of Damocles”

Self-Portrait: Me Meme

My idea was creating a portrait of myself with some simple and fun interaction. After looking online, I saw that eye movement is quite common and flexible. I was thinking about which type of movement I should implement when I remember a meme that is quite popular on the internet:

I'm the creator of the meme: "Awkward Look Monkey Puppet". Is it possible to sell it as NFT? : r/ethtrader

The awkward monkey meme

I decided to use interaction in p5js to depict the eye movement. When the cursor is far away from the face, the eyes will be looking towards the left, when the cursor is near, the eyes will look away (like when you just did something wrong and someone look at you).

To implement this in programming, I calculate the distance between the cursor and the center of the face. If the distance is smaller than the radius, the eyes movement is triggered.

if (distance < 90){
  eyePositionLeft = 230;
  eyePositionRight = 280;
} else{
  eyePositionLeft = 210;
  eyePositionRight = 262;
}

For the rest of the portrait, I use circle, ellipse, line and rect to draw a simplified version of myself. Here is the final version:

Reflection

Because I am used to using graphic software with a wide range of shapes and tools, drawing with p5.js initially felt limiting. However, I rather enjoy the challenge of using only a limited number of shapes and seeing what I can create with them. I also enjoy planning the interactivity I could incorporate, which is a different experience compared to drawing with graphic software.