# 繪製燈箱
turtle.pensize(5)
turtle.forward(100)
turtle.left(90)
turtle.forward(200)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(200)
turtle.left(90)
# 繪製第乙個燈,紅燈
turtle.penup()
turtle.goto(50,200-35)
turtle.pendown()
turtle.dot(50,"red")
# 繪製第二個燈,黃燈
turtle.penup()
turtle.goto(50,200-95)
turtle.pendown()
turtle.dot(50,"yellow")
# 繪製第三個燈,綠燈
turtle.penup()
turtle.goto(50,200-155)
turtle.pendown()
turtle.dot(50,"green")
# 寫字
turtle.penup()
turtle.goto(0,-60)
turtle.pendown()
turtle.write("交通燈",font=("arial",20,"normal"))
turtle.hideturtle()
turtle.done()
繼續優化,可以加上倒計時,模擬十字路口,紅燈停綠燈行黃燈等一等的效果
import turtle
import time
turtle.speed(0)
turtle.hideturtle()
# 寫字
turtle.penup()
turtle.goto(0,-60)
turtle.pendown()
turtle.write("交通燈",font=("arial",20,"normal"))
turtle.penup()
turtle.goto(0,0)
turtle.pendown()
# 繪製燈箱
turtle.pensize(5)
turtle.forward(100)
turtle.left(90)
turtle.forward(200)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(200)
turtle.left(90)
# 繪製第乙個燈,紅燈
turtle.penup()
turtle.goto(50,200-35)
turtle.pendown()
turtle.dot(50,"red")
# 等待5秒,紅燈滅
time.sleep(5)
turtle.penup()
turtle.goto(50,200-35)
turtle.pendown()
turtle.dot(50,"white")
# 繪製第二個燈,黃燈
turtle.penup()
turtle.goto(50,200-95)
turtle.pendown()
turtle.dot(50,"yellow")
# 等待2秒,黃燈滅
time.sleep(3)
turtle.penup()
turtle.goto(50,200-95)
turtle.pendown()
turtle.dot(50,"white")
# 繪製第三個燈,綠燈
turtle.penup()
turtle.goto(50,200-155)
turtle.pendown()
turtle.dot(50,"green")
turtle.done()
Windows程式設計 直線繪製
windiows程式設計中繪製直線的重要函式 moveto 函式 線段的起點位置 lineto 線段的終點位置 引數如下 bool movetoex in hdc hdc,視窗控制代碼 in int x,畫素x座標 in int y,畫素y座標 out lppoint lppoint 傳入之前的座標...
C 高階程式設計 繪製文字
這個示例 displaytext 是常見的 windows forms 這次重寫了 onpaint 新增了成員字段,如下所示 執行這個示例,會得到如圖 20 15 所示的結果。這個示例說明了如何使用 graphics.drawstring 方法繪製文字,drawstring 有許多過載方法,這裡介紹...
Python語言程式設計 蟒蛇繪製
python蟒蛇繪製 import turtle as t t.setup 650,350,200,200 t.penup penup 畫筆抬起 t.fd 250 fd 沿著海龜的前方向執行 t.pendown 畫筆落下 t.pensize 25 畫筆大小 t.pencolor purple pen...