I am trying to create 5 circle shapes with randomly generating filled color from an array. But since I hard coded 5 individual random()
generation. Sometimes the randomly generated colors between the circles still being the same. I am not sure how to make it so the colors for each circles will not have same color (the same random result) :
function setup() {
createCanvas(400, 700);
noLoop();
}
function draw() {
background(220);
filled = ['PapayaWhip','PaleVioletRed','Lavender','LightGreen','Coral', 'CadetBlue','Azure','HoneyDew','LightBlue','Thistle','SlateBlue','RosyBrown','SteelBlue','OrangeRed'];
randcol1 = filled[floor(random() * filled.length)];
randcol2 = filled[floor(random() * filled.length)];
randcol3 = filled[floor(random() * filled.length)];
randcol4 = filled[floor(random() * filled.length)];
randcol5 = filled[floor(random() * filled.length)];
fill(randcol1);
circle(width/2,100,100);
fill(randcol2);
circle(width/2,200,100);
fill(randcol3);
circle(width/2,300,100);
fill(randcol4);
circle(width/2,400,100);
fill(randcol5);
circle(width/2,500,100);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.0.0/p5.min.js"></script>
By the way may I also ask, is there anyway to perform individual random generation without repeating 5 lines of random()
?
Thanks