Skip to content

Fix spelling and grammar #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions docs/1_intro/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Pygame is a multimedia library for Python for making games
and multimedia applications.

It is a wrapper around the SDL (Simple DirectMedia Layer) library.
In this section we indroduce the basics of pygame functions without defining classes and objects.
In this section we introduce the basics of pygame functions without defining classes and objects.


Import the module
Expand All @@ -24,15 +24,15 @@ Pygame website to the console (as a side effect)::

The Pygame import statement is always placed at the beginning of the program.
It imports the pygame classes, methods and attributes into the current name space.
Now this new methods can be called via ``pygame.method()``.
Now these new methods can be called via ``pygame.method()``.

For exemple we can now initialize or quit **pygame** with the following command::
For example we can now initialize or quit **pygame** with the following command::

pygame.init()
pygame.quit()

The function ``display.set_mode()`` sets the screen size. It returns
a ``Surface`` object wich we assign to the variable ``screen``.
a ``Surface`` object which we assign to the variable ``screen``.
This variable will be one of the most used variables.
It represents the window we see::

Expand Down Expand Up @@ -62,14 +62,14 @@ The following is an infinite loop which prints all events to the console::

Try to move the mouse, click a mouse button, or type something on the keyboard.
Every action you do produces an event which will be printed on the console.
This will look something like this::
It will look something like this::

<Event(4-MouseMotion {'pos': (173, 192), 'rel': (173, 192), 'buttons': (0, 0, 0), 'window': None})>
<Event(2-KeyDown {'unicode': 'a', 'key': 97, 'mod': 0, 'scancode': 0, 'window': None})>
<Event(3-KeyUp {'key': 97, 'mod': 0, 'scancode': 0, 'window': None})>
<Event(12-Quit {})>

As we are in an infite loop, it is impossible to quit this program from within the application.
As we are in an infinite loop, it is impossible to quit this program from within the application.
In order to quit the program, make the console the active window and type ``ctrl-C``.
This will write the following message to the console::

Expand Down Expand Up @@ -98,7 +98,7 @@ If it occurs, we set ``running`` to ``False``::

pygame.quit()

Once the event loop, we call the ``pygame.quit()`` function to end the application
Once the event loop ends, we call the ``pygame.quit()`` function to end the application
correctly.

.. image:: intro2.png
Expand All @@ -119,7 +119,7 @@ A total of 16 million different colors can be represented this way.
.. image:: AdditiveColorMixing.png
:scale: 50 %

Let's define the base colors as tuples of the tree base values.
Let's define the base colors as tuples of the three base values.
Since colors are constants, we will write them using capitals.
The absence of all colors results in black.
The maximum value for all three components results in white.
Expand All @@ -129,13 +129,13 @@ Three identical intermediate values result in gray::
GRAY = (127, 127, 127)
WHITE = (255, 255, 255)

The tree base colors are defined as::
The three base colors are defined as::

RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)

By mixing two base colors we obtained more colors::
By mixing two base colors we obtain more colors::

YELLOW = (255, 255, 0)
CYAN = (0, 255, 255)
Expand All @@ -158,7 +158,7 @@ At this point nothing will be displayed. In order to show anything, the function
Switch the background color
---------------------------

At the beginning of the program we add a new veriable ``background``
At the beginning of the program we add a new variable ``background``
and initialize it to gray::

background = GRAY
Expand Down Expand Up @@ -188,8 +188,8 @@ Pressing the R and G keys allows you to switch the background color.
Import pygame.locals
--------------------

The ``pygame.locals`` module contains some 280 constants used and defined by pygme.
Placing this statement at the beginning of your programm imports them all::
The ``pygame.locals`` module contains some 280 constants used and defined by pygame.
Placing this statement at the beginning of your program imports them all::

import pygame
from pygame.locals import *
Expand Down Expand Up @@ -221,10 +221,10 @@ Instead of writing ``pygame.KEYDOWN`` we can now just write ``KEYDOWN``.
Use a dictionary to decode keys
-------------------------------

The easiest way to decode many keys, is to use a dictionary.
The easiest way to decode many keys is to use a dictionary.
Instead of defining many if-else cases, we just create a dictionary with the keyboard key entries.
In this exemple we want to associate 8 different keys with 8 different background colors.
At the beginning of the programm we define this key-color dictionary::
In this example we want to associate 8 different keys with 8 different background colors.
At the beginning of the program we define this key-color dictionary::

key_dict = {K_k:BLACK, K_r:RED, K_g:GREEN, K_b:BLUE,
K_y:YELLOW, K_c:CYAN, K_m:MAGENTA, K_w:WHITE}
Expand All @@ -236,7 +236,7 @@ Printing the dictionary to the console gives this result::
{107: (0, 0, 0), 114: (255, 0, 0), 103: (0, 255, 0), 98: (0, 0, 255),
121: (255, 255, 0), 99: (0, 255, 255), 109: (255, 0, 255), 119: (255, 255, 255)}

The keys are presented here with their ASCII code. For exaple the ASCII code for
The keys are presented here with their keycode. For example the keycode for
``k`` is 107. Colors are represented as tuples. The color black is represented as (0, 0, 0).

