Get the App
SLTechnology News&Howtos  ›  Development  › 

How to draw a picture through python-turtle library

Shulou Source: shulou.com Published: 2022-06-02 06:13:38 10月03日 Update

This article is about how to draw pictures through the python-turtle library. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1 figure 1

The first picture is mosquito-repellent incense. Interested partners can try to draw it with the turtle library in python.

The specific code is as follows:

# painting mosquito-repellent incense import turtleturtle.pensize (30) for i in range (30): turtle.circle (iMOS 10) turtle.done () 2 figure 2

The second picture is a variant of mosquito-repellent incense. How to change the color and shape of mosquito-repellent incense by adjusting the code to draw the following figure?

The specific code is as follows:

Import turtlet = turtle.Turtle () t.pensize (2) t.color ('violet') for i in range (90): t.circle (iMagne 60) 3 figure 3

The third picture is a cobweb map, but different parts have different colors, you can also try to change to other colors.

The specific code is as follows:

# draw cobwebs from turtle import * speed (0) t = 1for i in range (100): if t = 1: color ('darkviolet') fd (2onomi) rt (61) t + = 1 elif t = 2: color (' green') fd (2onomi) rt (61) t + = 1 else: color ('yellow') Fd (2chimi) rt (61) t = 14 figure 4

The fourth picture is the Olympic rings.

The specific code is as follows:

# draw Olympic rings import turtleturtle.width (5) # control brush width colors = ['blue',' black', 'red',' yellow', 'green'] for i in range (5): turtle.color (colors [I]) # control brush color turtle.circle (50) # control circle size, radius turtle.penup () # Let brush lift if I

Tags: Code mosquito-repellent incense color brush control picture different five-star red flag content Olympic Games more articles five stars five rings red flag good practical three medium use interest Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Docker OPPO Reno NVidia Linux