JĘZYK PYTHON - NARZĘDZIE DLA KAŻDEGO NAUKOWCA Marcin Lewandowski [ mlew@ippt.gov.pl ]
Z okazji dnia dziecka - 1 czerwca 2010 PYTHON DLA DZIECI Z MODUŁEM TURTLE 2
LOGO i moduł turtle LOGO język stworzony do nauki programowania przez Wally Feurzig & Seymour Papert w 1966/7 LOGO język funkcjonalny (dialekt Lisp) z grafiką żółwia Moduł turtle implementuje grafikę żółwia z LOGO w Pythonie 3
Żółw w trybie interaktywnym >>> from turtle import * >>> forward(100) >>> left(90) >>> forward(100) >>> left(90) >>> forward(100) >>> left(90) >>> forward(100) >>> left(90) 4
Grafiki Żółwia - ruchy Ruch i rysowanie forward() fd() backward() bk() back() right() rt() left() lt() goto() setpos() setposition() setx() sety() setheading() seth() home() circle() dot() stamp() clearstamp() clearstamps() undo() speed() Stan Żółwia position() pos() towards() xcor() ycor() heading() distance() Ustawienia degrees() radians() 5
Grafiki Żółwia - rysowanie Stan rysowania pendown() pd() down() penup() pu() up() pensize() width() pen() isdown() Kolor color() pencolor() fillcolor() Wypełnienie fill() begin_fill() end_fill() Inne reset() clear() write() 6
Grafiki Żółwia inne Widocznośd showturtle() st() hideturtle() ht() isvisible() Wygląd shape() resizemode() shapesize() turtlesize() settiltangle() tiltangle() tilt() Zdarzenia onclick() onrelease() ondrag() Inne metody begin_poly() end_poly() get_poly() clone() getturtle() getpen() getscreen() setundobuffer() undobufferentries() tracer() window_width() window_height() 7
Konfiguracja modułu turtle plik turtle.cfg width = 400 height = 300 canvwidth = 800 canvheight = 600 shape = turtle mode = logo language = german moduł turtle patrz dokumentacja Pythona 8
Przykłady Demo\* w dystrybucji źródeł Pyhona cgi CGI examples (see also../tools/faqwiz/.) classes Some examples of how to use classes. comparisons A set of responses to a really old language-comparison challenge. curses A set of curses demos. embed An example of embedding Python in another application (see also pysvr). imputil Demonstration subclasses of imputil.importer. md5test Test program for the optional md5 module. metaclasses The code from the 1.5 metaclasses paper on the web. parser Example using the parser module pdist Old, unfinished code messing with CVS, RCS and remote files pysvr An example of embedding Python in a threaded application rpc A set of classes for building clients and servers for Sun RPC scripts Some useful Python scripts that I put in my bin directory sockets Examples for the new built-in module 'socket' threads Demos that use the 'thread' module tix Demos using the Tix widget set addition to Tkinter tkinter Demos using the Tk interface (including Matt Conway's excellent set of demos) xml Some XML demos zlib Some demos for the zlib module (see also the standard library module gzip.py) turtle przykłady grafiki Żółwia 9
Demo\turtle\turtleDemo.py Aplikacja do uruchamiania przykładów (opisanych na następnym slajdzie) 10
Name Description Features bytedesign complex classical turtlegraphics pattern tracer(), delay, update() chaos graphs verhust dynamics, proves that you must not trust computers computations world coordinates clock analog clock showing time of your computer turtles as clock s hands, ontimer colormixer experiment with r, g, b ondrag() fractalcurves Hilbert & Koch curves recursion lindenmayer ethnomathematics (indian kolams) L-System minimal_hanoi Towers of Hanoi Rectangular Turtles as Hanoi discs (shape, shapesize) paint super minimalistic drawing program onclick() peace elementary turtle: appearance and animation penrose aperiodic tiling with kites and darts stamp() planet_and_moon simulation of gravitational system compound shapes, Vec2D tree a (graphical) breadth first tree (using generators) clone() wikipedia a pattern from the wikipedia article on turtle graphics clone(), undo() yingyang another elementary example circle() 11
LINKI http://www.briggs.net.nz/log/writing/snake-wrangling-forkids Snake Wrangling for Kids; Książka dla 8+ (wersja Windows/Linux/Mac) http://ada.rg16.asn-wien.ac.at/~python Python für Kids http://inventwithpython.com "Invent Your Own Computer Games with Python" http://www.pygame.org moduł pygame do pisania gier w Pythonie (w oparciu o SDL) http://www.cs.berkeley.edu/~bh Computer Science Logo Style V1-3 C.Sande, Hello World! Computer Programming for Kids and Other Beginners, MANNING, 2009 12