1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| import pygame,math,time
import numpy as np
import random
RED=(255,0,0)
GREEN=(0,255,0)
BLUE=(0,0,255)
BLACK=(0,0,0)
GRAY=(128,128,128)
WHITE=(255,255,255)
YELLOW=(0,255,255)
pygame.init()
fond=pygame.image.load("fond.jpg")
de11=pygame.image.load("des11.jpg")
de12=pygame.image.load("des12.jpg")
de13=pygame.image.load("des13.jpg")
de14=pygame.image.load("des14.jpg")
de15=pygame.image.load("des15.jpg")
de16=pygame.image.load("des16.jpg")
sizeim=fond.get_size()
size=(sizeim[0],sizeim[1])
screen = pygame.display.set_mode(size)
def drawFace(screen,face,color=(0,0,255),echelle=200,centre=(512,400)):
npoints=face.shape[0]
for i in range(0,npoints-1):
pygame.draw.aaline(screen, color, \
(centre[0]+echelle*face[i,0]/face[i,2], centre[1]-echelle*face[i,1]/face[i,2]), \
(centre[0]+echelle*face[i+1,0]/face[i+1,2], centre[1]-echelle*face[i+1,1]/face[i+1,2]))
pygame.draw.aaline(screen, color, \
(centre[0]+echelle*face[npoints-1,0]/face[npoints-1,2], centre[1]-echelle*face[npoints-1,1]/face[npoints-1,2]), \
(centre[0]+echelle*face[0,0]/face[0,2], centre[1]-echelle*face[0,1]/face[0,2]))
def cube(L):
faceA=np.matrix([[float(L)/2,-float(L)/2,float(L)/2],[float(L)/2,float(L)/2,float(L)/2],[float(L)/2,float(L)/2,-float(L)/2],[float(L)/2,-float(L)/2,-float(L)/2]])
faceB=np.matrix([[float(L)/2,float(L)/2,float(L)/2],[-float(L)/2,float(L)/2,float(L)/2],[-float(L)/2,float(L)/2,-float(L)/2],[float(L)/2,float(L)/2,-float(L)/2]])
faceC=np.matrix([[float(L)/2,-float(L)/2,float(L)/2],[float(L)/2,float(L)/2,float(L)/2],[-float(L)/2,float(L)/2,float(L)/2],[-float(L)/2,-float(L)/2,float(L)/2]])
faceD=(-1)*faceA
faceE=(-1)*faceB
faceF=(-1)*faceC
return [faceA, faceB, faceC, faceD, faceE, faceF]
def translation(face, dx, dy,dz):
X=np.matrix([[dx,0,0],[dx,0,0],[dx,0,0],[dx,0,0]])
Y=np.matrix([[0,dy,0],[0,dy,0],[0,dy,0],[0,dy,0]])
Z=np.matrix([[0,0,dz],[0,0,dz],[0,0,dz],[0,0,dz]])
T=X+Y+Z
return face+T
def rotationz(point,a):
M=[[math.cos(a),math.sin(a),0],[-math.sin(a),math.cos(a),0],[0,0,1]]
R=(point)*M
return R
def rotationx(point,a):
M=[[1,0,0],[0,math.cos(a),math.sin(a)],[0,-math.sin(a),math.cos(a)]]
R=(point)*M
return R
def rotationy(point,a):
M=[[math.cos(a),0,math.sin(a)],[0,1,0],[-math.sin(a),0,math.cos(a)]]
R=(point)*M
return R
def rotationface(face,a):
for k in range(0,4) :
face[k]=rotation(face[k],a)
return [face[0],face[1],face[2],face[3]]
def lancedes():
running=1
a=1
b=0
c=0
while running:
if a>0 :
event = pygame.event.poll()
if event.type == pygame.QUIT:
running = 0
screen.fill((0, 0, 0))
t=time.time()
screen.blit(fond,(0,0))
drawFace(screen,translation(rotationx(rotationy(rotationz(cube(2)[0],5*t),5*t),0),18,25,20),BLACK)
drawFace(screen,translation(rotationx(rotationy(rotationz(cube(2)[1],5*t),5*t),0),18,25,20),BLACK)
drawFace(screen,translation(rotationx(rotationy(rotationz(cube(2)[2],5*t),5*t),0),18,25,20),BLACK)
drawFace(screen,translation(rotationx(rotationy(rotationz(cube(2)[3],5*t),5*t),0),18,25,20),BLACK)
drawFace(screen,translation(rotationx(rotationy(rotationz(cube(2)[4],5*t),5*t),0),18,25,20),BLACK)
drawFace(screen,translation(rotationx(rotationy(rotationz(cube(2)[5],5*t),5*t),0),18,25,20),BLACK)
drawFace(screen,translation(rotationx(rotationy(rotationz(cube(2)[0],5*t),5*t),0),25,25,20),BLACK)
drawFace(screen,translation(rotationx(rotationy(rotationz(cube(2)[1],5*t),5*t),0),25,25,20),BLACK)
drawFace(screen,translation(rotationx(rotationy(rotationz(cube(2)[2],5*t),5*t),0),25,25,20),BLACK)
drawFace(screen,translation(rotationx(rotationy(rotationz(cube(2)[3],5*t),5*t),0),25,25,20),BLACK)
drawFace(screen,translation(rotationx(rotationy(rotationz(cube(2)[4],5*t),5*t),0),25,25,20),BLACK)
drawFace(screen,translation(rotationx(rotationy(rotationz(cube(2)[5],5*t),5*t),0),25,25,20),BLACK)
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONUP :
a=0
else : pass
else :
b=random.randint(1,6)
c=random.randint(1,6)
if 0<b<2 : screen.blit(de11,(650,120))
if 1<b<3 : screen.blit(de12,(650,120))
if 2<b<4 : screen.blit(de13,(650,120))
if 3<b<5 : screen.blit(de14,(650,120))
if 4<b<6 : screen.blit(de15,(650,120))
if 5<b : screen.blit(de16,(650,120))
if 0<c<2 : screen.blit(de11,(730,120))
if 1<c<3 : screen.blit(de12,(730,120))
if 2<c<4 : screen.blit(de13,(730,120))
if 3<c<5 : screen.blit(de14,(730,120))
if 4<c<6 : screen.blit(de15,(730,120))
if 5<c : screen.blit(de16,(730,120))
running=0
pygame.display.flip ()
print lancedes |
Partager