您的位置:首页 > 编程语言 > Python开发

Python学习笔记四(turtle模块画图练习)

2019-03-27 10:48 417 查看

Turtle画图:

import turtle as t

import time

 

t.speed(5)

t.setup(900,900)

t.penup()

 

t.goto(0,-200)

t.pendown()

t.circle(200)

t.penup()

 

t.goto(-200,0)

t.pendown()

t.circle(200,90)

t.penup()

 

t.goto(-200,0)

t.setheading(0)

t.pendown()

t.circle(-200,90)

t.penup()

 

t.goto(200,0)

t.setheading(180)

t.pendown()

t.circle(200,90)

t.penup()

 

t.goto(200,0)

t.setheading(180)

t.pendown()

t.circle(-200,90)

t.penup()

 

Turtle画图:四瓣花,每一瓣由半径为100像素半圆弧的组成,如下图:

import turtle as t

import time

 

t.speed(5)

t.setup(900,900)

t.penup()

 

t.goto(-100,-100)

t.setheading(270)

t.pendown()

t.circle(100,180)

t.penup()

 

t.goto(100,-100)

t.setheading(0)

t.pendown()

t.circle(100,180)

t.penup()

 

t.goto(100,100)

t.setheading(90)

t.pendown()

t.circle(100,180)

t.penup()

 

t.goto(-100,100)

t.setheading(180)

t.pendown()

t.circle(100,180)

t.penup()

 

time.sleep(3)

 

 

Turtle绘制如下图形:

import turtle as t

import time

 

t.speed(5)

t.setup(800,800)

t.penup()

 

for a in range(3):

    t.home()

    t.setheading(120 * a)

    t.pendown()

    t.color("black", "black")

    t.begin_fill()

    t.forward(100)

    t.left(60)

    t.forward(100)

    t.left(120)

    t.forward(100)

    t.left(60)

    t.forward(100)

    t.end_fill()

    t.penup()

 

time.sleep(3)

 

Turtle绘制图形:

import turtle as t

import time

 

t.speed(5)

t.pensize(3)

t.setup(800,800)

 

t.pendown()

t.color("red","Black")

t.begin_fill()

t.left(30)

t.forward(100)

t.right(120)

t.forward(100)

t.right(120)

t.forward(200)

t.left(120)

t.forward(100)

t.left(120)

t.forward(100)

t.end_fill()

t.penup()

 

t.home()

t.goto(0,-15)

t.pendown()

t.color("red","Black")

t.begin_fill()

t.circle(15)

t.end_fill()

t.penup()

 

time.sleep(3)

 

 

Turtle绘制斯诺特图形,如下:

import turtle as t

import time

 

t.speed(5)

t.setup(800,800)

t.penup()

 

def Srt(r,n):

    for a in range(0,n):

        t.goto(0, -200)

        # t.dot(5,"red")

        t.setheading(120)

        t.forward(2 * r * a)

        t.setheading(0)

        for b in range(0, a + 1):

            t.pendown()

            t.circle(r)

            t.penup()

            t.forward(r+r)

 

Srt(50,4)

time.sleep(3)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: