看图编程之:九龟守空房

看图编程之:九龟守空房

九龟守空房李兴球Python
这个程序的单元是定义一个画正方形的函数,以下是这个函数,其它代码自己组织即可:

import turtle

def draw_square(center,length,cc):
    """center:中心点坐标
       length:边长
       cc:填充颜色
       以center为中心点画边长为length的正方形
    """
    l2 = length/2
    turtle.goto(center)
    turtle.bk(l2)
    turtle.right(90)
    turtle.bk(l2)
    turtle.left(90)
    turtle.color(cc)
    turtle.begin_fill()
    for _ in range(4):
        turtle.fd(length)
        turtle.right(90)
    turtle.end_fill()
    turtle.right(90)
    turtle.fd(l2)
    turtle.left(90)
    turtle.fd(l2)

turtle.penup()
draw_square((-100,100),100,'red')

李兴球

李兴球的博客是Python创意编程原创博客