GRASS 8 Programmer's Manual 8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
color_rand.c
Go to the documentation of this file.
1#include <time.h> /* For time() */
2#include <stdio.h> /* For NULL */
3#include <stdlib.h> /* For rand() and srand() */
4
5#include <grass/gis.h>
6#include <grass/raster.h>
7#include <grass/glocale.h>
8
9#define MAX_COLORS 1024
10#define DEVIATION 128
11
12/*!
13 * \brief make random colors
14 *
15 * Generates random colors. Good as a first pass at a
16 * color table for nominal data.
17 *
18 * \param colors
19 * \param min
20 * \param max
21 * \return
22 */
24{
25 unsigned char red, grn, blu;
26 int count;
27 CELL n;
28
29 Rast_init_colors(colors);
30 if (min > max)
31 G_fatal_error(_("Rast_make_random_colors: min (%d) > max (%d)"), min,
32 max);
33
34 /* You can set GRASS_RANDOM_SEED for repeatability */
36
38 if (count > max - min + 1)
39 count = max - min + 1;
40
41 for (n = 1; n <= count; n++) {
42 red = G_lrand48() & 0xff;
43 grn = G_lrand48() & 0xff;
44 blu = G_lrand48() & 0xff;
45 Rast_add_modular_c_color_rule(&n, red, grn, blu, &n, red, grn, blu,
46 colors);
47 }
49}
void Rast_make_random_colors(struct Colors *colors, CELL min, CELL max)
make random colors
Definition color_rand.c:23
#define DEVIATION
Definition color_rand.c:10
#define MAX_COLORS
Definition color_rand.c:9
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
long G_lrand48(void)
Generate an integer in the range [0, 2^31)
Definition lrand48.c:133
long G_srand48_auto(void)
Seed the pseudo-random number generator from the time and PID.
Definition lrand48.c:70
void Rast_set_c_color_range(CELL, CELL, struct Colors *)
Set color range (CELL version)
Definition color_range.c:24
int Rast_add_modular_c_color_rule(const CELL *, int, int, int, const CELL *, int, int, int, struct Colors *)
Add modular integer color rule (CELL version)
Definition color_rule.c:184
void Rast_init_colors(struct Colors *)
Initialize color structure.
Definition color_init.c:25
#define min(x, y)
Definition draw2.c:29
#define max(x, y)
Definition draw2.c:30
int CELL
Definition gis.h:634
#define _(str)
Definition glocale.h:10
int count
Definition gis.h:692