[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):
'''
This is a welcome speech
:return: 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 * 20 / self.sides + x)
t.left(90 / self.sides + 9)
t.width(x * self.sides / 200)
t.left(30)
if __name__ == '__main__':
star().hello().run()
[代码运行效果截图]