mtrx = pi3d.matrix() rot=0.0 rot1=0.0 rot2=0.0 #create a light mylight = pi3d.createLight(0,1,1,1,"",10,10,50, .8,.8,.8) # Display scene while 1: display.clear() mylight.off() pi3d.sprite(starsimg, 0,0,-20, 25,25,rot) rot=rot+0.02 mylight.on() mtrx.identity() mtrx.translate(0,0,-6) mysphere.draw(earthimg) mysphere.rotateIncY( 0.1 ) mysphere2.draw(cloudimg) mysphere2.rotateIncY( .2 ) mtrx.rotate(0,0,10) mtrx.rotate(0,rot1,0) mtrx.translate(4,0,0) mymoon.draw(moonimg) mymoon.rotateIncY( 0.2 ) mtrx.rotate(30,0,0)
ball.append(pi3d.load_textureAlpha("Textures/grn_ball.png")) ball.append(pi3d.load_textureAlpha("Textures/blu_ball.png")) bar = pi3d.load_texture("Textures/bar.png") bbtitle = pi3d.load_textureAlpha("Textures/pi3dbbd.png") camera = pi3d.camera() camera.orthographic(0, scnx, 0, scny) while True: display.clear() for b in range (0, maxballs): # Draw ball (tex,x,y,z,width,height,rotation) pi3d.sprite(ball[bi[b]],bx[b],by[b],-1,bs[b],bs[b]) # Increment ball positions bx[b]=bx[b]+dx[b] by[b]=by[b]+dy[b] # X coords outside of drawing area? Then invert X direction if bx[b]>scnx or bx[b]<0: dx[b]=-dx[b] # Y coords outside of drawing area? Then invert Y direction if by[b]>scny or by[b]<0: dy[b]=-dy[b] #draw a bar at the top of the screen pi3d.rectangle(bar,0,scny-32,scnx,32)
raspimg = pi3d.loadTextureAlpha("textures/Raspi256x256.png") pino=20 # 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 = pi3d.key() # Display scene and rotate cuboid while 1: display.clear() for b in range (0, pino): pi3d.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==112: display.screenshot("raspberryRain.jpg") display.swapBuffers()
mykeys = pi3d.key() 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] pi3d.sprite(clouds[c[3]], c[0], c[1], -c[2], 8, 5) #Press ESCAPE to terminate if mykeys.read() == 27: display.destroy() mykeys.close() break display.swapBuffers() time.sleep(0.01)
mtrx = pi3d.matrix() rot = 0.0 rot1 = 0.0 rot2 = 0.0 #create a light mylight = pi3d.createLight(0, 1, 1, 1, "", 10, 10, 50, .8, .8, .8) # Display scene while 1: display.clear() mylight.off() pi3d.sprite(starsimg, 0, 0, -20, 25, 25, rot) rot = rot + 0.02 mylight.on() mtrx.identity() mtrx.translate(0, 0, -6) mysphere.draw(earthimg) mysphere.rotateIncY(0.1) mysphere2.draw(cloudimg) mysphere2.rotateIncY(.2) mtrx.rotate(0, 0, 10) mtrx.rotate(0, rot1, 0) mtrx.translate(4, 0, 0) mymoon.draw(moonimg) mymoon.rotateIncY(0.2) mtrx.rotate(30, 0, 0)
def drawCloud(c, xx,zz): zzz=(zz+c[2]) % cloud_depth xxx=(xx+c[0]) pi3d.sprite(clouds[c[3]], xxx,c[1],-zzz,8,5)
scshots = 1 print balls[0].x, balls[0].vx while True: display.clear() for b in range (0,len(balls)): #if balls[b].vx<>0.0 or balls[b].vy<>0.0: #check collisions with other balls and bounce if necessary for c in range (b+1,len(balls)): balls[b].collisionBounce(balls[c]) balls[b].x += balls[b].vx balls[b].y += balls[b].vy #check if ball hits wall if balls[b].x>scnx or balls[b].x<0.0: balls[b].vx = -balls[b].vx if balls[b].y>scny or balls[b].y<0.0: balls[b].vy = -balls[b].vy pi3d.sprite(balltex[0],balls[b].x,balls[b].y,-1,balls[b].radius,balls[b].radius) k = mykeys.read() if k >-1: if k==27: display.destroy() mykeys.close() break if k==112: display.screenshot("collisionballs.jpg") display.swapBuffers()
ball.append(texs.loadTexture("textures/blu_ball.png")) bar = texs.loadTexture("textures/bar.png") bbtitle = texs.loadTexture("textures/pi3dbbd.png", True) # Fetch key presses mykeys = pi3d.key() scshots = 1 while True: display.clear() for b in range(0, maxballs): # Draw ball (tex,x,y,z,width,height,rotation) pi3d.sprite(ball[bi[b]], bx[b], by[b], -2.0, bs[b], bs[b]) # Increment ball positions bx[b] = bx[b] + dx[b] by[b] = by[b] + dy[b] # X coords outside of drawing area? Then invert X direction if bx[b] > scnx or bx[b] < 0: dx[b] = -dx[b] # Y coords outside of drawing area? Then invert Y direction if by[b] > scny or by[b] < 0: dy[b] = -dy[b] #draw a bar at the top of the screen pi3d.rectangle(bar, 0, scny, scnx, 32)
def drawCloud(c, xx, zz): zzz = (zz + c[2]) % cloud_depth xxx = (xx + c[0]) pi3d.sprite(clouds[c[3]], xxx, c[1], -zzz, 8, 5)
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] pi3d.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)
# 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 = pi3d.key() # Display scene and rotate cuboid while 1: display.clear() for b in range(0, pino): pi3d.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:
) z = z + zd zc = 0 # Fetch key presses mykeys = pi3d.key() while True: display.clear() z = (z + (cloud_depth - speed)) % cloud_depth zc = (zc + (cloudno - 1)) % cloudno # attempts to resolve z-sorting of clouds for d in range(zc, cloudno): pi3d.sprite(clouds[cxyz[d][3]], x + cxyz[d][0], cxyz[d][1], -((z + cxyz[d][2]) % cloud_depth), 8, 5) for d in range(0, zc): pi3d.sprite(clouds[cxyz[d][3]], x + cxyz[d][0], cxyz[d][1], -((z + cxyz[d][2]) % cloud_depth), 8, 5) # Press ESCAPE to terminate if mykeys.read() == 27: display.destroy() mykeys.close() break display.swapBuffers() time.sleep(0.01)