-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·133 lines (104 loc) · 4.41 KB
/
test.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
# Import a library of functions called 'pygame'
import pygame
from pygame.locals import *
from math import pi
import Matrice
# Initialize the game engine
pygame.init()
# Define the colors we will use in RGB format
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
h = {
(0,0): 'c',
(1,0): 'DROITE', (1,1): 'NE', (0,1): 'HAUT', (-1,1): 'NW',
(-1,0): 'GAUCHE', (-1,-1): 'SW', (0,-1): 'BAS', (1,-1): 'SE'
}
# Set the height and width of the screen
size = [400, 300]
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Example code for the draw module")
# Loop until the user clicks the close button.
done = False
clock = pygame.time.Clock()
#mon_joystick = pygame.joystick.Joystick
nb_joysticks = pygame.joystick.get_count()
if nb_joysticks > 0:
#if mon_joystick == pygame.joystick.Joystick:
mon_joystick = pygame.joystick.Joystick(0)
mon_joystick.init() #Initialisation
print("Axes :", mon_joystick.get_numaxes())
print("Boutons :", mon_joystick.get_numbuttons())
print("Trackballs :", mon_joystick.get_numballs())
print("Hats :", mon_joystick.get_numhats())
while not done:
# This limits the while loop to a max of 10 times per second.
# Leave this out and we will use all CPU we can.
clock.tick(10)
#On compte les joysticks
nb_joysticks = pygame.joystick.get_count()
#Et on en crée un s'il y a en au moins un
if nb_joysticks > 0:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop
if event.type == JOYBUTTONDOWN:
print(event.button)
if event.type == KEYDOWN:
print(event.key)
if event.type == MOUSEBUTTONDOWN:
print(event.button)
if event.type == JOYAXISMOTION:
if event.axis == 0 and event.value > 0:
print("droite %d",event.value)
if event.axis == 0 and event.value < 0:
print("gauche %d",event.value)
if event.type == JOYHATMOTION:
print(event.hat,h[event.value])
#if event.Hats == 0 and event.value > 0:
#print("droite %d",event.value)
#if event.axis == 0 and event.value < 0:
#print("gauche %d",event.value)
#if event.type != 7:
#print(event.type)
# All drawing code happens after the for loop and but
# inside the main while done==False loop.
# Clear the screen and set the screen background
screen.fill(WHITE)
pygame.draw.rect(screen, Matrice.Matrice.BLUE, [1*10, 1*10, 10, 10])
# Draw on the screen a GREEN line from (0,0) to (50.75)
# 5 pixels wide.
pygame.draw.line(screen, GREEN, [0, 0], [50, 30], 5)
# Draw on the screen a GREEN line from (0,0) to (50.75)
# 5 pixels wide.
pygame.draw.lines(
screen, BLACK, False, [[0, 80], [50, 90], [200, 80], [220, 30]], 5
)
# Draw on the screen a GREEN line from (0,0) to (50.75)
# 5 pixels wide.
pygame.draw.aaline(screen, GREEN, [0, 50], [50, 80], True)
# Draw a rectangle outline
pygame.draw.rect(screen, BLACK, [75, 10, 50, 20], 2)
# Draw a solid rectangle
pygame.draw.rect(screen, BLACK, [150, 10, 50, 20])
# Draw an ellipse outline, using a rectangle as the outside boundaries
pygame.draw.ellipse(screen, RED, [225, 10, 50, 20], 2)
# Draw an solid ellipse, using a rectangle as the outside boundaries
pygame.draw.ellipse(screen, RED, [300, 10, 50, 20])
# This draws a triangle using the polygon command
pygame.draw.polygon(screen, BLACK, [[100, 100], [0, 200], [200, 200]], 5)
# Draw an arc as part of an ellipse.
# Use radians to determine what angle to draw.
pygame.draw.arc(screen, BLACK, [210, 75, 150, 125], 0, pi / 2, 2)
pygame.draw.arc(screen, GREEN, [210, 75, 150, 125], pi / 2, pi, 2)
pygame.draw.arc(screen, BLUE, [210, 75, 150, 125], pi, 3 * pi / 2, 2)
pygame.draw.arc(screen, RED, [210, 75, 150, 125], 3 * pi / 2, 2 * pi, 2)
# Draw a circle
pygame.draw.circle(screen, BLUE, [60, 250], 40)
# Go ahead and update the screen with what we've drawn.
# This MUST happen after all the other drawing commands.
pygame.display.flip()
# Be IDLE friendly
pygame.quit()