python创意turtle作品和代码,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()

抽象画

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()

星空

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()

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()

樱花

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()
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值