This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RubiksCube.py
611 lines (460 loc) · 21.3 KB
/
RubiksCube.py
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
from PIL import Image
import random
def cube(x=0, y=0, z=0, size=10): # fonction de création de cube, coordonnées de base (0, 0, 0) et taille de base (10)
sq_x = np.array([x, x, x + size, x + size, x, x, x + size, x + size])
sq_y = np.array([y, y + size, y + size, y, y, y + size, y + size, y])
sq_z = np.array([z, z, z, z, z + size, z + size, z + size, z + size])
sq_w = np.array([1, 1, 1, 1, 1, 1, 1, 1])
cube = np.array([sq_x, sq_y, sq_z, sq_w])
return cube
def get_points(figure): # permet de recuperer les coordonées des angles d'un cube
points = []
for i in range(len(figure[0])):
points.append([figure[0][i], figure[1][i], figure[2][i]])
return points
def aggrandissement_reduc(figure, val): # fonction de modification de taille d'un cube
sq_tx = np.array([val, 0, 0, 0])
sq_ty = np.array([0, val, 0, 0])
sq_tz = np.array([0, 0, val, 0])
sq_tw = np.array([0, 0, 0, 1])
array_ar = np.array([sq_tx, sq_ty, sq_tz, sq_tw])
result = np.matmul(array_ar, figure)
return result
def translation3D(figure, tx, ty, tz): # translation d'un objet 3d
sq_tx = np.array([1, 0, 0, tx])
sq_ty = np.array([0, 1, 0, ty])
sq_tz = np.array([0, 0, 1, tz])
sq_tw = np.array([0, 0, 0, 1])
array_t = np.array([sq_tx, sq_ty, sq_tz, sq_tw]) # matrice de deplacement
result = np.matmul(array_t, figure) # multiplication de la matrice de l'objet et de la matrice de rotation
return result
def rotation3D_x(figure, teta, deplacement_y=0, deplacement_z=0): # rotation d'un objet 3d sur l'axe x
xr = np.array([1, 0, 0, 0])
yr = np.array([0, np.cos(teta), -np.sin(teta), 0])
zr = np.array([0, np.sin(teta), np.cos(teta), 0])
wr = np.array([0, 0, 0, 1])
matrix_rotation = np.array([xr, yr, zr, wr])
figure = translation3D(figure, 0, -deplacement_y, -deplacement_z)
figure = np.matmul(matrix_rotation, figure)
figure = translation3D(figure, 0, deplacement_y, deplacement_z)
return figure
def c_rotation3D_x(figure, teta, deplacement_y=0,
deplacement_z=0): # fonction permettant de réinitialiser la rotation d'un cube sur l'axe x
xr = np.array([1, 0, 0, 0])
yr = np.array([0, np.cos(teta), np.sin(teta), 0])
zr = np.array([0, -np.sin(teta), np.cos(teta), 0])
wr = np.array([0, 0, 0, 1])
matrix_rotation = np.array([xr, yr, zr, wr])
figure = translation3D(figure, 0, -deplacement_y, -deplacement_z)
figure = np.matmul(matrix_rotation, figure)
figure = translation3D(figure, 0, deplacement_y, deplacement_z)
return figure
def rotation3D_y(figure, teta, deplacement_x=0, deplacement_z=0): # rotation d'un objet 3d sur l'axe y
xr = np.array([np.cos(teta), 0, np.sin(teta), 0])
yr = np.array([0, 1, 0, 0])
zr = np.array([-np.sin(teta), 0, np.cos(teta), 0])
wr = np.array([0, 0, 0, 1])
matrix_rotation = np.array([xr, yr, zr, wr])
figure = translation3D(figure, -deplacement_x, 0, -deplacement_z)
figure = np.matmul(matrix_rotation, figure)
figure = translation3D(figure, deplacement_x, 0, deplacement_z)
return figure
def c_rotation3D_y(figure, teta, deplacement_x=0,
deplacement_z=0): # fonction permettant de réinitialiser la rotation d'un cube sur l'axe y
xr = np.array([np.cos(teta), 0, -np.sin(teta), 0])
yr = np.array([0, 1, 0, 0])
zr = np.array([np.sin(teta), 0, np.cos(teta), 0])
wr = np.array([0, 0, 0, 1])
matrix_rotation = np.array([xr, yr, zr, wr])
figure = translation3D(figure, -deplacement_x, 0, -deplacement_z)
figure = np.matmul(matrix_rotation, figure)
figure = translation3D(figure, deplacement_x, 0, deplacement_z)
return figure
def rotation3D_z(figure, teta, deplacement_x=0, deplacement_y=0): # rotation d'un objet 3d sur l'axe z
xr = np.array([np.cos(teta), -np.sin(teta), 0, 0])
yr = np.array([np.sin(teta), np.cos(teta), 0, 0])
zr = np.array([0, 0, 1, 0])
wr = np.array([0, 0, 0, 1])
matrix_rotation = np.array([xr, yr, zr, wr])
figure = translation3D(figure, -deplacement_x, -deplacement_y, 0)
figure = np.matmul(matrix_rotation, figure)
figure = translation3D(figure, deplacement_x, deplacement_y, 0)
return figure
def c_rotation3D_z(figure, teta, deplacement_x=0,
deplacement_y=0): # fonction permettant de réinitialiser la rotation d'un cube sur l'axe z
xr = np.array([np.cos(teta), np.sin(teta), 0, 0])
yr = np.array([-np.sin(teta), np.cos(teta), 0, 0])
zr = np.array([0, 0, 1, 0])
wr = np.array([0, 0, 0, 1])
matrix_rotation = np.array([xr, yr, zr, wr])
figure = translation3D(figure, -deplacement_x, -deplacement_y, 0)
figure = np.matmul(matrix_rotation, figure)
figure = translation3D(figure, deplacement_x, deplacement_y, 0)
return figure
def rotation3D(figure, teta_x=0, teta_y=0, teta_z=0, deplacement_x=0, deplacement_y=0,
deplacement_z=0): # fonction regroupant les 3 rotation d'axes possible
xr = np.array([1, 0, 0, 0])
yr = np.array([0, np.cos(teta_x), -np.sin(teta_x), 0])
zr = np.array([0, np.sin(teta_x), np.cos(teta_x), 0])
wr = np.array([0, 0, 0, 1])
matrix_rotation_x = np.array([xr, yr, zr, wr])
xr = np.array([np.cos(teta_y), 0, np.sin(teta_y), 0])
yr = np.array([0, 1, 0, 0])
zr = np.array([-np.sin(teta_y), 0, np.cos(teta_y), 0])
wr = np.array([0, 0, 0, 1])
matrix_rotation_y = np.array([xr, yr, zr, wr])
xr = np.array([np.cos(teta_z), -np.sin(teta_z), 0, 0])
yr = np.array([np.sin(teta_z), np.cos(teta_z), 0, 0])
zr = np.array([0, 0, 1, 0])
wr = np.array([0, 0, 0, 1])
matrix_rotation_z = np.array([xr, yr, zr, wr])
figure = translation3D(figure, -deplacement_x, -deplacement_y, -deplacement_z)
figure = np.matmul(matrix_rotation_x, figure)
figure = np.matmul(matrix_rotation_y, figure)
figure = np.matmul(matrix_rotation_z, figure)
figure = translation3D(figure, deplacement_x, deplacement_y, deplacement_z)
return figure
def counter_rotation3D(figure, teta_x=0, teta_y=0, teta_z=0, deplacement_x=0, deplacement_y=0,
deplacement_z=0): # fonction permettant de réinitialiser la rotation d'un cube sur n'importe quel axe
xr = np.array([1, 0, 0, 0])
yr = np.array([0, np.cos(teta_x), np.sin(teta_x), 0])
zr = np.array([0, -np.sin(teta_x), np.cos(teta_x), 0])
wr = np.array([0, 0, 0, 1])
matrix_rotation_x = np.array([xr, yr, zr, wr])
xr = np.array([np.cos(teta_y), 0, -np.sin(teta_y), 0])
yr = np.array([0, 1, 0, 0])
zr = np.array([np.sin(teta_y), 0, np.cos(teta_y), 0])
wr = np.array([0, 0, 0, 1])
matrix_rotation_y = np.array([xr, yr, zr, wr])
xr = np.array([np.cos(teta_z), np.sin(teta_z), 0, 0])
yr = np.array([-np.sin(teta_z), np.cos(teta_z), 0, 0])
zr = np.array([0, 0, 1, 0])
wr = np.array([0, 0, 0, 1])
matrix_rotation_z = np.array([xr, yr, zr, wr])
figure = translation3D(figure, -deplacement_x, -deplacement_y, -deplacement_z)
figure = np.matmul(matrix_rotation_x, figure)
figure = np.matmul(matrix_rotation_y, figure)
figure = np.matmul(matrix_rotation_z, figure)
figure = translation3D(figure, deplacement_x, deplacement_y, deplacement_z)
return figure
def init_plt(): # permet d'initaliser la fenetre de matplotlib et de colorier les faces des cubes
global fig # import de variables dans la fonction
global ax
global nbimg
global figures
global angle
nbimg += 1 # variable comptant le nombre d'images créées
print(nbimg)
fig = plt.figure(figsize=(12, 12)) # parametres de la zone de dessin matplotlib
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_xlim(-20, 20)
ax.set_ylim(-20, 20)
ax.set_zlim(-20, 20)
ax.view_init(elev=25, azim=angle)
angle += 2.5
plt.axis('off') # parametres de la zone de dessin matplotlib
for k in range(27): # coloriage des faces des cubes
points = get_points(figures[k])
edges = [[points[0], points[1], points[2], points[3]]]
face = Poly3DCollection(edges, linewidths=1, edgecolors='black')
face.set_facecolor(dic_color[k]["bottom"])
ax.add_collection3d(face)
edges = [[points[4], points[5], points[6], points[7]]]
face = Poly3DCollection(edges, linewidths=1, edgecolors='black')
face.set_facecolor(dic_color[k]["top"])
ax.add_collection3d(face)
edges = [[points[0], points[3], points[7], points[4]]]
face = Poly3DCollection(edges, linewidths=1, edgecolors='black')
face.set_facecolor(dic_color[k]["left"])
ax.add_collection3d(face)
edges = [[points[1], points[2], points[6], points[5]]]
face = Poly3DCollection(edges, linewidths=1, edgecolors='black')
face.set_facecolor(dic_color[k]["right"])
ax.add_collection3d(face)
edges = [[points[3], points[2], points[6], points[7]]]
face = Poly3DCollection(edges, linewidths=1, edgecolors='black')
face.set_facecolor(dic_color[k]["face"])
ax.add_collection3d(face)
edges = [[points[0], points[1], points[5], points[4]]]
face = Poly3DCollection(edges, linewidths=1, edgecolors='black')
face.set_facecolor(dic_color[k]["back"])
ax.add_collection3d(face)
def create_cubes(): # création des 9 cubes du rubiks cube
list = [] # liste des cubes créées
for i in [6.0, -5.0, -16.0]: # position choisis pour que le centre du cube du milieu soit en 0, 0, 0
for j in [6.0, -5.0, -16.0]:
for k in [6.0, -5.0, -16.0]:
list.append(cube(i, j, k, 10))
return list
def top_face(rubiks_cube): # obtenir la face du haut du rubiks cube (utilisation des positions)
low_point_for_cube = {}
for i in range(9):
for j in range(27):
l_lowest_z = rubiks_cube[j][2][0]
for point in rubiks_cube[j][2]:
if point <= l_lowest_z:
low_point_for_cube[j] = point
return list(({k: v for k, v in sorted(low_point_for_cube.items(), key=lambda item: item[1])}.keys()))[18:]
def mid_cubes_z(rubiks_cube): # obtenir la ligne de cube du milieu (entre le haut et le bas)
low_point_for_cube = {}
for i in range(9):
for j in range(27):
l_lowest_z = rubiks_cube[j][2][0]
for point in rubiks_cube[j][2]:
if point <= l_lowest_z:
low_point_for_cube[j] = point
return list(({k: v for k, v in sorted(low_point_for_cube.items(), key=lambda item: item[1])}.keys()))[9:18]
def bottom_face(rubiks_cube): #obtenir les 9 cubes du bas du rubiks cube
low_point_for_cube = {}
for i in range(9):
for j in range(27):
l_lowest_z = rubiks_cube[j][2][0]
for point in rubiks_cube[j][2]:
if point <= l_lowest_z:
low_point_for_cube[j] = point
return list(({k: v for k, v in sorted(low_point_for_cube.items(), key=lambda item: item[1])}.keys()))[:9]
def right_face(rubiks_cube): #obtenir les 9 cubes de droite du rubiks cube
low_point_for_cube = {}
for i in range(9):
for j in range(27):
l_lowest_z = rubiks_cube[j][1][0]
for point in rubiks_cube[j][1]:
if point <= l_lowest_z:
low_point_for_cube[j] = point
return list(({k: v for k, v in sorted(low_point_for_cube.items(), key=lambda item: item[1])}.keys()))[18:]
def left_face(rubiks_cube):#obtenir les 9 cubes de gauche du rubiks cube
low_point_for_cube = {}
for i in range(9):
for j in range(27):
l_lowest_z = rubiks_cube[j][1][0]
for point in rubiks_cube[j][1]:
if point <= l_lowest_z:
low_point_for_cube[j] = point
return list(({k: v for k, v in sorted(low_point_for_cube.items(), key=lambda item: item[1])}.keys()))[:9]
def front_face(rubiks_cube):#obtenir les 9 cubes de la face du rubiks cube
low_point_for_cube = {}
for i in range(9):
for j in range(27):
l_lowest_z = rubiks_cube[j][0][0]
for point in rubiks_cube[j][0]:
if point <= l_lowest_z:
low_point_for_cube[j] = point
return list(({k: v for k, v in sorted(low_point_for_cube.items(), key=lambda item: item[1])}.keys()))[18:]
def back_face(rubiks_cube):#obtenir les 9 cubes du dos du rubiks cube
low_point_for_cube = {}
for i in range(9):
for j in range(27):
l_lowest_z = rubiks_cube[j][0][0]
for point in rubiks_cube[j][0]:
if point <= l_lowest_z:
low_point_for_cube[j] = point
return list(({k: v for k, v in sorted(low_point_for_cube.items(), key=lambda item: item[1])}.keys()))[:9]
figures = create_cubes() #liste des cubes composants le rubiks cube
vitesse = 10 #vitesse de rotation des faces
def initialize_colors(rubiks_cube): #permet d'obtenir la couleur à attribuer a chaques faces des cubes
dic_list = [{"top": "k", "bottom": "k", "right": "k", "left": "k", "face": "k", "back": "k"} for i in range(27)]
for i in bottom_face(rubiks_cube):
dic_list[i]["bottom"] = "w"
for i in top_face(rubiks_cube):
dic_list[i]["top"] = "y"
for i in front_face(rubiks_cube):
dic_list[i]["face"] = "blue"
for i in back_face(rubiks_cube):
dic_list[i]["back"] = "green"
for i in right_face(rubiks_cube):
dic_list[i]["right"] = "red"
for i in left_face(rubiks_cube):
dic_list[i]["left"] = "darkorange"
return dic_list
def rotate_face(figures, j): #faire pivoter la face du rubiks cube
global vitesse
figures[j] = rotation3D_x(figures[j], np.pi / vitesse, 0, 0)
return figures
def rotate_back(figures, j): #faire pivoter le dos du rubiks cube
figures[j] = rotation3D_x(figures[j], np.pi / vitesse, 0, 0)
return figures
def rotate_right(figures, j): #faire pivoter la droite du rubiks cube
figures[j] = rotation3D_y(figures[j], np.pi / vitesse, 0, 0)
return figures
def rotate_left(figures, j): #faire pivoter la gauche du rubiks cube
figures[j] = rotation3D_y(figures[j], np.pi / vitesse, 0, 0)
return figures
def rotate_head(figures, j): #faire pivoter le haut du rubiks cube
figures[j] = rotation3D_z(figures[j], np.pi / vitesse, 0, 0)
return figures
def rotate_under(figures, j): #faire pivoter le bas du rubiks cube
figures[j] = rotation3D_z(figures[j], np.pi / vitesse, 0, 0)
return figures
def rotate_and_spin_top(top): #permet de faire pivoter tout le rubiks cube de 45° puis de le faire pivoter en continue et tourner sa face du haut
rubiks_cube = figures[:]
for i in range(27):
rubiks_cube[i] = rotation3D_z(rubiks_cube[i], 45 * np.pi / 180, 0, 0)
rubiks_cube[i] = rotation3D_y(rubiks_cube[i], 45 * np.pi / 180, 0, 0)
for i in range(10):
for i in range(27):
figures[i] = rotation3D_z(figures[i], 4.5 * np.pi / 180, 0, 0)
init_plt()
plt.savefig(f'{nbimg}.png')
plt.close()
for i in range(10):
for i in range(27):
figures[i] = rotation3D_y(figures[i], 4.5 * np.pi / 180, 0, 0)
init_plt()
plt.savefig(f'{nbimg}.png')
plt.close()
for i in range(27):
figures[i] = rubiks_cube[i]
for i in range(35):
for i in top:
figures[i] = rotation3D_z(figures[i], 7.2 * np.pi / 180)
figures[i] = rotation3D_x(figures[i], 7.2 * np.pi / 180)
init_plt()
plt.savefig(f'{nbimg}.png')
plt.close()
for i in range(27):
figures[i] = rubiks_cube[i]
init_plt()
plt.savefig(f'{nbimg}.png')
plt.close()
def rotate_and_spin_bot(top): #permet de faire pivoter tout le rubiks cube de 45° puis de le faire pivoter en continue et tourner sa face du bas
rubiks_cube = figures[:]
for i in range(27):
rubiks_cube[i] = rotation3D_z(rubiks_cube[i], 45 * np.pi / 180)
rubiks_cube[i] = rotation3D_y(rubiks_cube[i], 45 * np.pi / 180)
rubiks_cube[i] = rotation3D_x(rubiks_cube[i], 45 * np.pi / 180)
for i in range(10):
for i in range(27):
figures[i] = rotation3D_x(figures[i], 4.5 * np.pi / 180, 0, 0)
init_plt()
plt.savefig(f'{nbimg}.png')
plt.close()
"""for i in range(27):
figures[i] = rubiks_cube[i]"""
for i in range(50):
for j in top:
figures[j] = c_rotation3D_x(figures[j], 45 * np.pi / 180)
figures[j] = c_rotation3D_y(figures[j], 45 * np.pi / 180)
figures[j] = c_rotation3D_z(figures[j], 45 * np.pi / 180)
figures[j] = rotation3D_z(figures[j], 7.2 * np.pi / 180)
figures[j] = rotation3D_z(figures[j], 45 * np.pi / 180)
figures[j] = rotation3D_y(figures[j], 45 * np.pi / 180)
figures[j] = rotation3D_x(figures[j], 45 * np.pi / 180)
init_plt()
plt.savefig(f'{nbimg}.png')
plt.close()
for i in range(10):
for i in range(27):
figures[i] = c_rotation3D_x(figures[i], 4.5 * np.pi / 180)
figures[i] = c_rotation3D_y(figures[i], 4.5 * np.pi / 180)
figures[i] = c_rotation3D_z(figures[i], 4.5 * np.pi / 180)
init_plt()
plt.savefig(f'{nbimg}.png')
plt.close()
def apparition(): #animation de diparition du cube
bottom = bottom_face(figures)
top = top_face(figures)
mid = mid_cubes_z(figures)
for j in range(40):
deplacement = 5
for i in top:
figures[i] = translation3D(figures[i], 0, 0, deplacement)
deplacement += 1
deplacement = 5
for i in bottom:
figures[i] = translation3D(figures[i], 0, 0, deplacement)
deplacement += 1
deplacement = 5
for i in mid:
figures[i] = translation3D(figures[i], 0, 0, deplacement)
deplacement += 1
init_plt()
plt.savefig(f'{nbimg}.png')
plt.close()
def disparition():
for i in range(30):
for i in range(27):
figures[i] = aggrandissement_reduc(figures[i], 0.75)
init_plt()
plt.savefig(f'{nbimg}.png')
plt.close()
dic_color = initialize_colors(figures)
collection_faces = []
angle = 30
nbimg = -1
oldresult = -1
cote = -1
for i in range(20): # 20 rotations aléatoire du cube
# draw
# mouvements
while cote == oldresult:
cote = random.randint(0, 5) # selection d'une face aléatoirement
oldresult = cote # éviter de tourner deux fois la meme face
if cote == 0:
print('face')
for j in range(int(vitesse / 2)):
init_plt()
for k in front_face(figures):
figures = rotate_face(figures, k)
plt.savefig(f'{nbimg}.png')
plt.close()
elif cote == 1:
print('right')
for j in range(int(vitesse / 2)):
init_plt()
e = right_face(figures)
for k in e:
figures = rotate_right(figures, k)
plt.savefig(f'{nbimg}.png')
plt.close()
elif cote == 2:
print('left')
for j in range(int(vitesse / 2)):
init_plt()
for k in left_face(figures):
figures = rotate_left(figures, k)
plt.savefig(f'{nbimg}.png')
plt.close()
elif cote == 3:
print('head')
for j in range(int(vitesse / 2)):
init_plt()
for k in top_face(figures):
figures = rotate_head(figures, k)
plt.savefig(f'{nbimg}.png')
plt.close()
elif cote == 4:
print('under')
for j in range(int(vitesse / 2)):
init_plt()
for k in bottom_face(figures):
figures = rotate_under(figures, k)
plt.savefig(f'{nbimg}.png')
plt.close()
elif cote == 5:
print('back')
for j in range(int(vitesse / 2)):
init_plt()
for k in back_face(figures):
figures = rotate_back(figures, k)
plt.savefig(f'{nbimg}.png')
plt.close()
bot = bottom_face(figures)
top = top_face(figures)
rotate_and_spin_top(top)
rotate_and_spin_bot(bot)
apparition() # animation d'apparition du cube (chute depuis le haut)
r_nbimg = nbimg
images = [] # liste des images utilisés dans le gif
for n in reversed(range(nbimg)): # inversion de l'animation (pour faire croire une résolution de rubiks cube)
images.append(Image.open(f'{n}.png'))
figures = create_cubes()
disparition() # animation de disparition (reduction de la taille du rubiks cube)
for n in range(r_nbimg + 1, nbimg):
images.append(Image.open(f'{n}.png'))
images[0].save('cube.gif', save_all=True, append_images=images[1:], duration=10, loop=0) # création du gif