Institute of Computer Science
  1. Main page
  2. Python koolis
ET
Log in

Python koolis

  • Sissejuhatus
  • Teemad
  • PyGame

1. Aken
2. Värvid ja koordinaadid
3. Joonistamine
4. Pildid
5. Tekst
6. Animeerimine
7. Juhtimine klaviatuuriga
8. Juhtimine hiirega
9. Heli
10. Õpetusi

  • ÜLESANDED

3. PyGame: joonistamine

Pygame'is saame aknasse lisada erinevaid geomeetrilisi kujundeid: ringe, ristkülikuid, hulknurke jne. Kujundite lisamiseks kasutame Pygame'i moodulit "draw":

pygame.draw.<kujundi_nimi>(<argumendid>)

Sõltuvalt kujundist on argumentide nimekiri erinev: ristküliku puhul nõutakse pikkust ja laiust, ringi puhul raadiust jne.

# Aknasse "ekraan" joonistatud roheline ristkülik asukohaga x = 50, y = 50,
# laiusega 150, kõrgusega 80, kontuuriga 0 (e. seest üleni täidetud)
pygame.draw.rect(ekraan, [0, 225, 0], [50, 50, 150, 80], 0)


# Lilla joon punktide (50, 150) ja (300, 200) vahel laiusega 2
pygame.draw.line(ekraan, [255, 0, 204], [50, 150], [300, 200], 2)


# Punane ring asukohaga x = 250, y = 90, raadiusega 25, kontuuriga 4 (seest tühi)
pygame.draw.circle(ekraan, [255, 0, 0], [250, 90], 25, 4)

Lisamaterjalid

  • http://www.pygame.org/docs/ref/draw.html

Creative Commons litsentsiga Autorile viitamine + Mitteäriline eesmärk 3.0 Eesti (CC BY-NC 3.0 EE) - https://creativecommons.org/licenses/by-nc/3.0/ee/

  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment