Spiral Triangles
while surfing through web, one day I came across a nice web page titled ideas.I picked up the ideas over there to implement in the pythonic way and rewrite all code in python.
Todays one is to draw a simple spiral triangles.The basic idea is to start with a triangle, interpolate to find a point a fraction of the way down a side, draw a line to this point, and use that point as the new corner for the triangle. This will make a picture that looks like this:

Complete source code will be as following :
I made few changes in color combination and turn it into following one :

Todays one is to draw a simple spiral triangles.The basic idea is to start with a triangle, interpolate to find a point a fraction of the way down a side, draw a line to this point, and use that point as the new corner for the triangle. This will make a picture that looks like this:

Complete source code will be as following :
from Tkinter import *
import math
## constant for slope
## and fixed 3 points
ee = 0.04
x1=y1=y2=0
x2=10
x3=5
y3=5*math.sqrt(3)
PrevX = 0
PrevY = 150
## Scales the Line
def scale(x,y,xx,yy):
x=x*20+100
y=y*20+100
xx=xx*20+100
yy=yy*20+100
return(x,y,xx,yy)
root = Tk()
root.title("Trigno fun 1")
canvas = Canvas(width=400,height=300,bg='white')
canvas.create_line(scale(x1,y1,x2,y2),fill='red')
canvas.create_line(scale(x2,y2,x3,y3),fill='red')
canvas.create_line(scale(x3,y3,x1,y1),fill='red')
## positions shifted/swapped till 100th point
## using 3 fixed points
for i in range(0,100):
x4 = ee*x2 + (1-ee)*x3
y4 = ee*y2 + (1-ee)*y3
canvas.create_line(scale(x4,y4,x1,y1),fill='red')
x3=x2
y3=y2
x2=x1
y2=y1
x1=x4
y1=y4
canvas.pack()
mainloop()
I made few changes in color combination and turn it into following one :

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home