Add random_color and the color palette

random_color returns an immutable (red, green, blue) tuple of integers from 0 to 255
and random_palette_color picks a named color. Both take an optional random.Random
so that tests can seed them.

Task: MIL-003#1
Task: MIL-003#2
This commit is contained in:
2026-10-07 23:59:02 +08:00
parent b3153b9dc1
commit 9318a07fa0
5 changed files with 127 additions and 0 deletions
+18
View File
@@ -14,6 +14,12 @@ WINDOW_TITLE = "Turtle Challenges"
## colors can be given as RGB tuples from 0 to 255.
COLOR_MODE = 255
## Smallest value of one color channel.
COLOR_CHANNEL_MIN = 0
## Largest value of one color channel.
COLOR_CHANNEL_MAX = COLOR_MODE
## Degrees in a right angle.
RIGHT_ANGLE_DEGREES = 90
@@ -32,6 +38,18 @@ DASH_LENGTH = 10
## Challenge 2: length of the gap after each dash, in turtle units.
GAP_LENGTH = 10
## Challenge 3: named colors a polygon is drawn in.
COLOR_PALETTE: tuple[str, ...] = (
"CornflowerBlue",
"DarkOrchid",
"IndianRed",
"DeepSkyBlue",
"LightSeaGreen",
"wheat",
"SlateGray",
"SeaGreen",
)
## Command line name of challenge 1.
CHALLENGE_SQUARE = "square"