# L-31 MCS 260 Wed 7 Nov 2007 : pentagram.py # # Illustration of canvas: drawing a pentagram. # The origin is at the top left corner. from Tkinter import * from math import * d = 400 # number of pixels in rows/columns r = 0.8*d/2 # radius of the pentagram a = 2*pi/5 # dividing angle L = [(d/2,d/2-r),\ (d/2+r*cos(pi/2-a),d/2-r*sin(pi/2-a)),\ (d/2+r*cos(pi/2-2*a),d/2-r*sin(pi/2-2*a)),\ (d/2+r*cos(pi/2-3*a),d/2-r*sin(pi/2-3*a)),\ (d/2+r*cos(pi/2-4*a),d/2-r*sin(pi/2-4*a))] wdw = Tk() wdw.title('pentagram') c = Canvas(wdw,width=d,height=d,bg='white') c.pack() for p in L: c.create_oval(p[0]-6,p[1]-6,p[0]+6,p[1]+6,\ width=1,outline='black',fill='SkyBlue2') A = L[0]; B = L[1]; C = L[2]; D = L[3]; E = L[4] c.create_line(A[0],A[1],C[0],C[1],width=2) c.create_line(A[0],A[1],D[0],D[1],width=2) c.create_line(B[0],B[1],D[0],D[1],width=2) c.create_line(B[0],B[1],E[0],E[1],width=2) c.create_line(C[0],C[1],E[0],E[1],width=2) wdw.mainloop()