import numpy
import ppgplot
import math

s602 = math.sin(math.pi/3.) / 2.
c602 = math.cos(math.pi/3.) / 2.
 
def drawtriangle (p1, p2, p3, i):
    if (i > 5) :
        return
    l = math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)
    ppgplot.pgmove(p1[0], p1[1])
    ppgplot.pgdraw(p2[0], p2[1])
    ppgplot.pgdraw(p3[0], p3[1])
    ppgplot.pgdraw(p1[0], p1[1])
 
    ppgplot.pgsci(1)
    drawtriangle(p1, [p1[0] + l/2, p1[1]], \
                 [p1[0] + l*c602, p1[1] + l*s602], i+1)
    ppgplot.pgsci(2)
    drawtriangle([p2[0] - l/2, p2[1]], p2, \
                 [p2[0] - l*c602, p2[1] + l*s602], i+1)
    ppgplot.pgsci(3)
    drawtriangle([p3[0] - l*c602, p3[1] - l*s602], \
                 [p3[0] + l*c602, p3[1] - l*s602], p3, i+1)
 
 
l = 1
p1 = [0,0]
p2 = [l,0]
p3 = [math.cos(math.pi/3.), math.sin(math.pi/3.)]
 
print p3
 
ppgplot.pgbeg('?')
ppgplot.pgask(1)
ppgplot.pgenv(0,1,0,1)
ppgplot.pgslw(5)
ppgplot.pgsci(1)
 
drawtriangle(p1,p2,p3,0)
ppgplot.pgend()
 
