Skip to main content
100%

A small Python script to generate random color sequences, e.g. for use in plotting. Just call the "generate_new_color(existing_colors,pastel_factor)" function to generate a random color that is (statistically) maximally different from all colors in "existing_colors". The "pastel_factor" parameter can be used to specify the "pasteliness"(?) of the produced colors (please, don't you chose 0...)

✓ Published0🌍 Public
Aadewes
Last edited Jun 28, 2013
Created on Jun 28, 2013

This example demonstrates a Python utility for generating a sequence of visually distinct random colors, suitable for plotting or data visualization. It shows how to produce colors that are maximally different from a set of existing colors, with a `pastel_factor` parameter controlling pastel softness. The script uses Python’s `random` module to sample candidate RGB values and computes a simple Manhattan-distance metric (`color_distance`) to select the best candidate. The main function, `generate_new_color`, iterates 100 times to find the color with the greatest minimum distance from all previously chosen colors, with the example loop generating ten colors.

AI-generated description

Similar vizzes