Home Backend Development Python Tutorial How to draw simple animals using python

How to draw simple animals using python

Feb 05, 2020 am 10:02 AM
python animal Simple

How to draw simple animals using python

First let’s take a look at the implementation effect, as shown below:

How to draw simple animals using python

Please see the specific implementation code:

( Recommended learning: python video tutorial)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

# -*- coding:utf-8 -*-

# __author__ :kusy

# __content__:文件说明

# __date__:2018/8/21 13:08

import turtle

import time

import math as m

 

 

class Sheep(object):

 

    def __init__(self,xsize):

        self.t = turtle.Turtle()

        self.xsize = xsize

        t = self.t

        # 画笔设置

        t.screen.screensize(canvwidth=1000,canvheight=500,bg='white')

        t.pensize(2)

        t.speed(10)

        # t.hideturtle()

        #初始化画笔位置

        t.penup()

        t.setpos(self.xsize,0)

        t.pendown()

 

    # 设置画笔坐标

    def setxy(self,x,y):

        t = self.t

        t.penup()

        pos_x = t.position()[0]

        pos_y = t.position()[1]

        t.setpos(pos_x + x,pos_y + y)

        t.pendown()

 

    def create_sheep(self):

        t = self.t

        # 羊头

        self.setxy(-200,0)

        t.fillcolor('black')

        t.begin_fill()

        t.circle(100)

        t.end_fill()

 

        # 眼睛

        # 眼白

        print(t.position())

        self.setxy(-20,120)

 

        t.fillcolor('white')

        t.begin_fill()

        t.seth(45)

        t.circle(18,-280)

        t.seth(45)

        t.circle(-20,292)

        t.end_fill()

        # 眼珠

        self.setxy(3,12)

        t.fillcolor('black')

        t.begin_fill()

        t.seth(85)

        t.circle(10)

        t.seth(85)

        t.circle(-10)

        t.end_fill()

        # 眼心

        t.fillcolor('white')

        t.begin_fill()

        t.seth(85)

        t.circle(3)

        t.seth(85)

        t.circle(-3)

        t.end_fill()

 

        # 嘴

        self.setxy(0,-100)

        t.color('red')

        t.seth(300)

        t.forward(8)

        self.setxy(-1, 3)

        t.seth(0)

        t.circle(80,60)

        self.setxy(2, -2)

        t.seth(145)

        t.forward(8)

        t.color('black')

 

        # 耳朵

        self.setxy(-145,120)

        p1 = t.position()

        t.fillcolor('black')

        t.begin_fill()

        t.seth(0)

        t.circle(-120,20)

        p2 = t.position()

        t.setpos(p1)

        t.seth(60)

        t.circle(-30,120)

        t.goto(p2)

        t.end_fill()

 

        # 身体

        self.setxy(41,12)

        t.seth(45)

        t.circle(-150,100)

        t.pensize(5)

        t.seth(0)

        t.circle(-120,30)

        t.seth(60)

        t.circle(-15,320)

        t.seth(330)

        t.circle(-80,180)

        t.seth(210)

        t.circle(-80,90)

 

        #4条腿

        t.pensize(2)

        for leg in range(4):

            self.setxy(8+15*leg,0)

            t.seth(270)

            t.forward(80)

            t.seth(0)

            t.forward(8)

            t.seth(90)

            t.forward(80)

 

        #草

        self.setxy(-200,-80)

        p3 = t.position()

        t.color('green')

        t.fillcolor('green')

        t.begin_fill()

        t.seth(120)

        t.forward(30)

        t.seth(330)

        t.forward(30)

        t.seth(60)

        t.forward(40)

        t.seth(260)

        t.forward(45)

        t.setpos(p3)

        t.end_fill()

 

if __name__ == '__main__':

    for x in (0,350):

        sheep = Sheep(x)

        sheep.create_sheep()

    time.sleep(5)

Copy after login

Related article tutorial recommendation: python tutorial

The above is the detailed content of How to draw simple animals using python. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

Can vs code run in Windows 8 Can vs code run in Windows 8 Apr 15, 2025 pm 07:24 PM

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Is the vscode extension malicious? Is the vscode extension malicious? Apr 15, 2025 pm 07:57 PM

VS Code extensions pose malicious risks, such as hiding malicious code, exploiting vulnerabilities, and masturbating as legitimate extensions. Methods to identify malicious extensions include: checking publishers, reading comments, checking code, and installing with caution. Security measures also include: security awareness, good habits, regular updates and antivirus software.

How to run programs in terminal vscode How to run programs in terminal vscode Apr 15, 2025 pm 06:42 PM

In VS Code, you can run the program in the terminal through the following steps: Prepare the code and open the integrated terminal to ensure that the code directory is consistent with the terminal working directory. Select the run command according to the programming language (such as Python's python your_file_name.py) to check whether it runs successfully and resolve errors. Use the debugger to improve debugging efficiency.

Can visual studio code be used in python Can visual studio code be used in python Apr 15, 2025 pm 08:18 PM

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

Can vscode run ipynb Can vscode run ipynb Apr 15, 2025 pm 07:30 PM

The key to running Jupyter Notebook in VS Code is to ensure that the Python environment is properly configured, understand that the code execution order is consistent with the cell order, and be aware of large files or external libraries that may affect performance. The code completion and debugging functions provided by VS Code can greatly improve coding efficiency and reduce errors.

See all articles