[python]代码库
#!/usr/bin/env python
# encoding: utf-8
import turtle
class star:
def __init__(self):
self.sides = 6
self.circle = 360
self.colors = ['red', 'yellow', 'green', 'blue', 'orange', 'purple']
def hello(self):
return self
def run(self):
'''
The program entry
'''
turtle.bgcolor('black')
t = turtle.Pen()
for x in range(self.circle):
t.pencolor(self.colors[x % self.sides])
t.forward(x * 3 / self.sides + x)
t.left(360 / self.sides + 1)
t.width(x * self.sides / 180)
t.left(9)
if __name__ == '__main__':
star().hello().run()
[代码运行效果截图]