Python 2.6 Graphics Cookbook
上QQ阅读APP看书,第一时间看更新

Three arc ellipses

Three elliptic arcs are drawn.

How to do it...

The instructions used in recipe 1 should be used.

Just use the name 3arc_ellipses.py when you write, save, and execute this program.

# 3arc_ellipses.py
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>            
from Tkinter import *
root = Tk()
root.title('3arc ellipses')

cw = 180                                      # canvas width
ch = 180                                      # canvas height
canvas_1 = Canvas(root, width=cw, height=ch)
canvas_1.grid(row=0, column=1)                              

xy_1 = 20,   80,  80, 20
xy_2 = 20,  130,  80, 100
xy_3 = 100, 130, 140, 20

canvas_1.create_arc(xy_1, start=20, extent=270, fill="red")
canvas_1.create_arc(xy_2, start=-50, extent=290, fill="cyan")
canvas_1.create_arc(xy_3, start=150, extent=-290, fill="blue")
root.mainloop()
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

How it works...

The results are given in the next screenshot, showing well-behaved create_arc() ellipses.

How it works...

The point to note here is that just like rectangles and ovals; the overall shape of the drawn object is governed by the shape of the bounding box. Start and finish (that is extent) angles are expressed in conventional degrees. Note that if trigonometry functions are going to be used then the circular measure has to be radians and not degrees.

There's more...

The create_arc() method has been made user-friendly by requiring angular measurements in degrees rather than radians because most people can visualize degree amounts more easily than radians. But you need to know this is NOT the case with angular measurement in any function used by the math module. All the trigonometric functions like sine, cosine, and tangent use radian angular measurement which are only a minor convenience. The math module provides easy to use conversion functions.