コード例 #1
0
ファイル: turtle01.py プロジェクト: ScriptShef/Python-GUI
def classTurtle5():
        tr=turtle.Pen(shape='classic', undobuffersize=1000, visible=True)
        turtle.begin_fill()
        if turtle.filling():
             turtle.pensize(5)
        else:
             turtle.pensize(3)
コード例 #2
0
def fill_polygon(turtle, polygon, color):

    turtle.color(color)

    for vertex in polygon:
        turtle.goto(vertex)

        if not turtle.filling():
            turtle.begin_fill()

    turtle.end_fill()
コード例 #3
0
# 画笔运动命令:
turtle.pensize(10)  # 设置画笔的宽度
turtle.forward(100)  # 向当前画笔方向移动distance像素长
turtle.backward(50)  # 向当前画笔相反方向移动distance像素长
turtle.right(100)  # 顺时针移动 °
turtle.left(150)  # 逆时针移动 °
turtle.pendown()  # 移动时绘制图形,缺省时也为绘制
turtle.goto(10, 20)  # 将画笔移动到坐标为x,y的位置
turtle.penup()  # 移动时不绘制图形,提起笔,用于另起一个地方绘制时用
turtle.circle(50)  # 画圆,半径为正(负),表示圆心在画笔的左边(右边)画圆

# 画笔控制命令:
turtle.fillcolor('red')  # 绘制图形的填充颜色(箭头内部颜色)
turtle.color('red', '#72538e')  # 同时设置箭头颜色pencolor=color1, fillcolor=color2
turtle.filling()  # 返回当前是否在填充状态(无参数)
turtle.begin_fill()  # 准备开始填充图形(无参数)
turtle.end_fill()  # 填充完成
turtle.showturtle()  # *与hideturtle()函数对应*
turtle.hideturtle()  # 隐藏箭头显示

# 全局控制命令
turtle.clear()  # 清空turtle窗口,但是turtle的位置和状态不会改变
turtle.reset()  # 清空窗口,重置turtle状态为起始状态
turtle.undo()  # 撤销上一个turtle动作(注:无法撤销reset,clear)
turtle.isvisible()  # 返回当前turtle是否可见
# turtle.stamp()  # 复制当前图
# 三角形   (steps (optional) (做半径为radius的圆的内切正多边形,多边形边数为steps))
turtle.circle(80, steps=30)
turtle.circle(20, 80)  # 半圆
コード例 #4
0
        t.forward(b)
        t.left(360 / 30)
        
        
def half_circle(b, width):
    for i in range(30):
        t.forward(b)
        t.left(360 / 30)
    

t.shape('turtle')
t.width(1)
b = 50
t.begin_fill()
t.fillcolor('yellow')
t.filling()
t.circle(b)
t.end_fill()
t.penup()
t.left(90)
t.forward(6 * b / 4)
t.left(90)
t.forward(1.5 * b / 7)
t.right(90)
t.begin_fill()
t.fillcolor('blue')
t.filling()
t.circle(b / 10)
t.end_fill()
t.penup()
t.right(90)
コード例 #5
0
#pensize()函数主要用来设置画笔的粗细
turtle.pensize(10)
turtle.fd(100)
turtle.pensize(1)
turtle.fd(100)

#color函数用来设置画笔的颜色
turtle.color("red")
turtle.fd(100)

#begin_fill函数用;来填充一定的颜色,它必须和end_fill混合使用才会有效
turtle.begin_fill()
turtle.color("red")
turtle.circle(100)
print(turtle.filling())  #在填充的过程中是填充的状态,所以输出应该为true
turtle.end_fill()
print(turtle.filling())  #画结束之后输出为false
#filling函数的功能是返回填充的状态,true或者false

#clear()函数主要用来清空当前画布的图,但是并不改变画笔当前的位置,只保留下画笔当前的位置
#turtle.clear()

#reset函数主要用来直接恢复画布的状态为最原始的默认状态,即进行状态的重置
#turtle.reset()

#screensize()  重新设置画布的长度和宽度
turtle.screensize(2000, 2000)

#hideturtle画图之后总是存在小箭头,可以隐藏小箭头,showturtle可以展示出小箭头
turtle.fd(100)
コード例 #6
0
ファイル: TurtlePractice.py プロジェクト: CoreSheep/python
2.2 pen movement
'''
t.penup()  # alias pu() and up()
t.pendown()  # alias pd() and down()
t.forward(10)  # alias fd()
t.backward(10)  # alias bd()
t.right(10)  # right(radian) alias rt() for right()
t.left(10)  # left(radian)  alias lt() for left()
t.goto(5, 5)  # goto(x, y)    alias setpos() and setposition() for goto()
t.circle(100, 360, 50)  # circle(radius, radian=360, step=0)
# The center is radius units left of the turtle
'''
2.3 pen controller
'''
t.fillcolor('yellow')
t.color('red', 'yellow')  # pencolor() and fillcolor()
t.filling()  # Is current state a filling state?
t.begin_fill()  # begin to fill
t.end_fill()  # end fill
t.hideturtle()  # alias ht() make the arrow of the turtle invisible
t.showturtle()  # alias st() make the arrow of the turtle visible
'''
2.4 global control command
'''
t.clear()  # clear windows but perverse current state of turtle
t.reset()  # clear windows and reset turtle state
t.undo()  # undo last operation
t.isvisible()  # return
# stamp()       # copy current graphics
t.done()  # end turtle
コード例 #7
0
	turtle.circle(5*i)
	turtle.left(10)

	
>>> turtle.reset()
>>> turtle.color('red')
>>> turtle.speed(0)
>>> for i in range(50):
	turtle.circle(5*i)
	turtle.left(10)

	
>>> turtle.fillcolor('green')
>>> turtle.reset()
>>> turtle.color('red')
>>> turtle.fillcolor('green')
>>> turtle.speed(0)
>>> for i in range(50):
	turtle.circle(5*i)
	turtle.left(10)

	
>>> turtle.filling('yellow')
Traceback (most recent call last):
  File "<pyshell#87>", line 1, in <module>
    turtle.filling('yellow')
TypeError: filling() takes 0 positional arguments but 1 was given
>>> turtle.filling()
False
>>> 
コード例 #8
0
turtle.fillcolor("#ff6100")
turtle.fillcolor((0,255,0))
turtle.fillcolor(0,0,255)

# Returns or sets the pen and fill color
# Accepts the same arguments and pencolor
turtle.color()
turtle.color("blue") #sets both pen and fill color
turtle.color((255,0,0),(0,255,0)) #sets pen color first, then fill color second

# ------------------------------------------

#Fill

# Returns the fill state (True if there is fillig, False if not)
turtle.filling()

# Is called before drawing a shape that is going to be filled
turtle.begin_fill()

# Fills the shape rawn after the last begin_fill call
turtle.circle(100)
turtle.end_fill()

# ---------------------------------------------

#Drawing Control

# Resets canvas and turtle
turtle.reset()