February Post
- Chelsea Yang
- Mar 12, 2021
- 2 min read
This week, I met up with my liaison and fixed the problem of loading an image onto Processing, as well as drawing the robot’s head. The prior values that I used was RADIUS instead of radius in my code, which RADIUS should only be indicated in the setup() and not within the drawRobot() function.

I learnt a unit on objects, in which object-oriented programming was introduced. OOP is a way to group variables with related functions. Objects break up ideas into smaller blocks, so that as the code becomes more complex, smaller structures that form more complicated ones are present to help understand the larger context.
In objects, a variable is a property, or instance variable; a function is referred to as a method. They combine related data, properties, with related actions and behaviours, methods.
First, a constructor function needs to be created. A constructor function is the specification for an object - it defines the data types and behaviours, but each object made from a single constructor function has variables that could be of different values. This should be named with an uppercase letter in order to denote that it’s a constructor.
Then, properties are added. The keyword this can be used within the constructor to indicate the current object.
function setup() {
createCanvas(480, 120);
background(204);
bug = new JitterBug(width/2, height/2, 20);
}
function draw() {
bug.move();
bug.display();
}
function JitterBug(tempX, tempY, tempDiameter){
this.x = tempX;
this.y = tempY;
this.diameter = tempDiameter;
this.speed = 0.5;
this.move = function(){
this.x += random(-this.speed, this.speed);
this.y += random(-this.speed, this.speed);
};
this.display = function(){
ellipse(this.x,this.y,this.diameter,this.diameter);
};
}
When creating objects, the variable has to be declared, and initialise it with the keyword new.

Objects are useful to group smaller functions of a part of a larger piece of code when writing a more complex code. They can be recalled throughout the code to reduce redundancy in organization, and is also more convenient when writing it.
Comentarios