Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize turtle Sea Turtle drawing by python

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article "python how to achieve turtle Turtle drawing", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "python how to achieve turtle Turtle drawing" article.

I. installation

Write a lot of interesting visual things

Can also draw a lot of wonderful patterns.

Pip install turtule II. Canvas

The canvas is what turtle unfolds for us to use in the drawing area.

We can set its size and initial position.

Import turtle# returns the default size (400,300) turtle.screensize () # set canvas method 1, set width, height, background color turtle.screensize (800,600, "green") # set canvas method 2, width and height is decimal to occupy the proportion of the computer screen, width and height is integer to pixel turtle.setup (width=0.6, height=0.6) # startx,starty indicates the position of vertices in the upper left corner of the rectangular window, if empty Then the window is located in the center of the screen turtle.setup (width=800, height=800, startx=100, starty=100) 3. Brush

You can set the properties of the brush, color, width of lines, etc.

Import turtle# sets the width of the brush turtle.pensize () # No parameter is passed, the current brush color is returned, and the parameter is passed to set the brush color turtle.pencolor () # set the speed of the brush, and the speed range of brush painting is an integer. The larger the number, the faster turtle.speed (speed) 4. Drawing command import turtle# move distance pixel length turtle.forward (distance) # move distance pixel length turtle.backward (distance) # move distance pixel length turtle.backward (distance) # move degree °turtle.right (degree) # counterclockwise move degree °turtle.left (degree) # draw graphics when you move turtle.pendown () # move the brush to the coordinate x The position of y is turtle.goto (XQuery y) # No graphics are drawn when you move, pick up the pen For drawing from another place, the speed range of drawing with turtle.penup () # brush [0Jing 10] integer turtle.speed (speed) # draws a circle with a positive (negative) radius Indicates that the center is on the left (right) side of the brush to draw a circle turtle.circle () 5. Brush Control Command import turtle# width of drawing turtle.pensize (width) # Brush Color turtle.pencolor () # fill Color turtle.fillcolor (colorstring) # also set pencolor=color1 and fillcolor=color2turtle.color (color1) Color2) # returns whether it is currently populated turtle.filling () # ready to start filling graphics turtle.begin_fill () # fill completed turtle.end_fill () # Hidden arrow shows turtle.hideturtle () # corresponding to hideturtle () function turtle.showturtle () VI. Global control command import turtle# clears the turtle window But the position and state of turtle will not change turtle.clear () # empty window, reset turtle state to start state turtle.reset () # undo the last turtle action turtle.undo () # return whether the current turtle is visible turtle.isvisible () # copy the current graphic stamp () # write text, s is the text content, font is the font parameter, which is the font name Size and type turtle.write (s [, font= ("font-name", font_size, "font_type")) VII. Draw a square helix from turtle import * for i in range: forward (I) left (91)

Draw a color spiral from turtle import * colors = ['red',' purple', 'blue',' green', 'yellow',' orange'] for x in range: pencolor (colors [x% 6]) width (x / 100 + 1) forward (x) left (59)

9. Draw sunflowers import turtle as timport timet.color ("red", "yellow") t.speed (10) t.begin_fill () for _ in range (50): t.forward (200) t.left (170) end_fill () time.sleep (1)

Draw import turtledef drawSnake (rad, angle, len, neckrad): for _ in range (len): turtle.circle (rad, angle) turtle.circle (- rad, angle) turtle.circle (rad, angle/2) turtle.forward (rad/2) # straight forward turtle.circle (neckrad, 180) turtle.forward (rad/4) if _ name__ = "_ _ main__": turtle.setup (1500, 1400, 0) 0) turtle.pensize (30) # Brush size turtle.pencolor ("green") turtle.seth (- 40) # forward direction drawSnake (70, 80, 2, 15)

11. Draw the pentagram import turtleimport timeturtle.pensize (5) turtle.pencolor ("yellow") turtle.fillcolor ("red") turtle.begin_fill () for _ in range (5): turtle.forward (200) turtle.right (144) turtle.end_fill () time.sleep (2) turtle.penup () turtle.goto (- 150) turtle.color ("violet") turtle.write ("Done", font= ('Arial', 40,' normal')) time.sleep (1)

Draw Peggy Pig from turtle import*# draw nose def nose (xMaginy): pu () goto (xpeny) pd () seth (- 30) begin_fill () a=0.4for i in range (120): if 0

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report