turtle模块的简单运用

turtle()简单运用:
画一个平行四边形并重复偏移

import turtle as t

def drawdemo(tom):
    for i in range(2):
        tom.forward(100)
        tom.right(45)
        tom.forward(100)
        tom.right(135)

def drawflower():
    windows = t.Screen()
    windows.bgcolor('blue')
    tom = t.Turtle()
    tom.shape('turtle')
    tom.color('red')
    tom.speed(0.1)
    # tom.fillcolor('yellow')#图形颜色填充
    # tom.begin_fill()
    for i in range(360):
        drawdemo(tom)
        tom.right(1)
    # tom.end_fill()
    tom.hideturtle()
    t.done()
drawflower()

效果如下所示:
turtle模块的简单运用_第1张图片
画一个爱心:


import turtle
import time
turtle.shape('turtle')

def draw_circle():
    for i in range (200):
        turtle.right(1)
        turtle.forward(1)
def draw_heart():
    turtle.color('red','pink')
    turtle.pensize(5)
    turtle.speed(1000)
    turtle.goto(0,0)
    turtle.begin_fill()
    turtle.left(140)
    turtle.forward(112)
    draw_circle()
    turtle.left(120)
    draw_circle()
    turtle.forward(112)
    turtle.end_fill()
    turtle.hideturtle()
    turtle.done()
draw_heart()

效果如下:
turtle模块的简单运用_第2张图片
乱画一个:

import turtle
def demo(t):
    t.forward(100)
    t.left(120)
    t.forward(100)
    t.left(120)
    t.forward(100)


def draw():
    win = turtle.Screen()
    win.bgcolor('yellow')
    t = turtle.Turtle()
    t.shape('turtle')
    t.speed(2)
    t.fillcolor('blue')
    t.begin_fill()
    for i in range(12):
        demo(t)
        t.right(30)
    t.end_fill()
    t.hideturtle()
    turtle.done()
draw()

效果如下:
turtle模块的简单运用_第3张图片

你可能感兴趣的:(python编程)