# data[].attributes.headline
Piramida w trójkącie równobocznym - rozwiąz.

# data[].attributes.subject
Piramida w trójkącie równobocznym - rozwiąz.

# data[].attributes.body
from turtle import*

from math import sqrt

# prostokąt

def pr(a,b):

fillcolor('green')

begin_fill()

for i in range(2):

fd(a);rt(90)

fd(b);rt(90)

end_fill()

# pr(30,20)

# trójkąt równoboczny

def tr(a):

for i in range(3):

fd(a)

lt(120)

# tr(50)

# rząd prostokątów

def rzad(n,a,b):

for i in range(n):

pr(a,b); fd (a)

bk(n*a)

pu();lt(90);fd(b);rt(90);fd(a/2);pd()

#rzad(5,40,30)

# piramida z prostokątów

def pir (n,a,b):

speed(100)

pu();bk(200);rt(90);fd(200);lt(90);pd()

#print(pos())

for i in range(n):

rzad(n-i,a,b)

pu();rt(90);fd(b);lt(90)

#pu();goto(-200.00,-200.00);pd()

#pu();rt(90);fd(a);lt(90);bk(a/2);pd()

#pir(5,40,30)

# piramida w trójkącie równobocznym

def piramida (n, dl):

a = dl / (n+1)

# b - wysokość w trójkącie równobocznym

b = a * sqrt(3)/2

pir(n,a,b)

pu();goto(-200.00,-200.00);pd()

pu();rt(90);fd(b);lt(90);bk(a/2);pd()

tr(dl)

piramida(5, 400)

# data[].attributes.attachment_link.description
Animated global statistics that everyone can understand

# data[].attributes.attachment_link.readable_text
Source code: Lib/turtle.py

Introduction

Turtle graphics is an implementation of the popular geometric drawing tools introduced in Logo, developed by Wally Feurzeig, Seymour Papert and Cynthia Solomon in 1967.

In Python, turtle graphics provides a representation of a physical "turtle" (a little robot with a pen) that draws on a sheet of paper on the floor.

It's an effective and well-proven way for learners to encounter programming concepts and interaction with software, as it provides instant, visible feedback. It also provides convenient access to graphical output in general.

Turtle drawing was originally created as an educational tool, to be used by teachers in the classroom. For the programmer who needs to produce some graphical output it can be a way to do that without the overhead of introducing more complex or external libraries into their work.

Tutorial

New users should start here. In this tutorial we'll explore some of the basics of turtle drawing.

Starting a turtle environment

In a Python shell, import all the objects of the module:

Basic drawing

Send the turtle forward 100 steps:

You should see (most likely, in a new window on your display) a line drawn by the turtle, heading East. Change the direction of the turtle, so that it turns 120 degrees left (anti-clockwise):

Let's continue by drawing a triangle:

Notice how the turtle, represented by an arrow, points in different directions as you steer it.

Experiment with those commands, and also with and .

Pen control

Try changing the color - for example, - and width of the line - for example, - and then drawing again.

You can also move the turtle around without drawing, by lifting up the pen: before moving. To start drawing again, use .

The turtle's position

Send your turtle back to its starting-point (useful if it has disappeared off-screen):

The home position is at the center of the turtle's screen. If you ever need to know them, get the turtle's x-y co-ordinates with:

And after a while, it will probably help to clear the window so we can start anew:

Making algorithmic patterns

Using loops, it's possible to build up geometric patterns:

- which of course, are limited only by the imagination!

Let's draw the star shape at the top of this page. We want red lines, filled in with yellow:

Just as and determine whether lines will be drawn, filling can be turned on and off:

Next we'll create a loop:

is a good way to know when the turtle is back at its home position.

Finally, complete the filling:

(Note that filling only actually takes place when you give the command.)

How to...

This section covers some typical turtle use-cases and approaches.

Get started as quickly as possible

One of the joys of turtle graphics is the immediate, visual feedback that's available from simple commands - it's an excellent way to introduce children to programming ideas, with a minimum of overhead (not just children, of course).

The turtle module makes this possible by exposing all its basic functionality as functions, available with . The turtle graphics tutorial covers this approach.

It's worth noting that many of the turtle commands also have even more terse equivalents, such as for . These are especially useful when working with learners for whom typing is not a skill.

You'll need to have the installed on your system for turtle graphics to work. Be warned that this is not always straightforward, so check this in advance if you're planning to use turtle graphics with a learner.

Use the module namespace