The event loop now becomes very simple.
Expand All @@ -256,7 +256,7 @@ Try to press the 8 specified keys to change the background color.
Change the window caption
-------------------------

The fonction ``pygame.display.set_caption(title)`` allows to change the caption (title)
The function ``pygame.display.set_caption(title)`` allows us to change the caption (title)
of the application window. We can add this to the event loop::

if event.key in key_dict:
Expand Down Expand Up @@ -331,22 +331,24 @@ Then we move the rectangle and check the left/right and top/bottom borders::
if rect.top < 0 or rect.bottom > height:
speed[1] = -speed[1]

Finaly we draw a green background, a red rectangle and the ball image::
Finally we draw a green background, a red rectangle and the ball image::

screen.fill(GREEN)
pygame.draw.rect(screen, RED, rect, 1)
screen.blit(ball, rect)
pygame.display.update()

When the event loop ends, close the application::

pygame.quit()

This is what the ball and the ``Rect`` outline looks:
This is what the ball and the ``Rect`` outline looks like:

.. image:: intro6.png

:download:`ball.gif<ball.gif>`

Try to understand what the program does.
Then try to modify it's parameters.
Then try to modify its parameters.

:download:`intro6.py<intro6.py>`
:download:`intro6.py<intro6.py>`
33 changes: 17 additions & 16 deletions docs/2_draw/draw.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Drawing graphics primitives
============================

The ``pygame.draw`` module allows to draw simple shapes to a surface.
This can be the screen surface or any Surface object such as an image or drawing:
The ``pygame.draw`` module allows us to draw simple shapes to a surface.
This can be the screen surface or any Surface object such as an image or drawing.
The available shapes include:

- rectangle
- polygon
Expand All @@ -11,9 +12,9 @@ This can be the screen surface or any Surface object such as an image or drawing

The functions have in common that they:

- take a **Surface** object as first argument
- take a color as second argument
- take a width parameter as last argument
- take a **Surface** object as the first argument
- take a color as the second argument
- take a width parameter as a keyword argument
- return a **Rect** object which bounds the changed area

the following format::
Expand All @@ -28,7 +29,7 @@ Draw solid and outlined rectangles
----------------------------------

The following draws first the background color and then adds three overlapping solid rectangles
and next to it three oulined overlapping rectangles with increasing line width::
and next to them three outlined overlapping rectangles with increasing line width::

screen.fill(background)
pygame.draw.rect(screen, RED, (50, 20, 120, 100))
Expand All @@ -41,14 +42,14 @@ and next to it three oulined overlapping rectangles with increasing line width::

.. image:: draw1.png

Try to modifiy the parameters and play with the drawing function.
Try to modify the parameters and play with the drawing function.


Draw solid and outlined ellipses
--------------------------------

The following code draws first the background color and then adds three overlapping solid ellipses
and next to it three oulined overlapping ellipses with increasing line width::
and next to them three outlined overlapping ellipses with increasing line width::

screen.fill(background)
pygame.draw.ellipse(screen, RED, (50, 20, 160, 100))
Expand All @@ -70,7 +71,7 @@ Detect the mouse
----------------

Pressing the mouse buttons produces MOUSEBUTTONDOWN and MOUSEBUTTONUP events.
The flollowing code in the event loop detects them and writes the event to the console::
The following code in the event loop detects them and writes the event to the console::

for event in pygame.event.get():
if event.type == QUIT:
Expand All @@ -80,20 +81,20 @@ The flollowing code in the event loop detects them and writes the event to the c
elif event.type == MOUSEBUTTONUP:
print(event)

Pressing the mouse buttons produces this kind of events::
Pressing the mouse buttons produces these kinds of events::

<Event(5-MouseButtonDown {'pos': (123, 88), 'button': 1, 'window': None})>
<Event(6-MouseButtonUp {'pos': (402, 128), 'button': 1, 'window': None})>
<Event(5-MouseButtonDown {'pos': (402, 128), 'button': 3, 'window': None})>
<Event(6-MouseButtonUp {'pos': (189, 62), 'button': 3, 'window': None})>

Just moving the mouse produces a MOUSEMOTION event.
The following code detects them an writes the event to the console::
The following code detects them and writes the event to the console::

elif event.type == MOUSEMOTION:
print(event)

Moving the mosue produces this kind of event::
Moving the mouse produces this kind of event::

<Event(4-MouseMotion {'pos': (537, 195), 'rel': (-1, 0), 'buttons': (0, 0, 0), 'window': None})>
<Event(4-MouseMotion {'pos': (527, 189), 'rel': (-10, -6), 'buttons': (0, 0, 0), 'window': None})>
Expand All @@ -103,7 +104,7 @@ Moving the mosue produces this kind of event::
Draw a rectangle with the mouse
-------------------------------

We can use this three events to draw a rectangle on the screen.
We can use these three events to draw a rectangle on the screen.
We define the rectangle by its diagonal start and end point.
We also need a flag which indicates if the mouse button is down and if we are drawing::

