当前位置:   article > 正文

Python Turtle有趣的作品_turtle作品

turtle作品

Python Turtle有趣的作品


笑脸

emotions.py

import turtle


def draw_circle(x_position, y_position, t_radius, t_angle, t_color):
	turtle.up()
	turtle.setpos(x_position,y_position)
	turtle.down()
	turtle.begin_fill()
	turtle.circle(t_radius,t_angle)
	turtle.color(t_color)
	turtle.end_fill()


turtle.shape('turtle')
#画脸
turtle.left(90)
draw_circle(200,0,200,360,'yellow')

#画眼睛
draw_circle(-20,100,30,360,'black')
draw_circle(80,100,30,360,'black')

#画眼睛
draw_circle(-20,100,30,180,'white')
turtle.lt(180)
draw_circle(80,100,30,180,'white')
turtle.lt(180)

#画脸颊
draw_circle(-80,-20,50,360,'pink')
draw_circle(180,-20,50,360,'pink')

#画嘴
turtle.seth(-120)

turtle.up()
turtle.pencolor('black')
turtle.setpos(80,-90)
turtle.down()
turtle.circle(-90,120)

turtle.hideturtle()
turtle.done()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

抽象画

picture.py

import turtle
import random


pen = turtle.Turtle()
pen.shape('turtle')

paper = turtle.Screen()
# pen.speed(0)
paper.tracer(0)

x = -200
y = 200
size = 20

for b in range(20):
    pen.goto(x,y)
    y -= size

    for a in range(20):
        # 大正方形
        pen.color(random.random(), random.random(), random.random())
        pen.begin_fill()
        for j in range(4):
            pen.forward(size)
            pen.left(90)
        pen.end_fill()

        # 新的起笔位置
        pen.penup()
        pen.forward(size / 4)
        pen.left(90)
        pen.forward(size / 4)
        pen.right(90)
        pen.pendown()

        # 小正方形
        pen.color(random.random(), random.random(), random.random())
        pen.begin_fill()
        for j in range(4):
            pen.forward(size / 2)
            pen.left(90)
        pen.end_fill()

        #回到初始位置
        pen.penup()
        pen.forward(-size / 4)
        pen.left(90)
        pen.forward(-size / 4)
        pen.right(90)
        pen.pendown()

        #让海龟走到下一个位置
        pen.penup()
        pen.forward(size)
        pen.pendown()
pen.penup()
pen.ht()
pen.goto(0,-230)
pen.write('Thousands Eyes',align='center',font=('楷体',30,'normal'))
pen.goto(0,-270)
pen.write('$999999999999',align='center',font=('楷体',30,'normal'))
paper.update() # 更新画布
turtle.done()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64

星空

star_night.py

import turtle
import random


pen=turtle.Turtle()
paper=turtle.Screen()
#pen.speed(0)
paper.tracer(0)


paper.screensize(1280,1024,'black')


for b in range(200):
    pen.begin_fill()
    pen.fillcolor('yellow')

    X=random.random()*20

    for a in range(5):
        pen.forward(X)
        pen.left(72)
        pen.forward(X)
        pen.right(144)
        

    pen.penup()
    pen.goto(random.random()*1280-640,random.random()*1024-512)
    pen.left(random.randint(0,360))
    pen.pendown()


    pen.end_fill()
    

paper.update()
turtle.done()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

snow.py

import turtle
import random

pen=turtle.Turtle()
pen.shape('turtle')

paper=turtle.Screen()
paper.bgcolor('light blue1')
#pen.speed(0)
paper.tracer(0)


def koch(size,n):
    if n==0:
        pen.forward(size)
    else:
        for angel in [0,60,-120,60]:
            pen.left(angel)
            koch(size/3,n-1)


for i_snow in range(100):

    pen.penup()
    pen.setx(random.randint(-500,500))
    pen.sety(random.randint(-500,500))
    pen.pendown()
    size_snow=random.randint(10,50)

    pen.begin_fill()
    pen.color('white')
    for i in range(3):
        koch(size_snow,4)
        pen.right(120)
    pen.end_fill()

pen.penup()
pen.ht()
pen.goto(0,-360)
pen.color('gray23')
pen.write('SNOW FLOWERS',align='center',font=('楷体',30,'normal'))

pen.penup()
pen.ht()
pen.goto(0,-400)
pen.color('gray23')
pen.write('Snow',align='left',font=('楷体',20,'normal'))

pen.hideturtle()
paper.update()
turtle.done()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51

樱花

sakura.py

import turtle as T
import random
import time

# 画樱花的躯干(60,t)
def Tree(branch, t):
    time.sleep(0.0005)
    if branch > 3:
        if 8 <= branch <= 12:
            if random.randint(0, 2) == 0:
                t.color('snow')  # 白
            else:
                t.color('lightcoral')  # 淡珊瑚色
            t.pensize(branch / 3)
        elif branch < 8:
            if random.randint(0, 1) == 0:
                t.color('snow')
            else:
                t.color('lightcoral')  # 淡珊瑚色
            t.pensize(branch / 2)
        else:
            t.color('sienna')  # 赭(zhě)色
            t.pensize(branch / 10)  # 6
        t.forward(branch)
        a = 1.5 * random.random()
        t.right(20 * a)
        b = 1.5 * random.random()
        Tree(branch - 10 * b, t)
        t.left(40 * a)
        Tree(branch - 10 * b, t)
        t.right(20 * a)
        t.up()
        t.backward(branch)
        t.down()

# 掉落的花瓣
def Petal(m, t):
    for i in range(m):
        a = 200 - 400 * random.random()
        b = 10 - 20 * random.random()
        t.up()
        t.forward(b)
        t.left(90)
        t.forward(a)
        t.down()
        t.color('lightcoral')  # 淡珊瑚色
        t.circle(1)
        t.up()
        t.backward(a)
        t.right(90)
        t.backward(b)

# 绘图区域
t = T.Turtle()
# 画布大小
w = T.Screen()
t.hideturtle()  # 隐藏画笔
t.getscreen().tracer(5, 0)
w.screensize(bg='wheat')  # wheat小麦
t.left(90)
t.up()
t.backward(150)
t.down()
t.color('sienna')

# 画樱花的躯干
Tree(60, t)
# 掉落的花瓣
Petal(200, t)
w.exitonclick()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/276726
推荐阅读
相关标签
  

闽ICP备14008679号