python-turtle库学习

from turtle import *
import random
import time
n=80.0

speed("fastest")
#画笔的移动速度,绘制速度范围(0,10],数字越大越快
screensize(bg='seashell')
#设置画布大小 canvas  canvwidth canvheight bg 分别分别代表 画布的宽、高、背景颜色 
#宽高为小数时,表示占据电脑屏幕的比例
#为整数的时候,表示像素
#若为空,窗口位于屏幕中心

left(90)
#逆时针移动90度
forward(3*n)
#向当前画笔方向移动 像素长度
color("orange","yellow")
#同时设置pencolor=orange,fillcolor=yellow
#pencolor 代表画笔颜色
#fillcolor 绘制图形的填充颜色

begin_fill()
#准备开始填充图形
left(126)
#逆时针移动126度
for i in range(5):
    forward(n/5)
    right(144)
    #顺时针移动144度
    forward(n/5)
    left(72)

end_fill()
#填充完成
right(126)


color("dark green")
backward(n*4.8)
#向当前画笔相反方向移动 像素长度
def tree(d,s):
    if d<=0:return
    forward(s)
    tree(d-1,s*.8)
    right(120)
    tree(d-3,s*.5)
    right(120)
    tree(d-3,s*.5)
    right(120)
    backward(s)
tree(15,n)
backward(n/2)

for i in range(200):
    a = 200 - 400 * random.random()
    b = 10 - 20*random.random()
    up()
    forward(b)
    left(90)
    forward(a)
    down()
    if random.randint(0,1) == 0:
        color('tomato')
    else:
        color('wheat')
    circle(2)
    up()
    backward(a)
    right(90)
    backward(b)
time.sleep(60)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Pythonturtle是一个用于创建简单图形和动画的模块,非常适合初学者学习编程的绘图概念。如果你想使用turtle来画出鸣人这个角色,首先你需要知道鸣人的基本特征,比如他的发型、服装等元素。 以下是一个简化的步骤,展示如何用turtle画出鸣人的大致轮廓: 1. 导入turtle模块并设置画笔大小和颜色: ```python import turtle turtle.speed(1) # 设置画笔速度,0最快,1等,2慢,3最慢 turtle.pencolor('yellow') # 鸣人的头发通常是黄色 ``` 2. 绘制头部(圆形或椭圆): ```python turtle.begin_fill() turtle.circle(30) # 大致的圆形头 turtle.end_fill() ``` 3. 绘制面部特征(两个小圆作为眼睛,一个长形为嘴巴): ```python turtle.penup() turtle.goto(-15, -10) # 移动到合适位置 turtle.pendown() turtle.circle(5) # 左眼 turtle.penup() turtle.goto(-15, 10) # 右眼 turtle.pendown() turtle.circle(5) turtle.penup() turtle.goto(0, 0) # 嘴巴 turtle.pendown() turtle.forward(20) turtle.right(90) turtle.forward(10) turtle.left(90) turtle.forward(20) ``` 4. 绘制身体和衣服: ```python turtle.penup() turtle.goto(-40, 0) # 移动到身体位置 turtle.pendown() turtle.begin_fill() turtle.circle(60) # 身体 turtle.end_fill() turtle.penup() turtle.goto(-70, -20) # 衣服部分 turtle.pendown() turtle.begin_fill() turtle.color('blue', 'white') # 蓝色上衣 turtle.circle(40) # 上衣轮廓 turtle.end_fill() ``` 5. 最后,你可以添加一些细节,如手脚和标志性的螺旋丸符号,但这会更复杂些。 请注意,由于鸣人形象非常细致,用turtle可能无法精确还原,但以上代码提供了一个基本的绘画框架。如果你需要进一步了解如何改进细节或想要其他相关问题,请告诉我。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值