I am currently working on a project where I am using an array of objects to display random items on a canvas. The goal is to have each object display with a unique random color. However, the code I have written is causing every object to have the same color.
var arrayOfObjects = [
{x: 1, y: 5, r: 10, color: pickColor}, //should have a random color
{x: 2, y: 6, r: 10, color: pickColor} // should have a different color
//and so on...
];
I attempted to update the code by replacing the pickColor variable with a function that would be executed within each object to ensure they all receive a different color. However, I am facing difficulty in using this function to select a color from the color array.
Despite my efforts, the following code snippet does not achieve the desired outcome:
{x: 1, y: 5, r: 10, color: colorList[parseInt(Math.random() * colorList.length)]},
UPDATE: I have confirmed that this code is functioning correctly. The issue was unrelated and took some time to diagnose. Thank you for your assistance in troubleshooting.