Institute of Computer Science
  1. Main page
  2. Teeme ise arvutimänge
ET
Log in

Teeme ise arvutimänge

  • Esileht
  • I RAAMAT
  • II RAAMAT
  • III RAAMAT
  • IV RAAMAT
  • V RAAMAT
  • VI RAAMAT

Tsükkel

Graafika Turtle mooduliga

Vaatame ühte lihtsat viisi, kuidas juba praegu saame käsitisi Pythonit kasutades midagi ekraanile joonistada.

Selleks kasutame Turtle moodulit. Mängude tegemiseks seda väga kasutada ei saa, aga erinevaid kujundeid saab joonistada hästi. :)

Sissejuhatuse selle mooduli kasutamisse teeb järgmine video.

Korduvad kujundid

Kui soovime for tsüklitega korrata ühte kujundit mitu korda, siis võib kasuks tulle veel ühe käsu teadmine.

Selleks on goto(), millel on 2 parameetrit, x telje koordinaat ja y telje koordinaat - ehk selle arvuline horisontaalne asukoht ja kõrgus.

Näide 5 x 5 kolmnurkadest koosnevat kujundtit joonistavast programmist:

 from turtle import *
 speed(0)
 for rida in range(5):
    for tulp in range (5):
      # Lähme sinna, kuhu soovime uut kujundit joonistada.
      up()
      goto(tulp * 50, rida * 50)     # Parameetrid on siin (x koordinaat, y koordiaat)
      down()

      # Joonistame kujundi enda.
      forward(30)
      left(120)
      forward(30)
      left(120)
      forward(30)
      left(120) #Pöörame tagasi algsuunda, et uus kujund tuleks samas suunas.
  • 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