Write a program or function that takes in the following input in a reasonable format of your choice:
Two positive integers W and H that define the width and height of the image you'll be generating.
Two RGB colors C1 and C2 that will be used to color the image.
A list of 3-tuples of the form
(r, x, y)
that define circles with radiusr
and centerx, y
in the plane of the image.r
is a positive integer andx
andy
are any integers. The top left pixel of the image is0, 0
and the x-axis increases to the right and the y-axis increases downward.
Output an image with dimensions W by H that is colored with C1 and C2 such that no two neighboring regions defined by all the overlapping circles are the same color.
For example: If the input is
W = 300 H = 200 C1 = (255, 200, 0) C2 = (128, 0, 255) Circles = (25, 50, 80), (40, 80, 120), (300, -100, 6), (17, 253, 162)
then the circle boundaries look like this:
There are six distinct, contiguous regions in the image created by the circles. Each region must be colored with C1 (yellow) or C2 (purple) such that no two neighboring regions are the same color.
There are two ways to do this, their only difference being that the colors are swapped:
Thus, either of these two images would be valid output for the example input.
Something like this would be invalid output since two yellow regions neighbor each other.
Your output images should follow these guidelines:
Besides C1 and C2, a third, neutral color such as black or white may be used for circle boundaries as long as they are no more than 5 pixels thick. (Black, 1-pixel thick boundaries are present in the example above.)
Circles boundaries are not required, however. The regions may neighbor each other directly:
Both of these is another valid output to the example above.
Circles should be as accurate as reasonably possible, using circle drawing algorithms or whatever your graphics library provides.
In general, pixel-perfection is not required, but if the input parameters are scaled equally larger and larger, the resulting image should become more and more accurate.
Anti-aliasing is allowed but not required.
Gridlines or axis labels etc. in the background are not allowed.
The shortest code in bytes wins.
More Examples
All using these inputs with different sets of circles:
W = 100
H = 60
C1 = (255, 0, 0)
C2 = (0, 0, 255)
In any example the colors can be swapped and remain valid.
Circles =
A. empty list
B. (13, 16, 20)
C. (30, 16, 20)
D. (200, 16, 20)
E. (42, 50, 20)
F. (42, 50, 20), (17, 40, 30)
G. (42, 50, 20), (17, 20, 30)
H. (42, 50, 20), (17, 10, 30), (10, 50, 30)
I. (42, 50, 20), (17, 10, 30), (35, 50, 20)
J. (18, 36, 40), (18, 63, 40), (18, 50, 20)
K. (100, -10, -20), (60, 50, -10)
L. (18, 36, 40), (18, 63, 40), (18, 50, 20), (14, 50, 20), (5, 50, 18), (20, 0, 0), (70, 22, 0), (10000, -9970, 0), (135, 100, -80)
A.
B.
C.
D.
E.
F.
G.
H.
I.
J.
K.
L.
Make sure your output behaves similar to all these examples.
tikz
\$\endgroup\$