turtle绘图 - 简单图案

爱心love

import turtle as t

t.speed(0)

def love():
    t.color('red','pink')
    t.begin_fill()
    t.seth(45)
    t.fd(200)
    t.circle(100,extent=180)
    t.seth(135)
    t.circle(100,extent=180)
    t.fd(200)
    t.end_fill()

love()

t.done()

彩色气球 

import turtle as t
import random

for i in range(30): # 画30个气球

    t.speed(0)      # 绘画速度
    t.pensize(2)    # 画笔尺寸

    # 设置颜色
    t.colormode(255) # 颜色模式(有255和1.0两种)
    red = random.randint(0,255)
    green = random.randint(0,255)
    blue = random.randint(0,255)

    # 调整位置
    x = random.randint(-220,220) # 画笔x坐标
    y = random.randint(-220,220) # 画笔y坐标
    t.penup()                    # 提笔(画笔不接触画布,goto时不会留下笔迹)
    t.goto(x,y)                  # 调整画笔位置
    t.pendown()                  # 落笔(画笔接触画布)

    # 气球
    t.color(red,green,blue)
    # 通过三元组(red,green,blue)确定颜色(RGB调色)
    t.begin_fill()    # 开始填充
    t.circle(30)      # 画圆
    t.end_fill()      # 结束填充

    # 气球绳
    t.right(90)       # 向右转90度
    t.forward(30)     # 画直线
    t.left(90)        # 向左转90度

# 隐藏画笔
t.hideturtle()
# 点击关闭,即可退出窗口
t.exitonclick()

 

繁星满天 

import turtle as t
import random

t.setup(width=800,height=660) # 窗口大小
# t.bgpic()                   # 背景图片
t.speed(0)                    # 绘画速度
t.colormode(255)              # 颜色模式(有255和1.0两种)
t.bgcolor('black')            # 背景颜色

# 天空
t.pensize(100)  # 画笔尺寸
co = 20         # 在t.color(0, 0, co)中使用
x = -450        # 画笔x坐标
y = 300         # 画笔y坐标
for i in range(8):           # 天空有8个层次
    t.color(0, 0, co)        # 蓝色渐变
    t.penup()                # 提笔(画笔不接触画布,goto时不会留下笔迹)
    t.goto(x, y)             # 调整画笔位置
    t.pendown()              # 落笔(画笔接触画布)
    t.forward(1000)          # 画直线
    co += 12                 # 蓝色渐变
    y -= 100                 # 画笔y坐标

# 星星
t.pensize(3)

for k in range(26): # 画26颗星星

    red = random.randint(0,255)     # 红
    green = random.randint(0, 255)  # 绿
    blue = random.randint(0, 255)   # 蓝
    t.color(red,green,blue)
    # 通过三元组(red,green,blue)确定颜色(RGB调色)

    x = random.randint(-300,300)    # x坐标随机
    y = random.randint(-60,300)     # y坐标随机
    t.penup()
    t.goto(x,y)
    t.pendown()

    l = random.randint(5,20)        # 大小随机
    t.begin_fill()                  # 开始填充
    for i in range(4):
        t.forward(l)
        t.left(30)                  # 向左转30度
        t.forward(l)
        t.right(120)                # 向右转120度
    t.end_fill()                    # 结束填充

    t.left(20)                      # 向左转20度

# 隐藏画笔
t.hideturtle()
# 点击关闭,即可退出窗口
t.exitonclick()

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值