【发布时间】:2015-04-10 00:14:20
【问题描述】:
为我的世界创建一个立方体的图像。 试图让盒子里的颜色自己改变。除了使用随机数之外,我还可以使用某种整数算法来实现这一点吗?因为现在,它会创建随机颜色,但我希望小盒子自己改变颜色。有任何想法吗?
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)。
标签: python colors minecraft cube turtle-graphics