| |||
|
| ||
|
| |||
|
| ||
|
COMMAND | USAGE EXAMPLE |
pendown(), pd() | pd() |
The spaceship has the pen down (active) and draws a line in its trail. | |
penup(), pu() | pu() |
The spaceship has the pen up (inactive) and does not draw a line in its trail. | |
pensize(value), width(value) | pensize(25) |
Sets the pen tip size to value pixels.
|
|
pencolor(color) | pencolor("#ff00ff") |
Sets the drawing color.
The color parameter can be specified using standard names or HEX values (internet format).
Examples:
pencolor('red')
"yellow" (), "white" (), "brown" (), "tan" (), "green" (), "aquamarine" (), "salmon" (), "purple" (), "orange" (), "gray" (). |
|
fillcolor(color) | fillcolor("yellow") |
Sets the fill color (default is black).
The color parameter can be a
standard name or a HEX code (internet format).Examples:
fillcolor("red")
|
|
color(c_drawing[,c_filling]) | color("red","green") |
We can modify both the drawing and filling colors simultaneously.
If the c_filling parameter is missing,
the color described by c_drawing is used for both attributes.
|
COMMAND | EXAMPLE OF USE | ||
stamp() | stamp() | ||
Draws a copy of the turtle's shape on the canvas at the current position, like a stamp. | |||
begin_fill() | begin_fill() | ||
Starts a new path that describes a geometric shape (a polygon). | |||
end_fill() | end_fill() | ||
Closes the current path and fills the geometric shape with the fill color (see fillcolor()).
Example. The following program draws a green square. The fill color is set first, then the path is started with begin_fill():
The desired geometric shape is drawn, and the end_fill() command closes the path and fills it with green. |
|||
fill() | print(fill()) ; if (fill()) ... | ||
The function returns a boolean value based on the fill mode state:
true (True )
or false (False ), useful
in some slightly more complex programs.
|
|||
dot() | dot() | ||
Draws a dot at the current position. The function is very useful if you want to
use it in combination with penup(), drawing only certain important points during the
turtle's movement.
Example. Below we draw only the corners of a square:
|
|||
circle(radius, angle, steps) | circle(50,360,100) | ||
A circle is characterized by radius , which is the distance from the center to any point on it.
Then, you need to understand that a circle is made up of steps points.
You can draw a full circle using angle value of 360 degrees
or just a part of it, specifically an arc, by specifying a smaller angle accordingly.
The larger the steps , the finer the drawing of the geometric shape.
The magic of geometry. When steps = 4 ,
a square (like a diamond) is drawn, and for
steps = 5 , a pentagon.
Choosing steps = 6 gives us a hexagon, and so on.
The larger the steps parameter value,
the closer the regular polygon approximates the circle it inscribes!
Examples. Test the code below to understand better:
|
|||
write(message, move, alignment, font) | write("Hello") | ||
Writes the text from message starting from the current position. The move parameter is boolean
(True / False ) and
allows the turtle to move or not while the message is being drawn. The alignment parameter
can take values "left" , "center" , or
"right" . The text style is entered as a tuple of data:
(font, size, font_style) .
Example. Below is text written without moving the turtle ( False ),
aligned to the left and with a specific style set:
Notes • The font_style parameter can be "normal" ,
"italic" , or "bold" .
• To move the turtle without drawing a line, you can of course use penup() before the write() command, and then return with pendown():
from turtle import *
• Only the text as message is a mandatory parameter,
while the rest are optional. Play with different text style values! For example, common standard font names are:
"Tahoma ", "Verdana ",
"Arial ", "Calibri ", etc.
|
COMMAND | EXAMPLE OF USE |
variable_name = clone() | clone1 = clone() |
A new variable, accessible through variable_name ,
will hold a new graphic object (an identical spaceship)
that can be controlled using the Python programming language. The position on the screen and other parameters will also be identical
with all attributes of the "parent" ship. You can create one clone, two ... or as many as you want!
Note! The "parent" ship can still be controlled with direct commands like
fd(80), but
clone1 in the example will receive
instructions such as clone1.fd(50) because they are different objects on the screen,
and addressing must be done accordingly!
Important observation! Python is an interpreter and
executes instructions sequentially, that is, one after the other.
Thus, graphic objects on the screen will perform animations alternately depending on the program you create!
Example. Test the code below:
from turtle import *
|
|
variable_name = Turtle() | ship2 = Turtle() |
A new variable, accessible through variable_name ,
will hold a new graphic object (a new spaceship).
Unlike clone(), this function creates a new object with default parameters starting from coordinates (0,0).
Example. Test the code below:
from turtle import *
A little trick. To simulate the simultaneous movement of two spaceships, we can move them with a small step (e.g., 1 pixel) alternately, as in the example below:
from turtle import *
The speed of the two ships in this case still decreases significantly... |
forward(50)
will make the turtle move straight ahead a certain distance.
forward(100)
will make it move in the same
direction twice as far. Soon, you will grasp the idea that numbers represent the distance it moves; they can be
considered as steps. Now, if you want it to move in a different direction, you enter a command like right(90)
. It will stay
in the same place but turn east if it was initially facing north. With this knowledge, you will
be able to draw a circle or a rectangle easily. And if this is easy for you,
you can think about drawing a circle or try to draw a spiral.