Colours
Colour names
Colours are named in capitals. The main ones:
| Name | Name | Name |
|---|---|---|
WHITE | BLACK | GREY (or GRAY) |
RED | ORANGE | YELLOW |
GREEN | TEAL | BLUE |
GOLD | MAROON | PINK |
PURPLE | LIGHT_BROWN | DARK_BROWN |
Most come in five shades, _A (lightest) to _E (darkest): BLUE_A, BLUE_B, BLUE_C (the same as BLUE), BLUE_D, BLUE_E. Greys are GREY_A to GREY_E. PURE_RED, PURE_GREEN, PURE_BLUE and PURE_YELLOW are the full-strength versions.
A hex string works too: "#ff8800". So does any web colour name, such as "tomato", but an animated change of colour blends smoothly only between the capital names and hex colours; a web name switches at once.
Outline and fill
A shape has an outline (its stroke) and an inside (its fill):
from pymations import *
c = Circle(radius=1.5)
c.set_stroke(YELLOW, width=8)
c.set_fill(BLUE, opacity=0.6)
play(DrawBorderThenFill(c))
| Change | What it does |
|---|---|
m.set_color(RED) | Outline and fill colour together |
m.set_fill(BLUE, opacity=0.5) | The inside's colour and how solid it is (0 empty, 1 solid) |
m.set_stroke(WHITE, width=2, opacity=1) | The outline's colour, width and how solid it is |
m.set_opacity(0.5) | Makes the whole thing see-through |
m.fade(0.5) | Fades it by half |
group.set_color_by_gradient(BLUE, GREEN) | Colours a group's members in steps from one colour to the next |
The same can be given when you make the shape: Circle(color=RED, fill_opacity=0.5, stroke_width=6). stroke_width is 4 unless you say.
Shades in between
interpolate_color(BLUE, YELLOW, 0.25)is a quarter of the way from blue to yellow.color_gradient([BLUE, GREEN, YELLOW], 10)gives ten colours in steps.average_color(RED, YELLOW)mixes them.
The background
config.background_color = WHITE at the top of the file changes the background (black unless you change it). Remember to give text a dark colour on a light background: text is white unless you say.
Related
- Shapes
- Text and maths: colouring parts of an equation