Expand All @@ -112,7 +113,7 @@ We also need a flag which indicates if the mouse button is down and if we are dr
drawing = False

When the mouse button is pressed, we set start and end to the current mouse position
and indciate with the flag that the drawing mode has started::
and indicate with the flag that the drawing mode has started::

elif event.type == MOUSEBUTTONDOWN:
start = event.pos
Expand Down Expand Up @@ -169,7 +170,7 @@ MOUSEBUTTONUP event, we create a rectangle and append it to the rectangle list::
drawing = False

In the drawing code, we first fill the background color, then iterate through the
rectagle list to draw the objects (red, thickness=3), and finally we draw the current rectangle which
rectangle list to draw the objects (red, thickness=3), and finally we draw the current rectangle which
is in the process of being drawn (blue, thickness=1)::

screen.fill(GRAY)
Expand Down Expand Up @@ -236,4 +237,4 @@ Here is the complete file:

.. literalinclude:: mouse4.py

:download:`mouse4.py<mouse4.py>`
:download:`mouse4.py<mouse4.py>`
30 changes: 15 additions & 15 deletions docs/3_image/image.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Work with images
Load an image
-------------

The ``pyagme.image`` module provides methods for loading and saving
The ``pygame.image`` module provides methods for loading and saving
images. The method ``load()`` loads an image from the file system
and returns a Surface object. The method ``convert()`` optimizes the
image format and makes drawing faster::
Expand Down Expand Up @@ -40,7 +40,7 @@ Then we blit the image, draw a red rectangle around it and finally update the sc
Move the image with the mouse
-----------------------------

At the beginning of the programm we set a boolean variable ``moving`` to False.
At the beginning of the program we set a boolean variable ``moving`` to False.
Only when the mouse button is pressed, and when the mouse position is within the image (collidepoint) we set it to True::

elif event.type == MOUSEBUTTONDOWN:
Expand Down Expand Up @@ -82,7 +82,7 @@ In order to show the image rectangle, we add a green border to the original imag
rect0 = img0.get_rect()
pygame.draw.rect(img0, GREEN, rect0, 1)

Then we place the place the image in the center of the screen::
Then we place the image in the center of the screen::

center = w//2, h//2
img = img0
Expand All @@ -94,9 +94,9 @@ First we define the global variables **scale** and **angle**::
angle = 0
scale = 1

We use the R key to increment rotation by 10 degrees and
(decrement if the SHIFT key is pressed). The function ``rotozoom()`` allows to combine
rotation and scaling. We always transform the orignial image (img0). Repeated rotation or scaling of
We use the R key to increment rotation by 10 degrees
(or decrement if the SHIFT key is pressed). The function ``rotozoom()`` allows us to combine
rotation and scaling. We always transform the original image (img0). Repeated rotation or scaling of
an image would degrade its quality::

if event.type == KEYDOWN:
Expand All @@ -118,7 +118,7 @@ is pressed)::
img = pygame.transform.rotozoom(img0, angle, scale)

As the image is transformed the bounding rectangle changes size. It must be
recalulated and placed at the center again::
recalculated and placed at the center again::

rect = img.get_rect()
rect.center = center
Expand Down Expand Up @@ -150,14 +150,14 @@ and the V key to flip the image vertically::
Detect edges with the Laplacian
-------------------------------

The fonction ``laplacien(img)`` allows to detect the outline of the image::
The function ``laplacian(img)`` allows us to detect the outline of the image::

elif event.key == K_l:
img = pygame.transform.laplacian(img)

.. image:: image2.png

The fonction ``scale2x(img)`` doubles the size of a pixel::
The function ``scale2x(img)`` doubles the size of a pixel::

elif event.key == K_2:
img = pygame.transform.scale2x(img)
Expand All @@ -172,7 +172,7 @@ At the beginning we import the ``math`` module::

import math

At the beginning we store the initial mouse position::
We store the initial mouse position::

mouse = pygame.mouse.get_pos()

Expand All @@ -186,8 +186,8 @@ We also calculate the center-mouse distance **d** ::
y = mouse[1] - center[1]
d = math.sqrt(x ** 2 + y ** 2)

The ``atan2(y, x)`` math function allows to find the rotation angle. We need to
transform radians in degrees. From the distance mouse-center we calculate the
The ``atan2(y, x)`` math function allows us to find the rotation angle. We need to
transform radians to degrees. From the distance mouse-center we calculate the
scale argument::

angle = math.degrees(-math.atan2(y, x))
Expand All @@ -196,8 +196,8 @@ scale argument::
rect = img.get_rect()
rect.center = center

To finally draw the transformed image we first fille the whole screen background (GRAY),
blit the transformed image, surround it with a red rectangle.
To finally draw the transformed image we first fill the whole screen background (GRAY),
blit the transformed image, and surround it with a red rectangle.

In order to give visual feedback for the mouse action when transforming an image, we

Expand All @@ -218,4 +218,4 @@ Here is the full code.

.. literalinclude:: image2.py

:download:`image2.py<image2.py>`
:download:`image2.py<image2.py>`
Loading