Fill from an array

hi all,

i’m trying to input fill() from a global array and can’t see why this won’t work. it looks like a type conversion issue, but i thought this should work. any hints?

let array_main = ['0fb794', 2, 3];

function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(220);
  
  print("'#"+array_main[0]+"'");
  fill("'#"+array_main[0]+"'"); //This dosen't work
  //fill('#0fb794' ); //This works
  triangle(30, 75, 58, 20, 86, 75);
}

Try:
fill("#"+array_main[0]);

1 Like

that works! thank you, i knew i was missing something :face_with_spiral_eyes:

Hi @ablanton,

Why not putting the hash(#) direct in array initialisation and afterwards just do …

fill(array_main[0]); 

?

Cheers
— mnse

oh, this is just a quick example, in the work i’m slicing a longer string and then putting it into the array. so it’s quicker to concatenate the # in the fill function