Spiral Polygons
In last assignent we used hard coded three values for generating triangle.Here I extended the same script and the number of vertices kept variable values.
from Tkinter import *
import math
ee = 0.08
OuterDia = 250
Cpx = 200
Cpy = 150
vertices = 8
angle = 2*math.pi/vertices
# this stores point x,y values
points=[]
def point(x,y,i):
p = 5
return(x-p,y-p,x+p,y+p)
for i in range(0,vertices):
X = math.cos(angle*i)*OuterDia/2 + Cpx
Y = math.sin(angle*i)*OuterDia/2 + Cpy
pair = [X,Y]
points.append(pair)
root = Tk()
root.title("Trigno fun")
canvas = Canvas(width=400,height=300,bg='black')
fromx = points[vertices-1][0]
fromy = points[vertices-1][1]
for pt in points:
canvas.create_line(pt[0],pt[1], \
fromx,fromy,fill='white')
fromx = pt[0]
fromy = pt[1]
for i in range(0,100):
lastx = ee*points[vertices-2][0] \
+ (1-ee)*points[vertices-1][0]
lasty = ee*points[vertices-2][1] \
+ (1-ee)*points[vertices-1][1]
if(i%4==0):
color='yellow'
if(i%4==1):
color='green'
if(i%4==2):
color='red'
if(i%4==3):
color='blue'
canvas.create_line(lastx,lasty,points[0][0],\
points[0][1],fill=color)
for i in range(vertices-1,0,-1):
points[i][0]=points[i-1][0]
points[i][1]=points[i-1][1]
points[0][0]=lastx
points[0][1]=lasty
canvas.pack()
mainloop()