Using is convenient - but be warned that it imports a rather large collection of objects, and if you're doing anything but turtle graphics you run the risk of a name conflict (this becomes even more an issue if you're using turtle graphics in a script where other modules might be imported).

Use turtle graphics in a script

It's recommended to use the module namespace as described immediately above, for example:

Another step is also required though - as soon as the script ends, Python will also close the turtle's window. Add:

to the end of the script. The script will now wait to be dismissed and will not exit until it is terminated, for example by closing the turtle graphics window.

Use object-oriented turtle graphics

Other than for very basic introductory purposes, or for trying things out as quickly as possible, it's more usual and much more powerful to use the object-oriented approach to turtle graphics. For example, this allows multiple turtles on screen at once.

In this approach, the various turtle commands are methods of objects (mostly of objects). You can use the object-oriented approach in the shell, but it would be more typical in a Python script.

The example above then becomes:

Note the last line. is an instance of the that a Turtle instance exists on; it's created automatically along with the turtle.

The turtle's screen can be customised, for example:

Turtle graphics reference

Note

In the following documentation the argument list for functions is given. Methods, of course, have the additional first argument self which is omitted here.

Methods of TurtleScreen/Screen

Window control

Animation control

Using screen events

Settings and special methods

Input methods

Methods specific to Screen

Methods of RawTurtle/Turtle and corresponding functions

Most of the examples in this section refer to a Turtle instance called .

Turtle motion

Stamp a copy of the turtle shape onto the canvas at the current turtle position. Return a stamp_id for that stamp, which can be used to delete it by calling clearstamp(stamp_id) .

Tell Turtle's state

Settings for measurement

Set the angle measurement units to radians. Equivalent to degrees(2*math.pi) .

Pen control

Drawing state

Set the line thickness to width or return it. If resizemode is set to "auto" and turtleshape is a polygon, that polygon is drawn with the same line thickness. If no argument is given, the current pensize is returned.

Parameters

Return or set the pen's attributes in a "pen-dictionary" with the following key/value pairs:

"shown": True/False

"pendown": True/False

"pencolor": color-string or color-tuple

"fillcolor": color-string or color-tuple

"pensize": positive number

"speed": number in range 0..10

"resizemode": "auto" or "user" or "noresize"

"stretchfactor": (positive number, positive number)

"outline": positive number

"tilt": number

Filling

To be called just before drawing a shape to be filled.

Whether or not overlap regions for self-intersecting polygons or multiple shapes are filled depends on the operating system graphics, type of overlap, and number of overlaps. For example, the Turtle star above may be either all yellow or have some white regions.

More drawing control

Delete the turtle's drawings from the screen, re-center the turtle and set variables to the default values.

Delete the turtle's drawings from the screen. Do not move turtle. State and position of the turtle as well as drawings of other turtles are not affected.

Turtle state

Appearance

Return or set the pen's attributes x/y-stretchfactors and/or outline. Set resizemode to "user". If and only if resizemode is set to "user", the turtle will be displayed stretched according to its stretchfactors: stretch_wid is stretchfactor perpendicular to its orientation, stretch_len is stretchfactor in direction of its orientation, outline determines the width of the shape's outline.

Rotate the turtleshape to point in the direction specified by angle, regardless of its current tilt-angle. Do not change the turtle's heading (direction of movement).

Deprecated since version 3.1.

Set or return the current transformation matrix of the turtle shape.

If none of the matrix elements are given, return the transformation matrix as a tuple of 4 elements. Otherwise set the given elements and transform the turtleshape according to the matrix consisting of first row t11, t12 and second row t21, t22. The determinant t11 * t22 - t12 * t21 must not be zero, otherwise an error is raised. Modify stretchfactor, shearfactor and tiltangle according to the given matrix.

Return the current shape polygon as tuple of coordinate pairs. This can be used to define a new shape or components of a compound shape.

Using events

Special Turtle methods

Compound shapes

To use compound turtle shapes, which consist of several polygons of different color, you must use the helper class explicitly as described below:

1. Create an empty Shape object of type "compound".

2. For example:

3. Now add the Shape to the Screen's shapelist and use it:

Note

The class is used internally by the method in different ways. The application programmer has to deal with the Shape class only when using compound shapes like shown above!

Methods of TurtleScreen/Screen and corresponding functions

Most of the examples in this section refer to a TurtleScreen instance called .

Animation control

See also the RawTurtle/Turtle method .

Input methods

