From b23c94a522a36505b229399f7bfab4e73afdb8e8 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Wed, 30 Oct 2024 12:18:26 -0400 Subject: random colors --- balls.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'balls.c') diff --git a/balls.c b/balls.c index f40f64e..430a611 100644 --- a/balls.c +++ b/balls.c @@ -327,15 +327,19 @@ genVertexBuffer(void) { void setColors(void) { GLfloat (*colors)[3]; + GLfloat color[3]; int i, j; if ((colors = malloc(NBALLS*CIRCLE_POINTS*3*sizeof(GLfloat))) == NULL) sysfatal("Failed to allocate color array.\n"); for (i = 0; i < NBALLS; i++) { + color[0] = randFloat(0, 1); + color[1] = randFloat(0, 1); + color[2] = randFloat(0, 1); for (j = 0; j < CIRCLE_POINTS; j++) { - colors[i*CIRCLE_POINTS + j][0] = 1.0; - colors[i*CIRCLE_POINTS + j][1] = 0.0; - colors[i*CIRCLE_POINTS + j][2] = 0.0; + colors[i*CIRCLE_POINTS + j][0] = color[0]; + colors[i*CIRCLE_POINTS + j][1] = color[1]; + colors[i*CIRCLE_POINTS + j][2] = color[2]; } } -- cgit v1.2.3