天天看点

海龟画图进阶操作

import turtle as t
# t.fd(100)
# t.dot(100,"purple")#dot(size,(rgb)或者颜色字符串)
# t.done()
# t.fd(100)
# t.stamp()#记录下turtle的头部位置ID,并在图上打印出来,turtle的头部
# t.fd(100)
# t.done()
#t.bgcolor("orange")#窗口控制,设置背景的颜色
# with open(r"C:\Users\MI\Desktop\y.jpg","rb+") as f:
#     y = f.read()
t.title("江西理工大学")#设置画窗的的标题
t.bgpic(r"C:\Users\MI\Desktop\tt.gif")#bgpic(picname),背景图片一定要是GIF
# t.penup()
t.speed(3)#1-3-6-10速度是逐渐增加的,然后0是最快
t.penup()
t.color('purple','red')
t.goto(50,50)#绝对位移,乌龟的头部始终保持着向右方向
t.pendown()
#t.write("江西理工大学",move = False,align="left",font=("Arial",8,"normal"))#write(string,move =False,align = "left"/"right"/"center,font = ("字体",字号,“字体的名字”))
#t.hideturtle()#隐藏海龟头,绘画的速度更快
#t.showturtle()#展示海龟头,省略写t.st()
t.Shape('polygon',((-1,1),(-1,0),(0,1),(0,0)))
t.begin_fill()#begin_fill(),t.fillcolor(),end_fill()填充颜色
t.fillcolor('yellow')
t.left(180)
for i in range(4):
    t.fd(100)
    t.left(90)
t.end_fill()
#获取海龟的转态
print(t.pos())#返回位置的坐标
print(t.xcor())#返回x坐标
print(t.ycor())#返回y坐标
#colormode()#设置颜色数码,设置255,设置1
#print(t.towards(0,0))#t.towards(x,y)起始位置到(x,y)矢量位置
#print(t.heading())#放回海龟朝向的相对角度
#print(t.distance())#返回起始点到(x,y)距离
# t.radians();
# print(t.heading());#设置的角度为弧度
# t.pendown()
# t.left(90)
# for i in range(4):
#     t.fd(200)
#     t.left(90)
#t.goto(100,100)#goto(x,y)直接跳到某个位置,并且头部的位置始终保持着向右的趋势,头部并不改变方向
#print(t.towards(0,0))#t.towards(x,y)起始位置到(x,y)矢量位置

# t.setworldcoordinates(20, -20, 40, 40)#设置画布
# t.screensize(10,4,"purple")
t.done()
#split(str='',mum=string.count(str))默认是切割某个字符片段,如果第一个参数没写的话,默认切割空格,/n,以及/t,切割次数为num,如果省略的话就是就是全部切割split[-1]