Pop up a dialog window for input of a number. title is the title of the dialog window, prompt is a text mostly describing what numerical information to input. default: default value, minval: minimum value for input, maxval: maximum value for input. The number input must be in the range minval .. maxval if these are given. If not, a hint is issued and the dialog remains open for correction. Return the number input. If the dialog is canceled, return .

Settings and special methods

Methods specific to Screen, not inherited from TurtleScreen

Bind method to mouse clicks on the Screen.

If the value "using_IDLE" in the configuration dictionary is (default value), also enter mainloop. Remark: If IDLE with the switch (no subprocess) is used, this value should be set to in . In this case IDLE's own mainloop is active also for the client script.

Explanation

A turtle object draws on a screen object, and there a number of key classes in the turtle object-oriented interface that can be used to create them and relate them to each other.

A instance will automatically create a instance if one is not already present.

is a subclass of , which doesn't automatically create a drawing surface - a canvas will need to be provided or created for it. The canvas can be a tkinter.Canvas , or .

is the basic drawing surface for a turtle. is a subclass of TurtleScreen , and includes some additional methods for managing its appearance (including size and title) and behaviour. TurtleScreen 's constructor needs a tkinter.Canvas or a as an argument.

The functional interface for turtle graphics uses the various methods of and TurtleScreen /. Behind the scenes, a screen object is automatically created whenever a function derived from a method is called. Similarly, a turtle object is automatically created whenever any of the functions derived from a Turtle method is called.

To use multiple turtles on a screen, the object-oriented interface must be used.

Help and configuration

How to use help

The public methods of the Screen and Turtle classes are documented extensively via docstrings. So these can be used as online-help via the Python help facilities:

When using IDLE, tooltips show the signatures and first lines of the docstrings of typed in function-/method calls.

The docstrings of the functions which are derived from methods have a modified form:

These modified docstrings are created automatically together with the function definitions that are derived from the methods at import time.

Translation of docstrings into different languages

There is a utility to create a dictionary the keys of which are the method names and the values of which are the docstrings of the public methods of the classes Screen and Turtle.

If you (or your students) want to use with online help in your native language, you have to translate the docstrings and save the resulting file as e.g. turtle_docstringdict_german.py .

If you have an appropriate entry in your file this dictionary will be read in at import time and will replace the original English docstrings.

At the time of this writing there are docstring dictionaries in German and in Italian. (Requests please to .)

How to configure Screen and Turtles

The built-in default configuration mimics the appearance and behaviour of the old turtle module in order to retain best possible compatibility with it.

If you want to use a different configuration which better reflects the features of this module or which better fits to your needs, e.g. for use in a classroom, you can prepare a configuration file which will be read at import time and modify the configuration according to its settings.

The built in configuration would correspond to the following :

Short explanation of selected entries:

shape can be any of the built-in shapes, e.g: arrow, turtle, etc. For more info try .

If you want to use no fill color (i.e. make the turtle transparent), you have to write (but all nonempty strings must not have quotes in the cfg file).

If you want to reflect the turtle its state, you have to use .

If you set e.g. the docstringdict turtle_docstringdict_italian.py will be loaded at import time (if present on the import path, e.g. in the same directory as ).

The entries exampleturtle and examplescreen define the names of these objects as they occur in the docstrings. The transformation of method-docstrings to function-docstrings will delete these names from the docstrings.

using_IDLE: Set this to if you regularly work with IDLE and its switch ("no subprocess"). This will prevent to enter the mainloop.

There can be a file in the directory where is stored and an additional one in the current working directory. The latter will override the settings of the first one.

The Lib/turtledemo directory contains a file. You can study it as an example and see its effects when running the demos (preferably not from within the demo-viewer).

Changes since Python 2.6

The methods , and have been eliminated. Methods with these names and functionality are now available only as methods of . The functions derived from these remain available. (In fact already in Python 2.6 these methods were merely duplications of the corresponding / methods.)

The method Turtle.fill() has been eliminated. The behaviour of and have changed slightly: now every filling process must be completed with an call.

A method has been added. It returns a boolean value: if a filling process is under way, otherwise. This behaviour corresponds to a call without arguments in Python 2.6.

Changes since Python 3.0

# data[].attributes.attachment_link.description
Source code: Lib/turtle.py Introduction: Turtle graphics is an implementation of the popular geometric drawing tools introduced in Logo, developed by Wally Feurzeig, Seymour Papert and Cynthia Solo...

# data[].attributes.attachment_link.readable_text
Wikibooks

Wikibooks

Wikibooks

