python学习turtle(笔控制)

学习记录,

笔控制

turtle.pendown()

turtle.pd()

turtle.down(),下笔,移动时绘画。

 

turtle.penup()

turtle.pu()

turtle.up(),拿起笔,移动时不绘画。

 

turtle.pensize(width=None)

turtle.width(width=None),返回或者设置笔画宽度。

 

turtle.pen(pen=None**pendict),设置笔的属性。

“shown”: True/False

“pendown”: True/False

“pencolor”: color-string or color-tuple

“fillcolor”: color-string or color-tuple

“pensize”: positive number

“speed”: number in range 0..10

“resizemode”: “auto” or “user” or “noresize”

“stretchfactor”: (positive number, positive number)

“outline”: positive number

“tilt”: number

 

turtle.isdown(),是否下笔,下笔返回True,提起笔False。

 

turtle.fillcolor(*args),返回或设置填充颜色。

可以是,fillcolor(colorstring)像"violet","#33cc8c";fillcolor((r, g, b));fillcolor(r, g, b)。

配合begin_fill()和end_fill()使用。

运行到turtle.end_fill()填充。

turtle.color(*args),返回或设置笔的颜色和填充的颜色。

color(colorstring1, colorstring2)color((r1,g1,b1), (r2,g2,b2)),等效于pencolor(colorstring1) 和 fillcolor(colorstring2)

 

turtle.filling(),返回填充状态,有设置开始填充返回True,否则返回False。

 

turtle.begin_fill(),开始填充位置。

turtle.end_fill(),结束填充位置。

 

turtle.reset(),重置,龟返回原点并清除已绘屏,

 

turtle.clear(),清除已绘屏,龟当前状态和位置不变。

 

turtle.write(argmove=Falsealign="left"font=("Arial"8"normal")),写入文本。

arg要写入的文本,move是否向右移动,align文本对齐,font字体大小,格式...元组。

 

试画下简单的图;

import turtle as t

t.home() #开始原点
t.fillcolor('violet') #填充颜色
t.penup() #拿起笔
t.begin_fill() #开始填充violet色
t.stamp() #当前位置复制龟图形
t.fd(100) #向前移100
t.setheading(90) #设置指向角度90
t.stamp()
t.fd(100)
t.lt(90) #向左转90度
t.end_fill() #结束填充
t.fillcolor('cyan')
t.stamp()
t.begin_fill()
t.fd(100)
t.lt(90)
t.stamp()
t.fd(100)
t.end_fill()
t.home()

##画另一个图
t.setpos(0,-150) #移到坐标0,-150
t.pendown() #放下笔开始绘
t.pencolor('violet') #设笔颜色
for i in range(0,24): 
    t.forward(100)
    t.left(105)
    t.stamp()

如图;

转载于:https://my.oschina.net/oisanblog/blog/1926852

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值