xxxxxxxxxx
58
// Week 2 - Variables example
// Intro to IM
// 2022-09-05
let myNumber = 4.5; // Declare variable for circle size
let myString = "the quick brown fox";
let myArray = ["the", "quick", "brown", "fox"];
// 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);
}
function draw() {
background(220);
// width and height are automatically set by
// p5js
let circleWidth = 20 + myRandomNumber;
circle(width / 2, height / 2, circleWidth);
drawBigCircle();
}
function drawBigCircle() {
let circleWidth = 50;
let filled=false;
circle(circleWidth - 10, circleWidth - 10, circleWidth);
while(true)
{
if(mouseIsPressed)
{
if (filled){
fill(255)
filled=false;
}
else
{
fill(0);
filled=true;}
}
}
}