Python jest interpretowanym, interaktywnym językiem programowania stworzonym przez Guido van Rossuma w 1990 roku. Posiada w pełni dynamiczny system typów i automatyczne zarządzanie pamięcią, jest zatem podobny do takich języków, jak Tcl, Perl, Scheme czy Ruby. Python rozwijany jest jako projekt Open Source, zarządzany przez niedochodową Python Software Fundation. Najnowsza wersja stabilna to wersja 3.8.1 z 18 grudnia 2019 i można ją pobrać stąd.

Python jest językiem stosunkowo prostym do nauczenia.

Niniejszy podręcznik powstaje na podstawie książki Dive into Python Marka Pilgrima (w większości jest to tłumaczenie) udostępnionej na licencji Creative Commons Attribution Share-Alike. Kody wszystkich przykładów można pobrać stąd.

W przygotowaniu:

Podręcznik co prawda został już przetłumaczony, ale wymaga poprawek i uaktualnień. Rzeczy, które należy teraz wykonać można znaleźć w Zaleceniach dla autorów.

Istnieje potrzeba opisu zastosowania Pythona w Blenderze. Chętni proszeni o pilną pomoc w opracowaniu!

# data[].attributes.attachment_link.title
Zanurkuj w Pythonie - Wikibooks, biblioteka wolnych podręczników

# data[].attributes.attachment_link.description
Python jest interpretowanym, interaktywnym językiem programowania stworzonym przez Guido van Rossuma w 1990 roku. Posiada w pełni dynamiczny system typów i automatyczne zarządzanie pamięcią, jest zatem podobny do takich języków, jak Tcl, Perl, Scheme czy Ruby. Python rozwijany jest jako projekt Open Source, zarządzany przez niedochodową Python Software Fundation.

# data[].attributes.body
Zapis "ab" * 5 odpowiada napisowi "ababababab" o długości 10.
Jaka jest długość napisu "abc" * 6?

# data[].attributes.headline
Zadanie 3 - Posadzka; Zadanie 1 - Wiatrak

# data[].attributes.subject
Zadanie 3 - Posadzka; Zadanie 1 - Wiatrak

# data[].attributes.attachment_link.description
Hasła należy wybierać mądrze. Aby sprawdzić siłę swoich haseł, odwiedź tę stronę.

# data[].attributes.headline
Uruchom arkusz kalkulacyjny EXCEL i wykonaj zadania.

# data[].attributes.subject
Uruchom arkusz kalkulacyjny EXCEL i wykonaj zadania.

# data[].attributes.body
Zadanie 1
Wybierz po 2 państwa z różnych części świata i dowiedz się, jaki % populacji korzysta z Internetu. Przedstaw dane na wykresie kolumnowym.

Zadanie 2
Początki Internetu na świecie.

Zadanie 3
Wyszukaj dane na temat liczby ludności (populacja) dla 5 wybranych państw na rok 1930, 1945, 1980, najnowsze dane. Przedstaw dane na wykresie liniowym.

Zadanie 4
Emisja CO2 na osobę. Państwa rozwinięte vs rozwijające się (dane aktualne, z poprzednich lat)

Zadanie 5
Inflacja, wybrane państwa (co za wydarzenia miały miejsce w 1929, 945, 2008?)
1929
1945
2008
2021
2023

# data[].attributes.attachment_link.title
DuckDuckGo - Protection. Privacy. Peace of mind.

# data[].attributes.attachment_link.description
The Internet privacy company that empowers you to seamlessly take control of your personal information online, without any tradeoffs.

# data[].attributes.body
password (do złamania w <1 s)

123456 (do złamania w <1 s)

123456789 (do złamania w <1 s)

guest (do złamania w 10 s)

qwerty (do złamania w <1 s)

12345678 (do złamania w <1 s)

111111 (do złamania w <1 s)

12345 (do złamania w <1 s)

col123456 (do złamania w 11 s)

123123 (do złamania w <1 s)

1234567 (do złamania w <1 s)

1234 (do złamania w <1 s)

1234567890 (do złamania w <1 s)

000000 (do złamania w <1 s)

555555 (do złamania w <1 s)

666666 (do złamania w <1 s)

123321 (do złamania w <1 s)

654321 (do złamania w <1 s)

7777777 (do złamania w <1 s)

123 (do złamania w <1 s)

D1lakiss (do złamania w 3 h)

777777 (do złamania w <1 s)

110110jp (do złamania w 3 s)

1111 (do złamania w <1 s)

987654321 (do złamania w <1 s)