python绘制科赫雪花

代码如下

# -*- coding: utf-8 -*-
"""
Created on Sun Apr 15 11:12:58 2018

@author: dell
"""
#Coch
import turtle
def coch(size,n):
    if n==0:
        turtle.fd(size)
    else:
        for angle in [0,60,-120,60]:
            turtle.left(angle)
            coch(size/3,n-1)
def main():
    turtle.setup(600,600)
    turtle.penup()
    turtle.pensize(2)
    turtle.goto(-200,100)
    turtle.pendown()
    level=3
    coch(400,level)
    turtle.right(120)
    coch(400,level)
    turtle.right(120)
    coch(400,level)
    turtle.hideturtle()
main()

这里写图片描述

阅读更多

没有更多推荐了,返回首页