天天看點

海龜畫圖進階操作

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]