pino=10 # Setup array of random x,y,z coords and initial rotation xyz=[] for b in range (0, pino): xyz.append((random.random()*8-4,random.random() * 8,random.random() * 4 + 3, random.random() * 360)) # Fetch key presses mykeys = Keyboard() # Display scene and rotate cuboid while 1: display.clear() for b in range (0, pino): Draw.sprite(raspimg,xyz[b][0],5-xyz[b][1],-xyz[b][2],1,1,xyz[b][3]) #draw a rectangle(x,y,z,scaleX,scaleY,rotation) r = xyz[b][3]+1 y = (xyz[b][1]+0.1) % 10 if y<0.06: xyz[b] = ((random.random()*8-4, y, xyz[b][2], r)) else: xyz[b] = ((xyz[b][0], y, xyz[b][2], r)) k = mykeys.read() if k >-1: if k==27: mykeys.close() texs.deleteAll() display.destroy() break elif k==112:
while True: display.clear() maxDepth = 0 axDepthIndex = 0 # this is easier to understand, the z position of each cloud is (only) held in cxyz[][2] # it stops the clouds appearing in front of nearer clouds! # first go through the clouds to find index of furthest away for i in range(len(cxyz)): cxyz[i][2] = (cxyz[i][2] - speed) % cloud_depth if (cxyz[i][2] > maxDepth): maxDepth = cxyz[i][2] maxDepthIndex = i # paint the clouds from background to foreground for i in range(maxDepthIndex, maxDepthIndex + cloudno): c = cxyz[i%cloudno] Draw.sprite(clouds[c[3]], c[0], c[1], -c[2], 8, 5) #Press ESCAPE to terminate if mykeys.read() == 27: mykeys.close() texs.deleteAll() display.destroy() break display.swapBuffers() time.sleep(0.01)