Python in turtle usage (lecture notes)

turtle Library Overview

turtle (turtle) library is a python turtle painting system to achieve
one of Python's standard library

#python computing ecosystem = + standard library third-party libraries
# standard library: with interpreter installed directly into the operating system function modules
# third-party libraries: need to go through the installation in order to use the function module

Library Library, pack Package, the module Module, collectively referred to as module

Is the entry-level graphics rendering library

Use of turtle

turtle principles
1.turtle real, imagine being in the form of a turtle center, walk on the canvas
2. path traversed formed a graphics rendering
3. turtles and program control, can change color, change the width

graphic form drawing turtle

graphic form drawing of turtle, turtle space of the canvas that is, the minimum unit is a pixel
window using turtle.setup (width, height, startx, stary) function (width, height [herein refers to the width and height and width of the form height is determined], the starting point [top left corner of the form relative to the upper left corner of the screen position] of x, y values, which after two selectable values can be freely determined)
(Setup this function is not required only if you when the need to control the size and position of the start of the form, the setup function are required to use)Here Insert Picture Description

turtle spatial we coordinate system

(Divided into two categories one is the absolute coordinates, and the other is the sea turtle coordinates)
turtle coordinates
absolute coordinates of the center of sea turtles in the beginning of the canvas, the location is the (0,0) coordinate, which is the absolute coordinate system, as shown in the x, y-axis is the absolute coordinate systemHere Insert Picture Description

Some functions make use of turtles in motion
turtle.goto (x, y) [let turtles anywhere, to (x, y) that point]

Turtle coordinates
Here Insert Picture Description
can use some functions, control turtle
turtlr.fd (d) running in the forward direction before the turtle d Note! Herein refers to which direction in front of the head toward the turtle
turtlr.bk (d) operating the turtle reverse direction d
turtle.circle (r, range) to the left of a point as the center to do curvilinear motion turtle

turtle angle coordinate system

Absolute angular coordinate systemHere Insert Picture Description

With function turtle.seth (angle) angle brackets is the direction of attention seth only to change direction, not take the initiative forward, angel for the absolute angle
turtle.left (angel) turn left angle how
much turtle.right (angel) Turn right angle

For a small chestnut, draw a Z

import turtle
turtle.left(45)
turtle.fd(150)
turtle.right(135)
turtle.fd(300)
turtle.left(135)
turtle.fd(150)

z strange, as long as it can draw
**

RBG color system

1, RGB means red, green and blue color combination of the three channels, each of the RGB colors in the range 0-255 0-1 certificate or decimal, the decimal is represented Turtle library using default, of course, we can modify the human

2. Use the function turtle.colormode (mode) to change color
if the decimal mode = 1.0 i.e., that change color with a subsequent full fractional
If mode = 255 is an integer that is the whole integer by a subsequent color change

3. a blogger common RGB color (whisper bb, color quite nice

Share curtain down notes
This is my school notes python courses on Chinese University mooc, the picture is a screenshot of courseware

Published an original article · won praise 0 · Views 12

Guess you like

Origin blog.csdn.net/m0_46238930/article/details/105183961