-
Notifications
You must be signed in to change notification settings - Fork 1
/
circling_triangle.py
60 lines (51 loc) · 1.16 KB
/
circling_triangle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!python3
### https://sites.google.com/site/algorithms2013/home/python-turtle-graphics
# space filling hilbert curve in python 3
# adapted from http://www.fundza.com/algorithmic/space_filling/hilbert/basics/index.html
import sys, math, time
import turtle as t
#try:
#from OpenGL.GLUT import *
#from OpenGL.GL import *
#from OpenGL.GLU import *
#except:
# print('Error: PyOpenGL not installed properly')
# sys.exit( )
import array
import signal
import random
def signal_handler(signal, frame):
print('u pressed ctrl-c')
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
## a=> b-a-b
## b=> a+b+a
mycolor = ['blue', 'DarkOrchid4', 'forest green', 'gold4', 'gray', 'green', 'navy', 'purple', 'red', 'yellow' ]
def triangle(t, length, gap):
t.forward(length)
t.left(120)
t.forward(length)
t.left(120)
t.forward(length)
t.left(120)
t.left(gap)
xcolor = 0.1
ycolor = 0.2
p = t.Pen()
p.reset()
p.down()
p.speed(100)
ts = t.getscreen()
ts.colormode(255)
length = 50
count = 0
while length < 500:
n=20
gap = 360/n
while n>0:
triangle(t, length, gap)
n = n - 1
t.color(mycolor[count%10])
count = count + 1
length = length + 50
raw_input()