Week 1 – Self-portrait

Concept

 

 

Code snippet

// Declare in the global scope
// All functions will have access to this variable
let myRandomNumber;


function setup() {
  createCanvas(300, 400);
  
  myRandomNumber = random(255); // How can we find out what a variable's value is? print()

  let myRoundedNumber = round(myRandomNumber); 
  
  print('myRandomNumber = ' + myRandomNumber);
  print('myRoundedNumber = ' + myRoundedNumber);

  
}

 

Self-portrait as a young robot

Concept

For my digital self-portrait I tried to represent my inner robot.

Code

The drawing consists of simple shapes that use a mix of manual and calculated coordinates.

The location of the mouth is automatically calculated to be horizontally centered and 3/4 of the way down the canvas. The code uses variables that allow the size of the mouth rectangle to be easily changed and the position will be automatically recalculated.

// Set the mouth width and height
let rectangleWidth = 150;
let rectangleHeight = 90;

{...}

// Draw a centered rectangle
rect((width / 2) - (rectangleWidth / 2), height * 0.75 - rectangleHeight / 2, rectangleWidth, rectangleHeight);

Completed self-portrait:

Reflection / Future Work

The robot expresses my inner coder. In future I would like to add animated laser beams shooting from the eyes that automatically track the mouse cursor.