Arrays -
array is a list of values separated by commas embedded in square closed brackets
list of values
order of array matters
elements have an index
count from 0
how many elements there is e.g [50,71,12,22] = 0,1,2,3,
let nums = [160,25,46,72];
let num = 23;
let index = 0;
draw -
ellipse(100,200,nums[2],num)
text(words[2] / index, 12, 200) // pulling 3rd word from array
e.g function mousePressed(){
index = index+1; // makes code go through list of arrays in order when mouse pressed
}
how to pull numbers from an array
arrays can be anything e.g let words = ["rainbow" , "heart"]
For loops + arrays
for(let i = 0; i <4; i++){
// can also be used
stroke + fill
ellipse(i * 100 + 100 ,200, nums[i], nums[i]); }
// go through code 4 times = draw 4 circles // the times and + are taking the numbers in the array timesing them by 100 then adding 100 to get the right amounts
// execute a task check to see if its less than 4 add 1 , execute a task + repeat
-
-