Let’s go through the simple program above…Īfter importing the Turtle module we set the pencolor (for the border of the shape) and the fillcolor (to fill the shape) using the color() function. Is inside the 1st quadrant (positive x and y axis).The first shape we will draw is a square that: Let’s start drawing the first shape… Drawing a Square with Turtle Using this principle you can draw as many lines as you want and rotating the cursor using any angle you prefer. Once you change direction for the cursor you can move the cursor forward and draw a second line (position 4). The Turtle module provides a way to do that before drawing the next line. Now, if we want to draw a line in the direction of the y axis, that starts at position (30,0) and it’s perpendicular to the x axis, we have to rotate the cursor by 90 degrees anti-clockwise (position 3 in the picture below). You can identify the position of a point in the x-y plane by giving a specific value to x and y. While moving, the cursor draws a line, so in this case we would have a line that connects the points with coordinates (0,0) and (30,0). Think about the x-y plane and imagine that there is a cursor at position (0, 0) pointing in the direction of the positive x axis (position 1 in the picture below).Īt this point you can use a Turtle function to move the cursor in the direction it’s facing by a certain amount of pixels (position 2 in the picture below). Before drawing a shape we have to understand the basic concepts used by the Turtle module to draw.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |