教你用Python画哆啦A梦、海绵宝宝、皮卡丘、史迪仔!(附完整源码)

一、哆啦A梦

由于代码过长,这里仅显示部分代码:

from turtle import \*
import turtle as t
from random import \*

#五轨迹跳跃
def my\_goto(x,y):
    penup()
    goto(x,y)
    pendown()

def eyes():
    fillcolor('#ffffff')
    begin\_fill()

    tracer(False)
    a \= 2.5
    for i in range(120):
        if 0<= i<30 or 60 <= i <90:
            a \-= 0.05
            lt(3)
            fd(a)
        else:
            a += 0.05
            lt(3)
            fd(a)
    tracer(True)
    end\_fill()

#胡须
def beard():
    my\_goto(\-32,135)
    seth(165)
    fd(60)

    my\_goto(\-32,125)
    seth(180)
    fd(60)

    my\_goto(\-32,115)
    seth(193)
    fd(60)

    my\_goto(37,135)
    seth(15)
    fd(60)

    my\_goto(37,125)
    seth(0)
    fd(60)

    my\_goto(37,115)
    seth(\-13)
    fd(60)

#嘴巴
def mouth():
    my\_goto(5,148)
    seth(270)
    fd(100)
    seth(0)
    circle(120,50)
    seth(230)
    circle(\-120,100)

二、海绵宝宝

部分代码如下:

from turtle import \*

def go\_to(x, y):
    penup()
    goto(x, y)
    pendown()

def help\_do():
    go\_to(\-400, 0)
    forward(800)
    go\_to(\-400, 100)
    forward(800)
    go\_to(\-400,200)
    forward(800)
    go\_to(\-400, -100)
    forward(800)
    go\_to(\-400, -200)
    forward(800)
    left(90)
    go\_to(0,\-300)
    forward(600)
    go\_to(100, -300)
    forward(600)
    go\_to(\-100, -300)
    forward(600)
    go\_to(\-200, -300)
    forward(600)
    go\_to(200, -300)
    forward(600)

def head():
    go\_to(\-200, 180)
    fillcolor('yellow')
    begin\_fill()
    seth(\-30)
    for \_ in range(6):
        circle(36, 60)
        circle(\-36, 60)
    seth(\-125)
    for \_ in range(5):
        circle(40,60)
        circle(\-40,60)
    seth(\-210)
    for \_ in range(4):
        circle(45,60)
        circle(\-45,60)
    seth(65)
    for \_ in range(5):
        circle(40,60)
        circle(\-40,60)
    end\_fill()

三、皮卡丘

部分代码如下:

import turtle

def getPosition(x, y):
    turtle.setx(x)
    turtle.sety(y)
    print(x, y)

class Pikachu:

    def \_\_init\_\_(self):
        self.t \= turtle.Turtle()
        t \= self.t
        t.pensize(3)
        t.speed(9)
        t.ondrag(getPosition)

    def noTrace\_goto(self, x, y):
        self.t.penup()
        self.t.goto(x, y)
        self.t.pendown()

    def leftEye(self, x, y):
        self.noTrace\_goto(x, y)
        t \= self.t
        t.seth(0)
        t.fillcolor('#333333')
        t.begin\_fill()
        t.circle(22)
        t.end\_fill()

        self.noTrace\_goto(x, y \+ 10)
        t.fillcolor('#000000')
        t.begin\_fill()
        t.circle(10)
        t.end\_fill()

        self.noTrace\_goto(x \+ 6, y + 22)
        t.fillcolor('#ffffff')
        t.begin\_fill()
        t.circle(10)
        t.end\_fill()

    def rightEye(self, x, y):
        self.noTrace\_goto(x, y)
        t \= self.t
        t.seth(0)
        t.fillcolor('#333333')
        t.begin\_fill()
        t.circle(22)
        t.end\_fill()

        self.noTrace\_goto(x, y \+ 10)
        t.fillcolor('#000000')
        t.begin\_fill()
        t.circle(10)
        t.end\_fill()

        self.noTrace\_goto(x \- 6, y + 22)
        t.fillcolor('#ffffff')
        t.begin\_fill()
        t.circle(10)
        t.end\_fill()

