turtle 模塊以麵向對象和麵向過程的方式提供 turtle 圖形基元。由於它使用Tkinter作為基礎圖形,因此需要安裝有Tk支持的Python版本。
turtle .color()
此方法用於更改 turtle 的顏色。默認顏色是黑色。
用法:
turtle.color(*args)
參數:
格式 | 參數 | 描述 |
---|---|---|
turtle.color(colorstring) | 色帶 | 一串顏色名稱,例如“red”,“green”等。 |
turtle.color((r,g,b)) | (r,g,b) | 使用rgb顏色代碼的三個值r,g和b的元組 |
turtle.color(r,g,b) | r,g,b | 使用rgb顏色代碼的三個值r,g和b |
下麵是上述方法的實現和一些示例:
範例1:
Python3
# importing package
import turtle
# use forward by 50 (deault = black)
turtle.forward(50)
# change the color of turtle
turtle.color("red")
# use forward by 50 (color = red)
turtle.forward(50)
輸出:
範例2:
Python3
# importing package
import turtle
# use forward by 100 (deault = black)
turtle.forward(100)
# change the color of turtle
turtle.color("red")
# use forward by 100 in 90 degrees
# right (color = red)
turtle.right(90)
turtle.forward(100)
# change the color of turtle
turtle.color((41,41,253))
# use forward by 100 in 90 degrees
# right (color = blue)
turtle.right(90)
turtle.forward(100)
# change the color of turtle
turtle.color(41,253,41)
# use forward by 100 in 90 degrees
# right (color = green)
turtle.right(90)
turtle.forward(100)
輸出:
相關用法
- Python next()用法及代碼示例
- Python set()用法及代碼示例
- Python os.dup()用法及代碼示例
- Python Decimal exp()用法及代碼示例
- Python shutil.which()用法及代碼示例
- Python os.minor()用法及代碼示例
- Python os.sched_rr_get_interval()用法及代碼示例
- Python os.sched_get_priority_min()用法及代碼示例
- Python os.sched_setaffinity()用法及代碼示例
- Python os.sched_get_priority_max()用法及代碼示例
- Python os.sched_getaffinity()用法及代碼示例
- Python os.major()用法及代碼示例
- Python os.ftruncate()用法及代碼示例
- Python os.truncate()用法及代碼示例
- Python os.fsdecode()用法及代碼示例
- Python os.wait()用法及代碼示例
- Python sympy.div()用法及代碼示例
- Python os.setgroups()用法及代碼示例
注:本文由純淨天空篩選整理自deepanshu_rustagi大神的英文原創作品 turtle.color() method in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。