Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to draw a bat chart with Python

Shulou Source: shulou.com Published: 2022-06-01 20:18:31 09月11日 Update

This article mainly explains "how to draw a bat chart with Python". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to draw a bat chart with Python.

Preface

Halloween is coming!

Today I will give you a simple tutorial to draw a bat.

Bat ears

Before drawing, we need to introduce the turtle library needed for drawing. The code is as follows:

Import turtlet = turtle.Pen ()

After importing the library, we still create a new brush called t.

Next, we do a little analysis of this bat.

In the turtle drawing, the entire screen is separated by such a coordinate system, and the middle position of the screen is (0Power0), which is the initial position of the turtle.

Let's assume that each grid represents 10 pixels on the screen. Can you calculate the coordinates of the bat's ears?

OK, let's write a short piece of code first and see if what we draw is correct!

T.forward (10) t.goto (200.30)

A sharp corner has been drawn!

Next, find the coordinates of the point under the bat's ear!

The wings of a bat

It seems that we need to draw some curves next. Do you remember how to draw curves?

Using the circle () method, we can draw a circle, or a half circle, or a stroke of 4 circles!

Pay attention to the direction of brush t!

Next we will adjust the direction of the brush t to the right, and then draw a straight line.

T.right (90) t.forward (100)

Here, we draw a circle with a radius of 100 and an angle of 90 degrees!

Use the code to draw this part!

T.left (180) t.circle (100pl 90)

The code is as follows:

T.setheading (180) t.circle

Let's take a look at the pattern!

The first is the first green circle:

T.left (180) t.circle

Then there is the second blue circle:

T.right (90) t.circle (100per 90)

Don't forget next!

We still need to turn around and draw the rest of the bat, which needs to be done carefully compared to the previous code.

T.right (180) t.fd (100) t.right (90) t.circle (40) t.goto (- 20) t.goto (- 10) t.goto (0)

You can use t.hideturtle () to hide the brush t so that it looks more perfect!

At this point, I believe you have a deeper understanding of "how to draw a bat chart with Python". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Bat next code brush chart coordinates screen ear part position content circle direction method curve learning wrong practical deeper careful Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology OPPO Reno Redmi Shulou Tech Info MariaDB