xxxxxxxxxx
47
/*
Objective:
- Introduction to Objects
*/
// CODE WITHOUT OBJECTS
/*
let bobX = 200;
let bobY = 200;
let bobR = 50;
function setup() {
createCanvas(400, 400);
background(42);
}
function draw() {
// We create a circle with our variables and make it green
fill(0, 255, 200);
circle(bobX, bobY, bobR);
}
*/
// CODE USING AN OBJECT
// bob object with three properties: x, y, r;
// Objects have keys and values.
// key x, value 100. key y, value 100, key r, value 50
let bob = {
x: 100,
y: 100,
r: 50,
};
function setup() {
createCanvas(400, 400);
background(42);
}
function draw() {
// We create a circle using our bob object
// We access the values in the object by using dot notation
// We type the name of the object, a dot (.) and then the property we want to access
fill(255,200,0);
circle(bob.x, bob.y, bob.r)
}