python_turtle模板畫圖,python_turtle模板

來源:互聯網
上載者:User

python_turtle模板畫圖,python_turtle模板

turtle簡單畫圖所用到的代碼:

 1 turtle.showturtle()  #畫圖板 2 turtle.screensize(2024,2000) #畫圖板大小 3 turtle.forward() #往前移動 4 turtle.right(90) #方嚮往左調整n度 5 turtle.left(30) #方嚮往右調整n度 6 turtle.write("hello") #寫文字 7 turtle.goto(50,50) #座標移動 8 turtle.penup()  #抬筆 9 turtle.pendown() #落筆10 11 turtle.circle(100) # 畫圓12 turtle.done() # 顯示不退出13 turtle.reset() # 重設14 turtle.begin_fill() #開始填充15 turtle.circle(100,steps=5)  #設定邊形16 turtle.color("red") #畫筆顏色 預設黑17 turtle.end_fill()#結束填充18 turtle.hideturtle() # 隱藏箭頭19 turtle.pensize("15") #畫筆大小20 turtle.write("hello world",font=("華文琥珀",20,"normal")) # 設定字型21 turtle.screensize(2024,2718)  #畫板大小22 turtle.dot(10,"black")# 填充圓

 下面畫一個圍棋畫板

 1 turtle.showturtle() 2 turtle.screensize(2000,2000) 3 m=20 4 for i in range (19): 5     turtle.penup() 6     turtle.goto(0,20*i) 7     turtle.pendown() 8     turtle.forward(20*18) 9 turtle.right(270)10 for i in range(19):11     turtle.penup()12     turtle.goto(20*i,0)13     turtle.pendown()14     turtle.forward(20*18)15 turtle.dot(10,"black")16 turtle.done()
View Code

國際象棋

 1 turtle.showturtle() 2 m=20 3  4 for i in range(8):  #畫多個方格位置 5     for j in range(8): 6         turtle.penup() 7         turtle.goto(i*m,j*m) 8         turtle.pendown() 9         turtle.begin_fill()10         #畫一個方格11         for k in range(4):12             turtle.forward(m)13             turtle.right(90)14         # 判斷黑白, i+j 偶數黑,奇數白15         if (i+j)%2==0:16             turtle.color("black")17         else:18             turtle.color("white")19 20         turtle.end_fill()21 22 turtle.done()
View Code

 折線圖

1 import turtle2 for i in range(0,300,100):3     for j in range (0,400,100):4         turtle.goto(j,i)5         turtle.pendown()6         turtle.write(str(i)+","+str(j))7     turtle.penup()8 9 turtle.done()
View Code

 最後畫一個正方體

 1 import  turtle 2  3 turtle.goto(200,0) 4 turtle.goto(200,200) 5 turtle.goto(0,200) 6 turtle.goto(0,0) 7  8 turtle.penup() 9 turtle.goto(100,100)10 turtle.pendown()11 12 turtle.begin_fill()13 turtle.goto(100,-100)14 turtle.goto(-100,-100)15 turtle.goto(-100,100)16 turtle.goto(100,100)17 turtle.color("red")18 turtle.end_fill()19 20 turtle.goto(200,200)21 turtle.penup()22 turtle.goto(100,-100)23 turtle.pendown()24 turtle.goto(200,0)25 turtle.penup()26 turtle.goto(-100,-100)27 turtle.pendown()28 turtle.goto(0,0)29 turtle.penup()30 turtle.goto(-100,100)31 turtle.pendown()32 turtle.goto(0,200)33 turtle.color("blue")34 turtle.write("hello Python",font=("楷體","20","normal"))35 turtle.done()
View Code

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.