Python作圖模塊之turtle

Python2里面默認(rèn)有一個包叫做turtle,別名:烏龜,對于Python初學(xué)者很有吸引力,適合學(xué)習(xí)。這個包,主要是畫圖用的,這里用它畫個圖,并提供源碼。

源碼

import turtle
def draw_square(turtle):
    for i in range(4):
        turtle.forward(100)
        turtle.right(90)

def draw_flower(turtle):
    for i in range(36):
        draw_square(turtle)
        turtle.right(10)

def draw_pic():
    window=turtle.Screen()
    window.bgcolor('red')
    brad=turtle.Turtle()
    brad.shape('turtle')
    brad.color('white')
    draw_flower(brad)
    window.exitonclick()
draw_pic() 

代碼GitHub下載地址

作者:柯廣的網(wǎng)絡(luò)日志 ? Python作圖模塊之turtle


微信公眾號:Java大數(shù)據(jù)與數(shù)據(jù)倉庫