爲我的世界創建一個立方體的圖像。 試圖讓盒子裏的顏色自己改變。有什麼樣的整數算法,我可以用來實現這一點,除了使用隨機?因爲現在它會產生隨機顏色,但我希望小盒子能夠自己改變顏色。有任何想法嗎?Python龜,如何讓顏色自己改變?
import turtle
import random
minecraft = turtle.Turtle()
minecraft.ht()
minecraft.speed(9999999999999) #I guess there is a max speed??? wanted it to make the mini cubes a lot faster.
#centers the box
minecraft.up()
minecraft.goto(-50,50)
minecraft.down()
#end of center box
for i in range(4): #Creates the box
minecraft.forward(100)
minecraft.right(90)
for i in range(1000): #Repeats all this code over and over
for i in range(10): #makes the 10 cubes going down, then it comes back up and repeates making cubes until it gets to the last cube.
for i in range(10): #initiate the random colors
red = random.random()
blue = random.random()
yellow = random.random()
minecraft.color(red, blue, yellow)
for i in range(1): #the little boxes
minecraft.begin_fill()
minecraft.forward(10)
minecraft.right(90)
minecraft.forward(10)
minecraft.right(90)
minecraft.forward(10)
minecraft.right(90)
minecraft.forward(10)
minecraft.right(90)
minecraft.end_fill()
minecraft.right(90) #little boxes changing directions
minecraft.forward(10)
minecraft.right(-90)
minecraft.forward(10) #little boxes changing directions...again
minecraft.right(-90)
minecraft.forward(100)
minecraft.right(90)
minecraft.right(180) #and again...
minecraft.forward(100)
minecraft.right(180)
海龜的速度數字有點奇怪。速度0是最快的,但是他們從1最慢,2更快一點,6是正常速度,等到10快。任何高於10或低於0.5的數字都將轉換爲0.請參閱'help(turtle.speed)'。 – 2015-02-10 03:51:57