Diferències
Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.
| info:cursos:pue:python-pcpp1:m3:1.4 [23/12/2023 20:01] – creat mate | info:cursos:pue:python-pcpp1:m3:1.4 [23/12/2023 20:05] (actual) – mate | ||
|---|---|---|---|
| Línia 79: | Línia 79: | ||
| {{ : | {{ : | ||
| - | Setting non-zero values for more than one component produces intermediate colors, e.g. red and blue set to 255 with green set to 0 gives the violet. | + | Setting non-zero values for more than one component produces |
| {{ : | {{ : | ||
| + | It seems clear, doesn' | ||
| + | |||
| + | OK, but how to specify all these (more than 16 million) mixes in a comprehensive way? | ||
| + | |||
| + | It's is done by a trick used extensively in web pages – as a **string** starting with a **hash** (#) followed by **6 hexadecimal** digits. Each p**air of the digits** forms the value from range **0x00..0xFF** (0..255) what determines the specific component level. | ||
| + | |||
| + | This is how it works: | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | All three pairs (RR, GG and GG) are **two-digit hexadecimal number** so: | ||
| + | |||
| + | * #000000 is **black** | ||
| + | * #FFFFFF is **white** | ||
| + | * #FF0000 is **red** | ||
| + | * #00FF00 is **green** | ||
| + | * #0000FF is **blue** | ||
| + | * #00FFFF is **turquoise** | ||
| + | * #FF00FF is **violet** | ||
| + | * ... | ||
| + | |||
| + | |||
| + | Please, forgive us that we made that list so short. To tell the truth, we have no idea how to name each of these 16 million colors – do you? | ||
| + | |||
| + | Note: when all the components are set to the **same value**, equal neither to zero nor to 0xFF (e.g. #0F0F0F0), you will get **254 shades of gray**. | ||
| + | |||
| + | Look at the code in the editor. We want to show you a little test showing how the RGB works: | ||
| + | |||
| + | <code python> | ||
| + | import tkinter as tk | ||
| + | |||
| + | window = tk.Tk() | ||
| + | button = tk.Button(window, | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | button.pack() | ||
| + | window.mainloop() | ||
| + | |||
| + | </ | ||
| + | |||
| + | Do the colors look the same as in the previous code? | ||
| + | |||
| + | They should look the same as we used RGB equivalents of the previously used '' | ||
| + | |||
| + | Now try to find RGB codes for all your favorite colors. There are so many choices – don't feel lost! | ||