I’m trying to write a code which draws a circle at each of a series of coordinates given from a csv file.
I want to give each circle a random color but my code at present gives the same color to all the circles.
How can I achieve what I want?!
thankyou
//
// takes xy coordinates of and draws a circle at each point
Table table;
void setup() {
table = loadTable("xyloc.csv", "header");
size(1400, 600);
for (TableRow row : table.rows()) {
int x = row.getInt("x");
int y = row.getInt("y");
fill(random(255), random(255), random(255));
ellipse(x/5, y/5, 2, 2);
}
}
Hi @jimjimmer,
Welcome to the forum! 
No problem, just hit the </>
button when editing a message or use triple backticks ``` around your code like this: ``` code ``` → code
Your code should work since the random()
function is giving a random result each time its called (by definition). Therefore your ellipses should be filled with a random color.
Check this code (similar to yours):
void setup() {
size(500, 500);
background(255);
}
void draw() {
float rx = random(width);
float ry = random(height);
fill(random(255), random(255), random(255));
circle(rx, ry, 50);
}

Ha what a ditz yes it does work doesn’t it ! My circles were too small on the screen and I couldn’t see the variation! Thanks ever so much I’m sure I will be back soon!
1 Like
That’s it, 2 pixels large is quite small! 
Have fun programming 