Differences

This shows you the differences between two versions of the page.

Link to this comparison view

gp:laboratoare:01 [2025/02/05 12:45]
maria_anca.balutoiu [Biblioteci Utile]
gp:laboratoare:01 [2025/02/05 12:59] (current)
maria_anca.balutoiu [Tasks]
Line 53: Line 53:
 <​code>​ <​code>​
 python3 -m pip install pygame python3 -m pip install pygame
 +</​code>​
 +
 +<​code>​
 +import pygame
 +
 +# Initialize Pygame
 +pygame.init()
 +
 +# Set window properties
 +width, height = 800, 600
 +screen = pygame.display.set_mode((width,​ height))
 +pygame.display.set_caption('​Pygame Example'​)
 +
 +# Set the drawing colors
 +white = (255, 255, 255)
 +red = (255, 0, 0)
 +
 +# Set the coordinates and the dimensions of the square
 +x, y = 100, 100  # Upper-left corner
 +length = 50     # Length of the square
 +
 +running = True
 +while running:
 +    for event in pygame.event.get():​
 +        if event.type == pygame.QUIT:​
 +            running = False
 +
 +    # Set background color
 +    screen.fill(white)
 +
 +    # Draw a square
 +    pygame.draw.rect(screen,​ red, (x, y, length, length))
 +
 +    # Update the screen
 +    pygame.display.flip()
 </​code>​ </​code>​
  
Line 83: Line 118:
 </​code>​ </​code>​
 ==== Tasks ==== ==== Tasks ====
 +
 +<note tip>​Pentru a genera un număr random, folosiți biblioteca **random**.</​note>​
 +
   - Generați un grid de culori alese aleator.   - Generați un grid de culori alese aleator.
   - Generați aleator o hartă 2D folosind simboluri (~ pentru apă, # pentru munți, . pentru câmpii). Folosiți probabilități pentru a asigna tipul de teren generat.   - Generați aleator o hartă 2D folosind simboluri (~ pentru apă, # pentru munți, . pentru câmpii). Folosiți probabilități pentru a asigna tipul de teren generat.
   - **Bonus 1.** Modificați primul task astfel încât gridul de culori să se regenereze la apăsarea unei taste. ​   - **Bonus 1.** Modificați primul task astfel încât gridul de culori să se regenereze la apăsarea unei taste. ​
   - **Bonus 2.** Modificați al doilea task astfel încât să salvați harta de simboluri ca o imagine PNG.   - **Bonus 2.** Modificați al doilea task astfel încât să salvați harta de simboluri ca o imagine PNG.
gp/laboratoare/01.1738752321.txt.gz · Last modified: 2025/02/05 12:45 by maria_anca.balutoiu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0