• 技术文章 >Python技术 >Python基础教程

    python中怎样画小猪佩奇?

    小妮浅浅小妮浅浅2021-04-09 14:45:38原创4474

    1、绘图说明

    开发工具是pycham,pycham也是Python开发广泛使用的工具。使用的turtle库,当然安装了anaconda3这个库比较好。

    2、实例

    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

    148

    149

    150

    151

    152

    153

    154

    155

    156

    157

    158

    159

    160

    161

    162

    163

    164

    165

    166

    167

    168

    169

    170

    171

    172

    173

    174

    175

    176

    177

    178

    179

    180

    181

    182

    183

    184

    185

    186

    187

    188

    189

    190

    191

    192

    193

    194

    195

    196

    197

    198

    199

    200

    201

    202

    203

    204

    205

    206

    207

    208

    209

    210

    211

    212

    213

    214

    215

    216

    217

    218

    219

    220

    221

    222

    223

    224

    225

    226

    227

    228

    229

    230

    231

    232

    233

    234

    235

    236

    237

    238

    239

    240

    241

    242

    243

    244

    245

    246

    247

    248

    249

    250

    251

    252

    253

    254

    255

    256

    257

    258

    259

    260

    261

    262

    263

    264

    265

    266

    267

    268

    269

    270

    271

    272

    273

    274

    275

    276

    277

    278

    279

    280

    281

    282

    283

    284

    285

    import turtle as t

      

    t.pensize(4)

    t.hideturtle()

    t.colormode(255)

    t.color((255,155,192),"pink")

    t.setup(840,500)

    t.speed(10)

      

    #鼻子

    t.pu()

    t.goto(-100,100)

    t.pd()

    t.seth(-30)

    t.begin_fill()

    a=0.4

    for i in range(120):

        if 0<=i<30 or 60<=i<90:

            a=a+0.08

            t.lt(3) #向左转3度

            t.fd(a) #向前走a的步长

        else:

            a=a-0.08

            t.lt(3)

            t.fd(a)

    t.end_fill()

      

    t.pu()

    t.seth(90)

    t.fd(25)

    t.seth(0)

    t.fd(10)

    t.pd()

    t.pencolor(255,155,192)

    t.seth(10)

    t.begin_fill()

    t.circle(5)

    t.color(160,82,45)

    t.end_fill()

      

    t.pu()

    t.seth(0)

    t.fd(20)

    t.pd()

    t.pencolor(255,155,192)

    t.seth(10)

    t.begin_fill()

    t.circle(5)

    t.color(160,82,45)

    t.end_fill()

      

    #头

    t.color((255,155,192),"pink")

    t.pu()

    t.seth(90)

    t.fd(41)

    t.seth(0)

    t.fd(0)

    t.pd()

    t.begin_fill()

    t.seth(180)

    t.circle(300,-30)

    t.circle(100,-60)

    t.circle(80,-100)

    t.circle(150,-20)

    t.circle(60,-95)

    t.seth(161)

    t.circle(-300,15)

    t.pu()

    t.goto(-100,100)

    t.pd()

    t.seth(-30)

    a=0.4

    for i in range(60):

        if 0<=i<30 or 60<=i<90:

            a=a+0.08

            t.lt(3) #向左转3度

            t.fd(a) #向前走a的步长

        else:

            a=a-0.08

            t.lt(3)

            t.fd(a)

    t.end_fill()

      

    #耳朵

    t.color((255,155,192),"pink")

    t.pu()

    t.seth(90)

    t.fd(-7)

    t.seth(0)

    t.fd(70)

    t.pd()

    t.begin_fill()

    t.seth(100)

    t.circle(-50,50)

    t.circle(-10,120)

    t.circle(-50,54)

    t.end_fill()

      

    t.pu()

    t.seth(90)

    t.fd(-12)

    t.seth(0)

    t.fd(30)

    t.pd()

    t.begin_fill()

    t.seth(100)

    t.circle(-50,50)

    t.circle(-10,120)

    t.circle(-50,56)

    t.end_fill()

      

    #眼睛

    t.color((255,155,192),"white")

    t.pu()

    t.seth(90)

    t.fd(-20)

    t.seth(0)

    t.fd(-95)

    t.pd()

    t.begin_fill()

    t.circle(15)

    t.end_fill()

      

    t.color("black")

    t.pu()

    t.seth(90)

    t.fd(12)

    t.seth(0)

    t.fd(-3)

    t.pd()

    t.begin_fill()

    t.circle(3)

    t.end_fill()

      

    t.color((255,155,192),"white")

    t.pu()

    t.seth(90)

    t.fd(-25)

    t.seth(0)

    t.fd(40)

    t.pd()

    t.begin_fill()

    t.circle(15)

    t.end_fill()

      

    t.color("black")

    t.pu()

    t.seth(90)

    t.fd(12)

    t.seth(0)

    t.fd(-3)

    t.pd()

    t.begin_fill()

    t.circle(3)

    t.end_fill()

      

    #腮

    t.color((255,155,192))

    t.pu()

    t.seth(90)

    t.fd(-95)

    t.seth(0)

    t.fd(65)

    t.pd()

    t.begin_fill()

    t.circle(30)

    t.end_fill()

      

    #嘴

    t.color(239,69,19)

    t.pu()

    t.seth(90)

    t.fd(15)

    t.seth(0)

    t.fd(-100)

    t.pd()

    t.seth(-80)

    t.circle(30,40)

    t.circle(40,80)

      

    #身体

    t.color("red",(255,99,71))

    t.pu()

    t.seth(90)

    t.fd(-20)

    t.seth(0)

    t.fd(-78)

    t.pd()

    t.begin_fill()

    t.seth(-130)

    t.circle(100,10)

    t.circle(300,30)

    t.seth(0)

    t.fd(230)

    t.seth(90)

    t.circle(300,30)

    t.circle(100,3)

    t.color((255,155,192),(255,100,100))

    t.seth(-135)

    t.circle(-80,63)

    t.circle(-150,24)

    t.end_fill()

      

    #手

    t.color((255,155,192))

    t.pu()

    t.seth(90)

    t.fd(-40)

    t.seth(0)

    t.fd(-27)

    t.pd()

    t.seth(-160)

    t.circle(300,15)

    t.pu()

    t.seth(90)

    t.fd(15)

    t.seth(0)

    t.fd(0)

    t.pd()

    t.seth(-10)

    t.circle(-20,90)

      

    t.pu()

    t.seth(90)

    t.fd(30)

    t.seth(0)

    t.fd(237)

    t.pd()

    t.seth(-20)

    t.circle(-300,15)

    t.pu()

    t.seth(90)

    t.fd(20)

    t.seth(0)

    t.fd(0)

    t.pd()

    t.seth(-170)

    t.circle(20,90)

      

    #脚

    t.pensize(10)

    t.color((240,128,128))

    t.pu()

    t.seth(90)

    t.fd(-75)

    t.seth(0)

    t.fd(-180)

    t.pd()

    t.seth(-90)

    t.fd(40)

    t.seth(-180)

    t.color("black")

    t.pensize(15)

    t.fd(20)

      

    t.pensize(10)

    t.color((240,128,128))

    t.pu()

    t.seth(90)

    t.fd(40)

    t.seth(0)

    t.fd(90)

    t.pd()

    t.seth(-90)

    t.fd(40)

    t.seth(-180)

    t.color("black")

    t.pensize(15)

    t.fd(20)

      

    #尾巴

    t.pensize(4)

    t.color((255,155,192))

    t.pu()

    t.seth(90)

    t.fd(70)

    t.seth(0)

    t.fd(95)

    t.pd()

    t.seth(0)

    t.circle(70,20)

    t.circle(10,330)

    t.circle(70,30)

    t.done()

    以上就是python中画小猪佩奇的方法,希望对大家有所帮助。更多Python学习指路:python基础教程

    专题推荐:python
    上一篇:python模块中判断全局变量的赋值 下一篇:python如何绘制多拉A梦?

    相关文章推荐

    • python字符串如何简单运算• python如何用函数删除空白• Python浮点数的使用注意• python删除元素的使用条件• python列表排序的两种方式• python for…in循环的使用• python处理数字列表的函数• python切片如何进行索引• python中用切片复制列表• python字典中键值对的操作• python使用items()遍历键值对• python函数如何指定默认值• python函数中返回值的作用

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网