python史迪仔代码
时间: 2023-11-08 08:05:09 浏览: 291
以下是一个 Python 史迪仔的代码:
```
# -*- coding: utf-8 -*-
import turtle
# 绘制身体
def body():
turtle.pensize(40)
turtle.pencolor('#000000')
turtle.fillcolor('#00a0de')
turtle.begin_fill()
turtle.circle(80)
turtle.end_fill()
# 绘制眼睛
def eyes():
turtle.pensize(4)
turtle.pencolor('#ffffff')
turtle.fillcolor('#ffffff')
turtle.penup()
turtle.goto(-35, 130)
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.goto(-38, 150)
turtle.pendown()
turtle.fillcolor('#000000')
turtle.begin_fill()
turtle.circle(8)
turtle.end_fill()
turtle.penup()
turtle.goto(35, 130)
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.goto(32, 150)
turtle.pendown()
turtle.fillcolor('#000000')
turtle.begin_fill()
turtle.circle(8)
turtle.end_fill()
# 绘制嘴巴
def mouth():
turtle.pensize(6)
turtle.penup()
turtle.goto(-70, 30)
turtle.pendown()
turtle.goto(70, 30)
# 绘制鼻子
def nose():
turtle.penup()
turtle.goto(0, 90)
turtle.pendown()
turtle.fillcolor('#ff0000')
turtle.begin_fill()
turtle.circle(18)
turtle.end_fill()
# 绘制胡须
def whiskers():
turtle.pensize(2)
turtle.penup()
turtle.goto(-30, 45)
turtle.pendown()
turtle.goto(-100, 55)
turtle.penup()
turtle.goto(-30, 25)
turtle.pendown()
turtle.goto(-100, 25)
turtle.penup()
turtle.goto(30, 45)
turtle.pendown()
turtle.goto(100, 55)
turtle.penup()
turtle.goto(30, 25)
turtle.pendown()
turtle.goto(100, 25)
# 绘制脚
def feet():
turtle.pensize(40)
turtle.pencolor('#000000')
turtle.fillcolor('#f8e10d')
turtle.penup()
turtle.goto(-60, -80)
turtle.pendown()
turtle.begin_fill()
turtle.goto(-30, -180)
turtle.goto(30, -180)
turtle.goto(60, -80)
turtle.end_fill()
# 绘制名字
def name():
turtle.penup()
turtle.goto(-150, -250)
turtle.pencolor('#000000')
style = ('Courier', 50, 'bold')
turtle.write('Python 史迪仔', font=style, align='center')
# 主函数
def main():
turtle.setup(800, 600)
body()
eyes()
mouth()
nose()
whiskers()
feet()
name()
turtle.done()
if __name__ == '__main__':
main()
```
在运行以上代码之前,需要先安装 `turtle` 库,可通过以下命令进行安装:
```
pip install turtle
```
阅读全文