Pygame is a cross platform set of python modules designed for writing video games. It provides simple libraries, with the intention of allowing real time computer game development without the low level mechanics of C programming. We can draw simple geometrics figures like rectangle, square, polygon or circle. A sample syntax to draw a rectangle of length and breadth 50, 100 respectively is:
pygame.draw.rect(screen,(0,0,0),(50, 50, 100, 100))
pygame.display.flip().
Here screen is the surface on which the figure gets displayed or the basic background, (0, 0, 0) stands for the color of the rectangle to be drawn, flip() updates the full display surface to the screen.
The screenshot shows the output of the code I wrote to draw a rectangle.
pygame.draw.rect(screen,(0,0,0),(50, 50, 100, 100))
pygame.display.flip().
Here screen is the surface on which the figure gets displayed or the basic background, (0, 0, 0) stands for the color of the rectangle to be drawn, flip() updates the full display surface to the screen.
The screenshot shows the output of the code I wrote to draw a rectangle.
PYGAME ESSENTIALS
Pygame program to work the most essential things to be included in the program are:-
- import pygame module.
- initialize pygame using pygame.init().
- you need a display screen to display your figure. Select a background color and also the size of the screen for your figure.
- RGB color scheme represented by the tuple(0,0,0) which stands for black and (255,255,255) for white. Any combination in the tuple give you different colors.
- the figure to be drawn.
- display the figure using pygame.display.flip().
No comments:
Post a Comment