Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Turtle Library to draw a Tiger by Python

Shulou Source: shulou.com Published: 2022-06-01 18:31:52 10月03日 Update

This article will explain in detail how Python uses the Turtle library to draw a tiger. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Introduction

Hello, iron juices. I haven't seen you for a long time. The editor has returned to work, so he came non-stop to prepare New year's gifts for everyone.

Sea turtles come to make pictures.

The year of the Tiger is about drawing tigers.

2022 without paper and pen ~

Draw a tiger tonight.

One, two, three, four, five.

Schematic diagram of baby tiger

How can there be fewer tigers in the year of the Tiger? Draw a lovely tiger with a tiger's head and light it on New year's Eve. Do not need paper and pen, rely on Python sea turtles to draw, children hurry up the code to knock it!

1. Definition library and initialization interface def laohu (): import turtle as t # sets the screen size and color t.screensize (50,50, bg='yellow') t.title ("tiger baby") t.shape ("classic") t.pensize (10) t.color ("orange") t.fillcolor ("pink") t.speed (100) t.hideturtle () 2. Draw the left and right ears # t.penup () t.goto (- 105,97) t.setheading (160,160) t.begin_fill () t.pendown () t.circle (- 30,230) t.setheading (180) t.circle (37,90) t.end_fill () # right ear t.penup () t.goto 97) t.setheading (20) t.begin_fill () t.pendown () t.circle (30,230) t.setheading (0) t.circle (- 37,90) t.end_fill () 3. Draw the outline of the tiger's head # t.penup () t.goto (- 67,140) t.setheading (30) t.pendown () t.circle (- 134,60) t.penup () t.goto (- 50,-25) t.setheading (180) t.pendown () t.circle (- 100,30) t.circle (- 30) 90) t.setheading (100,20) t.penup () t.goto (50,25) t.setheading (0) t.pendown () t.circle (100,30) t.circle (30,90) t.setheading (80) t.circle (200,20) 4. Draw the tiger's two eyes # two tiger eyes # left eye t.penup () t.goto (- 90,25) t.setheading (- 45) t.fillcolor ("orange") t.begin_fill () t.pendown () # Ellipse drawing technique a = 0.2for i in range (120): if 0

Tags: Tiger step size gift article code function head Arial baby technique text more ellipse sea turtle paper interface arrowhead limb toe outline Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Xiaomi OPPO Reno Microsoft macOS