python中turtle模組之畫個小汽車
阿新 • • 發佈:2019-01-03
</pre><pre name="code" class="python">#!/usr/bin/python #coding: utf-8 import turtle import time t = turtle.Pen() def fun1(t, x, y): t.forward(x) t.left(y) def fun2(t, x, y): t.forward(x) t.right(y) ''' color函式有三個引數 第一個引數指定有多少紅色 第二個引數指定有多少綠色 第三個引數指定有多少藍色 都為0的時候此時為黑色 都為1的時候此時為白色 這種紅色,綠色,藍色的混搭叫做RGB 藍色和紅色混合產生紫色 黃色和紅色混合產生橙色 ''' t.color(1, 0, 0) t.begin_fill() fun1(t, 100, 90) fun1(t, 20, 90) fun2(t, 20, 90) fun1(t, 20, 90) fun1(t, 60, 90) fun2(t, 20, 90) fun1(t, 20, 90) t.forward(20) t.end_fill() time.sleep(3) t.color(0, 0, 0) t.up() t.forward(10) t.down() # 開始位置 t.begin_fill() # 畫圓 t.circle(10) # 結束位置 t.end_fill() # 設定當前的指定角度為0度 t.setheading(0) t.up() t.forward(90) t.right(90) t.forward(10) t.setheading(0) t.down() t.begin_fill() t.circle(10) t.end_fill() time.sleep(2)