相关: # python # # 分形 # 唱片
代码语言:javascript复制# coding: utf-8
import turtle
import random
def draw_circles(pen, xy, radius, step, is_homocentric = True):
(x, y) = xy
pen.ht()
pen.color("#FFFFFF")
pen.goto(x, y)
for r in range(radius, step, step):
rgb =tuple(color for color in (random.random(), random.random(), random.random()))
pen.begin_fill()
pen.fillcolor(rgb)
pen.color(rgb)
pen.circle(r)
pen.end_fill()
if is_homocentric:
y = y-step
pen.goto(x, y)
def main():
radius = 300
step = -20
xy = (-50, -radius)
my_pen = turtle.Turtle() draw_circles(my_pen, xy, radius, step)
my_pen.getscreen().getcanvas().postscript(file="homocentric_circle.eps")
my_pen.clear() draw_circles(my_pen, xy, radius, step, False)
my_pen.getscreen().getcanvas().postscript(file="nonhomocentric_circle.eps")
my_pen.clear()
if __name__ == "__main__":
main() pass
运行结果:
附 eps转png:
代码语言:javascript复制for f in `ls *.eps`; do
convert -density 500 $f -flatten ${f%.*}.png;
done