Première séance ISN
This commit is contained in:
parent
4c41b70864
commit
ab9c5672df
65
ISN/draw.py
Normal file
65
ISN/draw.py
Normal file
@ -0,0 +1,65 @@
|
||||
import pygame, sys
|
||||
|
||||
pygame.init()
|
||||
|
||||
windowSurface = pygame.display.set_mode((500, 400), 0,32)
|
||||
pygame.display.set_caption('Hello world!')
|
||||
|
||||
BLACK = (0, 0, 0)
|
||||
WHITE = (255, 255, 255)
|
||||
RED = (255, 0, 0)
|
||||
GREEN = (0, 255, 0)
|
||||
BLUE = (0, 0, 255)
|
||||
|
||||
color_text = WHITE
|
||||
color_background = WHITE
|
||||
color_polygon = GREEN
|
||||
color_border = RED
|
||||
|
||||
running = True
|
||||
while running:
|
||||
|
||||
basic_font = pygame.font.SysFont(None, 48)
|
||||
text = basic_font.render('Hello world!', True, color_text ,BLUE)
|
||||
text_rect = text.get_rect()
|
||||
text_rect.centerx = windowSurface.get_rect().centerx
|
||||
text_rect.centery = windowSurface.get_rect().centery
|
||||
|
||||
windowSurface.fill(color_background)
|
||||
|
||||
pygame.draw.polygon(windowSurface, color_polygon,
|
||||
((146, 0), (291, 106), (236, 277), (56, 277), (0, 106))
|
||||
)
|
||||
|
||||
pygame.draw.line(windowSurface, BLUE, (60, 60), (120, 60), 4)
|
||||
pygame.draw.line(windowSurface, BLUE, (120, 60), (60, 120))
|
||||
pygame.draw.line(windowSurface, BLUE, (60, 120), (120, 120), 4)
|
||||
|
||||
pygame.draw.circle(windowSurface, BLUE, (300, 50), 20, 0)
|
||||
|
||||
pygame.draw.ellipse(windowSurface, RED, (300, 250, 40,80), 1)
|
||||
|
||||
pygame.draw.rect(windowSurface, color_border,
|
||||
(text_rect.left - 20, text_rect.top - 20,
|
||||
text_rect.width + 40, text_rect.height + 40)
|
||||
)
|
||||
|
||||
windowSurface.blit(text, text_rect)
|
||||
|
||||
pygame.display.update()
|
||||
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
elif event.type == pygame.MOUSEBUTTONUP:
|
||||
color_background = WHITE
|
||||
color_border = (255, (color_border[1] + 10) % 256, 0)
|
||||
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||
color_background = RED
|
||||
elif event.type == pygame.KEYUP:
|
||||
if event.key == pygame.K_UP:
|
||||
color_polygon = BLACK
|
||||
elif event.key == pygame.K_DOWN:
|
||||
color_polygon = GREEN
|
||||
|
||||
pygame.quit()
|
@ -2,7 +2,7 @@ Quelques cours d'ISN pour la validation
|
||||
#######################################
|
||||
|
||||
:date: 2017-10-19
|
||||
:modified: 2017-10-19
|
||||
:modified: 2017-10-22
|
||||
:authors: Bertrand Benjamin
|
||||
:category: ISN
|
||||
:tags: Progression
|
||||
@ -18,7 +18,7 @@ Librairie Pygame (+3 séances)
|
||||
Étape 1: découverte de fonctionnalité de dessin
|
||||
-----------------------------------------------
|
||||
|
||||
On donne un code pas commenté. Les élèves doivent par eux même comprendre ce qui est fait et ajouter les commentaires (ou changer les noms de variables) pour le rendre plus explicite.
|
||||
On donne `un code pas commenté <./draw.py>`_. Les élèves doivent par eux même comprendre ce qui est fait et ajouter les commentaires (ou changer les noms de variables) pour le rendre plus explicite.
|
||||
|
||||
À la suite de ça, les élèves seront libres de dessiner ce qu'ils souhaitent sur l'écran. Les plus rapides pourront commencer à faire bouger les éléments.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user