日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python之 turtle好例子集锦

發(fā)布時(shí)間:2023/12/9 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python之 turtle好例子集锦 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

python好之turtle例子集錦

這些程序大多取自或借鑒網(wǎng)上源碼,整理在此,便于初學(xué)者借鑒,提高學(xué)習(xí)興趣。包括:風(fēng)車動(dòng)畫、小轎車、新年賀卡、動(dòng)態(tài)賀卡

一、風(fēng)車動(dòng)畫

效果圖如下:

源代碼如下:

import turtle as tt.pensize(2) t.hideturtle() windSpeed = 2 radius = 50def windmill(c):t.pencolor(c)t.tracer(False) #隱藏繪制軌跡,之后用update()直接出圖for i in range(4):t.forward(2*radius)t.right(90)t.circle(-radius,180)while True:windmill('red')t.update() #刷新圖畫windmill('white') #在此用背景色白色重繪風(fēng)車,以此清除之前的黑色軌跡t.right(windSpeed)t.done()

二、小轎車

源碼如下:

import turtle as t #車身 t.penup() t.goto(-130,0) t.pencolor("red") t.pendown() t.goto(-75,0) t.penup() t.goto(-25,0) t.pendown() t.pencolor("red") t.goto(50,0) t.penup() t.goto(100,0) t.pendown() t.pencolor("red") t.goto(125,0) t.color("red") t.begin_fill() t.goto(125,40) t.goto(120,40) t.goto(65,70) t.goto(-40,70) t.goto(-75,40) t.goto(-105,40) t.goto(-130,0) t.end_fill()#輪 t.penup() t.goto(-50,-25) t.color("black") t.begin_fill() t.pendown() t.circle(25) t.end_fill() t.penup() t.goto(75,-25) t.color("black") t.begin_fill() t.pendown() t.circle(25) t.end_fill()#門 t.penup() t.pensize(4) t.goto(-40,65) t.pendown() t.pencolor("black") t.color("blue") t.begin_fill() t.goto(-65,40) t.goto(65,40) t.goto(65,65) t.goto(-40,65) t.end_fill() t.penup() t.goto(15,65) t.pendown() t.pencolor("black") t.goto(15,5) t.penup() t.goto(-65,40) t.pendown() t.goto(-65,5) t.goto(15,5) t.goto(65,5) t.goto(65,40) t.penup() t.goto(0,30) t.pendown() t.goto(30,30) t.pensize(2)#標(biāo)志 t.penup() t.goto(-105,40) t.pencolor("black") t.pendown() t.goto(-105,5) t.goto(-125,5) t.goto(-110,5) t.goto(-110,30) t.penup() t.goto(-115,5) t.pendown() t.goto(-115,23) t.penup() t.goto(126,20) t.color("black") t.begin_fill() t.pendown() t.goto(100,20) t.goto(100,0) t.goto(126,0) t.goto(126,20) t.end_fill()#燈 t.penup() t.goto(-100,16) t.pendown() t.color("orange") t.begin_fill() t.circle(12,-180) t.goto(-100,16) t.end_fill() t.penup() t.goto(110,43) t.pendown() t.color("orange") t.begin_fill() t.circle(11,-180) t.goto(110,43) t.end_fill()t.hideturtle() t.done()

三、新年賀卡

效果圖如下:

?源代碼如下:

import turtle as t t.color("red") t.write("萬\n事\n大\n吉", font=("華文行楷", 45, "normal")) t.penup() t.goto(80,0) t.pendown() t.write("新\n年\n快\n樂", font=("華文行楷", 45, "normal"))t.penup() t.goto(-120,110) t.pendown() t.write("李\n一\n民\n賀", font=("方正舒體", 20, "normal"))t.penup() t.goto(-130,0) t.color("red") t.pendown() t.begin_fill() t.forward(55) t.left(90) t.forward(55) t.left(90) t.forward(55) t.left(90) t.forward(55) t.left(90) t.end_fill()t.color("white") t.penup() t.goto(-100,0) t.pendown() t.write("萬\n事", font=("華文隸書", 20, "normal")) t.penup() t.goto(-130,0) t.pendown() t.write("如\n意", font=("華文隸書", 20, "normal"))t.done()

四、動(dòng)態(tài)賀卡

效果圖

源碼如下

import turtle as T import random import timet = T.Turtle()w = T.Screen() t.hideturtle() t.getscreen().tracer(5, 0) w.screensize(bg='maroon') t.left(90) t.up() t.forward(280) t.down() t.pensize(3)n=100 t.color("orange","yellow") t.begin_fill() t.left(126)for i in range(5):t.forward(n/5)t.right(144)t.forward(n/5)t.left(71) t.end_fill() t.left(60) t.pensize(8) t.forward(60) t.right(20) t.right(116) t.pensize(6)t.color('dark green') n=130for i in range(6):time.sleep(0.5)a=1+i/2t.begin_fill()t.left(90)t.forward(n*a*0.707)t.left(135)t.forward(n*a)t.left(135)t.forward(n*a*0.707)t.end_fill()t.up()t.left(90)t.forward(n*a*0.707/3)t.left(135)t.forward(n*a/6)t.left(135)t.down()t.up() t.right(135) t.forward(30) t.right(90) t.forward(157) t.down() t.color('saddlebrown') t.begin_fill() t.forward(80) t.right(90) t.forward(45) t.right(90) t.forward(80) t.right(90) t.forward(45) t.end_fill()t.up() t.backward(45) t.right(90) t.backward(470) t.down()def light(l,t):t.pensize(3)colors = ["magenta","darkorange","red","blue"]for i in range(l):time.sleep(0.2)b = 70+16*ia = b/2*random.randint(-100,100)/100t.up()t.forward(b)t.left(90)t.forward(a)t.down()t.color("lightyellow",colors[i%4])t.begin_fill()t.circle(10)t.end_fill()t.up()t.backward(a)t.right(90)t.backward(b)t.down()t.pensize(1)def snow(m,t):for i in range(m):a = 400 - 800 * random.random()b = 600 - 800 * random.random()t.up()t.forward(b)t.left(90)t.forward(a)t.down()t.color('white')t.begin_fill()t.circle(1)t.end_fill()t.up()t.backward(a)t.right(90)t.backward(b)light(24,t) snow(600, t)t.goto(-200,200) my_word = ("Merry Christmas") t.write(my_word,font=("Edwardian Script ITC",40,"bold")) time.sleep(0.3) t.goto(-100,50) my_word = ("and") t.write(my_word,font=("Edwardian Script ITC",50,"bold")) time.sleep(0.3) t.goto(-150,-100) my_word = ("Happy New Year") t.write(my_word,font=("Edwardian Script ITC",40,"bold"))

總結(jié)

以上是生活随笔為你收集整理的python之 turtle好例子集锦的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。