如果不使用其他匯入,則相當簡單:turtle.colormode(255) # sets the color mode to rgb
r = random.randrange(0, 256, 100) # last value optional (step)
b = random.randrange(0, 256)
g = random.randrange(0, 256)
# using step allows more control if needed
# for example the value of `100` would return `0`, `100` or `200` only
rocket.color(r, g, b) ## randomized from values above
使用隨機值(200,255,23):
to rocket.colormode() for the next one?"
我建議的方法是建立乙個函式:
^$這樣,您可以隨時呼叫drawcolor()來選擇新顏色。在
現在你已經掌握了為你的繪圖隨機顏色的基本知識,你可以很有創意地為一些好看的結果設定值(根據你的喜好調整整數):
import turtle, math, random, time
def drawcolor(a, b, o):
turtle.colormode(255)
r = random.randrange(a, b, o) # last value is step (optional)
b = random.randrange(a, b, o)
g = random.randrange(a, b, o)
# print(r, g, b)
return r, g, b
def drawrocket(offset):
rocket = turtle.turtle()
rocket.speed(0)
rocket.color(drawcolor(20, 100, 1)) # start (0-256), end (0-256), offset
rotate=int(random.randrange(90))
drawspecial(rocket,random.randrange(0, 10), offset)
def drawcircles(t,size):
for i in range(30):
t.circle(size)
size = size - 20
def drawspecial(t,size,repeat):
for i in range(repeat):
drawcircles(t,size)
t.right(360/repeat)
def drawmain(x, y):
wn = turtle.screen()
wn.bgcolor(drawcolor(0, 20, 2))
for i in range(3): # iterations
drawrocket(x)
x+=y
# print(x)
drawmain(2, 10) # offset, step
input("press enter to exit")
jquery ul li值怎麼增加背景顏色
兩種方法 1 用css 設定背景屬性,語法 ul li css background 顏色值 2 用attr 添背景樣式,語法 ul li attr style background 顏色值 本教程操作環境 windows7系統 jquery1.10.2版本 dell g3電腦。jquery ul ...
python換行符怎麼鍵入 python 如何鍵入
python中的三種鍵入方式 python2.x python2.x中以下三個函式都支援 1 raw input 2 input 3 sys.stdin.readline raw input 將所有輸入作為字串看待,返回字串型別 input 只能接收 數字 的輸入,返回所輸入的數字的型別 int,f...
pdf檔案怎麼編輯文件中背景的顏色
想要編輯pdf檔案怎麼辦?很顯然直接開啟pdf檔案編輯是不可能實現的,我們要麼將pdf檔案轉換成其他可編輯的格式,要麼用pdf編輯器來完成pdf檔案的編輯。今天要跟大家分享的就是用pdf編輯器來編輯pdf檔案的方法。捷速pdf編輯器,支援修改編輯pdf檔案並向pdf新增文字 擦除內容 插入 繪製直線...