A red beachball of varying hue

We use the hexadecimal color specification scheme to make a series of color shades arranged in a pattern determined by predefined lists of numerical constants. The underlying idea is to establish a method of accessing these constants in a way that can be reused for quite different picture designs.

How to do it...

Execute the program shown in exactly the usual way, and you will see a sequence of colored disks laid on top of each other going from dark to light shades. The size and location of each disk is determined by the lists hFac and wFac. hfacisa mnemonic for " Height factor" andwFac for "Width factor". The following screenshot shows the Graded Color Ball.

How to do it...
# red_beach_ball_1.py
# >>>>>>>>>>>>>>>>>
from Tkinter import *
root = Tk()
root.title("Red beach ball")
cw = 240 # canvas width
ch = 220 # canvas height
chart_1 = Canvas(root, width=cw, height=ch, background="black")
chart_1.grid(row=0, column=0)
x_orig = 100
y_orig = 200
x_width = 80
y_hite = 180
xy0 = [x_orig, y_orig]
hexadecimal color specification schemecolor shades series, preparingxy1 = [x_orig - x_width, y_orig - y_hite]
xy2 = [x_orig + x_width, y_orig - y_hite ]
wedge =[ xy0, xy1 , xy2 ]
width= 80 # Standard disk diameter
hite = 80 # Median distance from origin (x_orig, y_orig).
hFac = [1.1, 1.15, 1.25, 1.35, 1.5, 1.6, 1.7] # Height # radial factors.
wFac = [ 2.0, 1.9, 1.7, 1.4, 1.1, 0.75, 0.40] # Disk # diameter factors.
# Color list. Elements incresing in darkness.
kulaRed = ["#500000","#6e0000","#a00000","#ff0000",
"#ff5050", "#ff8c8c", "#ffc8c8", "#ffffff" ]
kula = kulaRed
for i in range(0, 7): # Red disks
x0_disk = xy0[0] - width * wFac[i]/2 # Bottom left
y0_disk = xy0[1] - hite * hFac[i] + width * wFac[i]/2
xya = [x0_disk, y0_disk] # BOTTOM LEFT
x1_disk = xy0[0] + width * wFac[i]/2 # Top right
y1_disk = xy0[1] - hite * hFac[i] - width * wFac[i]/2
xyb = [x1_disk, y1_disk] # TOP RIGHT
chart_1.create_oval(xya ,xyb , fill=kula[i], outline=kula[i])
root.mainloop()

How it works...

The series of images of varying shades of red disks is laid down in a specific sequence by a for loop. The matching shades of red are held in the sequenced list of hex colors. Hex is the short form for hexadecimal.

The variables used to specify the reference origin as well as all the other positional parameters have been set up so they can be reused in other patterns later. The important principle here is that with careful planning of our programming we only need to solve a problem once in a universal, designed-for-reuse way. Of course in practice this planned design takes more time and includes lot more experimentation than the simpler once-off way of writing code. Either way the whole experimental process starts off with writing messy, rough and ready code that 'kind-of' works. This initial rough work is a very necessary part of the creative process as it allows vaguely formed ideas to grow and evolve into effective software programs.

There's more...

Having ironed out a scheme for drawing shaded disks in chosen geometric arrangements, we can now try different arrangements and end up with richer and more useful ideas. The next two recipes evolve this idea into a version of the artist's color wheel that illustrates how to achieve any color by controlled mixing of primary colors.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.181.47