四、史迪仔

部分代码如下:

from turtle import \*

setup(650,650)
penup()
pensize(5)
speed(1000)
pencolor("#065693")
seth(180)
fd(140)
seth(\-90)
fd(50)
pendown()      #起点
fillcolor("#0079C6")
begin\_fill()
seth(170)
circle(\-40,100)
seth(180)
fd(50)
seth(180)
circle(\-10,46)
seth(130)
circle(\-300,40)#耳朵外廓大圆
circle(-100,45)
right(10)
circle(\-50,30)
right(10)
circle(\-30,30)
left(1)
fd(2)
right(1)
fd(3)
right(4)
fd(3)
right(3)
fd(5)
right(4)
fd(6)
right(4)
fd(10)
right(4)
fd(10)
right(3)
fd(15)
right(2)
fd(20)
right(2)
fd(20)
right(4)
fd(20)
right(3)
fd(30)
right(1)
fd(40)
right(1)
fd(60)
seth(\-115)
fd(5)    #脸左侧开始逆时针
circle(200,30)
end\_fill()
begin\_fill()
left(8)
fd(20)
left(10)
fd(20)
left(14)
circle(100,30)
left(10)
circle(150,20)
right(2)
fd(55)
left(5)
fd(40)
left(3)
fd(25)
right(3)
circle(150,20)
left(7)
circle(100,30)

五、完整源码下载

六、学习资源推荐

除了上述分享,如果你也喜欢编程,想通过学习Python获取更高薪资,这里给大家分享一份Python学习资料。

这里给大家展示一下我进的最近接单的截图

私单

😝朋友们如果有需要的话,可以 V扫描下方二维码联系领取,也可以内推兼职群哦~

学好 Python 不论是就业还是做副业赚钱都不错,但要学会 Python 还是要有一个学习规划。最后大家分享一份全套的 Python 学习资料,给那些想学习 Python 的小伙伴们一点帮助!

1.Python学习路线

image-20230619144606466

python学习路线图1

2.Python基础学习

01.开发工具

02.学习笔记

在这里插入图片描述

03.学习视频

在这里插入图片描述

3.Python小白必备手册

图片

4.数据分析全套资源

在这里插入图片描述

5.Python面试集锦

01.面试资料

在这里插入图片描述

在这里插入图片描述

02.简历模板

在这里插入图片描述

因篇幅有限,仅展示部分资料,添加上方即可获取👆

------ 🙇‍♂️ 本文转自网络,如有侵权,请联系删除 🙇‍♂️ ------
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python是一种广泛应用于编程和数据分析的高级编程语言,它提供了许多强大的绘图功能,可以用来出各种各样的图形和图像,包括史迪仔。 要用Python史迪仔,首先需要准备一个绘图的库,比如matplotlib或者PIL(Python Imaging Library)。这些库提供了丰富的绘图函数和方法,可以帮助我们绘制出所需的图形。 为了史迪仔,我们可以先在绘图区域创建一个空白布,然后通过绘图函数一点一点地添加笔和颜色,逐渐绘制史迪仔的轮廓和特征。 史迪仔的轮廓和特征可以通过绘制直线、曲线、图形等方式来实现。例如,我们可以使用直线函数来史迪仔的身体、四肢和眼睛,使用曲线函数来史迪仔的胡须和嘴巴,使用图形函数来填充史迪仔的颜色。 在史迪仔时,我们还可以运用一些绘图技巧和方法,使得绘制的图像更加生动和逼真。例如,可以利用阴影和渐变效果来增加史迪仔的立体感,使用细节笔来表达史迪仔的毛发和纹理。 当好了史迪仔后,我们可以通过保存或者显示的方式来展示绘制的结果。可以将史迪仔保存为图片文件,或者直接在程序中显示出来。 总之,Python提供了丰富的绘图功能,可以用来出各种各样的图形和图像,包括史迪仔。通过利用绘图库和一些绘图技巧,我们可以实现绘制出具有立体感和逼真度的史迪仔图像。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值