用python画一只可爱的皮卡丘实例

效果图

#!/usr/bin/env python
# -*- coding:utf-8 -*-
from turtle import *
'''
绘制皮卡丘头部
'''
def face(x,y):
 """画脸"""
 begin_fill()
 penup()
 # 将海龟移动到指定的坐标
 goto(x, y)
 pendown()
 # 设置海龟的方向
 setheading(40)

 circle(-150, 69)
 fillcolor("#FBD624")
 # 将海龟移动到指定的坐标

 penup()
 goto(53.14, 113.29)
 pendown()

 setheading(300)
 circle(-150, 30)
 setheading(295)
 circle(-140, 20)
 print(position())
 forward(5)
 setheading(260)
 circle(-80, 70)
 print(position())
 penup()
 goto(-74.43,-79.09)
 pendown()

 penup()
 # 将海龟移动到指定的坐标
 goto(-144,103)
 pendown()
 setheading(242)
 circle(110, 35)
 right(10)
 forward(10)
 setheading(250)
 circle(80, 115)
 print(position())

 penup()
 goto(-74.43,-79.09)
 pendown()
 setheading(10)
 penup()
 goto(-144, 103)

 pendown()
 penup()
 goto(x, y)
 pendown()

 end_fill()

 # 下巴
 penup()
 goto(-50, -82.09)
 pendown()
 pencolor("#DDA120")
 fillcolor("#DDA120")
 begin_fill()
 setheading(-12)
 circle(120, 25)
 setheading(-145)
 forward(30)
 setheading(180)
 circle(-20, 20)
 setheading(143)
 forward(30)
 end_fill()
 # penup()
 # # 将海龟移动到指定的坐标
 # goto(0, 0)
 # pendown()

def eye():
 """画眼睛"""
 # 左眼
 color("black","black")
 penup()
 goto(-110, 27)
 pendown()
 begin_fill()
 setheading(0)
 circle(24)
 end_fill()
 # 左眼仁
 color("white", "white")
 penup()
 goto(-105, 51)
 pendown()
 begin_fill()
 setheading(0)
 circle(10)
 end_fill()
 # 右眼
 color("black", "black")
 penup()
 goto(25, 40)
 pendown()
 begin_fill()
 setheading(0)
 circle(24)
 end_fill()
 # 右眼仁
 color("white", "white")
 penup()
 goto(17, 62)
 pendown()
 begin_fill()
 setheading(0)
 circle(10)
 end_fill()
def cheek():
 """画脸颊"""
 # 右边
 color("#9E4406", "#FE2C21")
 penup()
 goto(-130, -50)
 pendown()
 begin_fill()
 setheading(0)
 circle(27)
 end_fill()

 # 左边
 color("#9E4406", "#FE2C21")
 penup()
 goto(53, -20)
 pendown()
 begin_fill()
 setheading(0)
 circle(27)
 end_fill()

def nose():
 """画鼻子"""
 color("black", "black")
 penup()
 goto(-40, 38)
 pendown()
 begin_fill()
 circle(7,steps = 3)
 end_fill()
def mouth():
 """画嘴"""
 color("black", "#F35590")
 # 嘴唇
 penup()
 goto(-10, 22)
 pendown()
 begin_fill()
 setheading(260)
 forward(60)
 circle(-11, 150)
 forward(55)
 print(position())
 penup()
 goto(-38.46, 21.97)
 pendown()
 end_fill()

 # 舌头
 color("#6A070D", "#6A070D")
 begin_fill()
 penup()
 goto(-10.00, 22.00)
 pendown()
 penup()
 goto(-14.29, -1.7)
 pendown()
 penup()
 goto(-52, -5)
 pendown()
 penup()
 goto(-60.40, 12.74)
 pendown()
 penup()
 goto(-38.46, 21.97)
 pendown()
 penup()
 goto(-10.00, 22.00)
 pendown()

 end_fill()

 color("black","#FFD624")

 penup()
 goto(-78, 15)
 pendown()
 begin_fill()
 setheading(-25)
 for i in range(2):
  setheading(-25)
  circle(35, 70)

 end_fill()
 color("#AB1945", "#AB1945")
 penup()
 goto(-52, -5)
 pendown()
 begin_fill()
 setheading(40)
 circle(-33, 70)
 goto(-16,-1.7)
 penup()
 goto(-18,-17)
 pendown()
 setheading(155)
 circle(25, 70)
 end_fill()

def ear():
 """画耳朵"""
 # 左耳
 color("black","#FFD624")
 penup()
 goto(-145, 93)
 pendown()
 begin_fill()
 setheading(165)
 circle(-248,50)
 right(120)
 circle(-248,50)
 end_fill()
 color("black", "black")
 penup()
 goto(-240, 143)
 pendown()
 begin_fill()
 setheading(107)
 circle(-170, 25)
 left(80)
 circle(229, 15)
 left(120)
 circle(300, 15)
 end_fill()

 # 右耳
 color("black", "#FFD624")
 penup()
 goto(30, 136)
 pendown()
 begin_fill()
 setheading(64)
 circle(-248, 50)

 right(120)
 circle(-248, 50)
 end_fill()
 color("black", "black")
 penup()
 goto(160, 200)
 pendown()
 begin_fill()
 setheading(52)
 circle(170, 25)
 left(116)
 circle(229, 15)
 left(71)
 circle(-300, 15)
 end_fill()
 def setting():
 """设置参数"""
 pensize(2)
 # 隐藏海龟
 hideturtle()
 speed(10)
def main():
 """主函数"""
 setting()
 face(-132,115)
 eye()
 cheek()
 nose()
 mouth()
 ear()
 done()

if __name__ == '__main__':
 main()

以上这篇用python画一只可爱的皮卡丘实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • python3实现用turtle模块画一棵随机樱花树

    废话不多说了,直接上代码吧! #!/usr/bin/env python # coding=utf-8 # 画一棵樱花 import turtle import random from turtle import * from time import sleep # 画樱花的躯干(60,t) def tree(branchLen,t): sleep(0.0005) if branchLen >3: if 8<= branchLen <=12: if random.randint(0,2)

  • 用python中的matplotlib绘制方程图像代码

    import numpy as np import matplotlib.pyplot as plt def main(): # 设置x和y的坐标范围 x=np.arange(-2,2,0.01) y=np.arange(-2,2,0.01) # 转化为网格 x,y=np.meshgrid(x,y) z=np.power(x,2)+np.power(y,2)-1 plt.contour(x,y,z,0) plt.show() main() 绘制的时候要保证x,y,z的维度相同 结果如下: 以上这

  • python画蝴蝶曲线图的实例

    蝴蝶曲线是由Temple H·Fay发现的可用极坐标函数表示的蝴蝶曲线. 由于此曲线优美, 因此就想把它作为博客favicon.ico,这里我使用pytho matplotlib.pyplot包来绘制需要的蝴蝶曲线图. 先看下漂亮的蝴蝶曲线吧. 1.首先我们需要确定蝴蝶曲线的函数表达 2.选择python里面的matplotlib.pyplot作为画图工具 1.首先导入python包 import numpy as np import matplotlib.pyplot as plt 2.设置个

  • 使用python的turtle绘画滑稽脸实例

    这是借鉴了一位兄弟的代码,然后进行修改的,原来代码存在问题,用了2小时,自己修改,终于画出了滑稽脸,也算是对于今天学的turtle绘画库的一个小小的记录吧!(有错误希望各位看官指正啊) 编译器是:Atom python 是3.7版本 运行位 Windows power shell import turtle turtle.setup(600,600,200,200) #fcae turtle.penup() turtle.goto(-210,0) turtle.seth(-90) turtle.

  • Python 用turtle实现用正方形画圆的例子

    最近发现一个很有意思的画图的python库,叫做turtle,这里先说下用turtle这个库来实现用正方形画圆的思路. 每次都用乌龟(turtle)来画出一个正方形,然后通过旋转3°后,继续画一样的正方形,在通过120次循环后就实现了完整的圆,这里当然也可以用其他的角度和次数,只要能完成360度就可以了. 先看完成的图形和代码. 代码如下: import turtle window = turtle.Screen() #设置好画图的基本参数 window.bgcolor("blue")

  • 使用Python的Turtle绘制哆啦A梦实例

    这是我几年前为了练习python的turtle库而画的,今天翻出了代码,分享给大家. 这是我初学python时画的,当时还没有面向对象的概念,也没有采取类方法之类,纯原始手工,供大家参考. 若有兴趣可以自行优化简洁代码,有时间我也会重新写一遍. 画出来的效果如下图: 代码如下: # * -- utf-8 -- * # Author: Tang import turtle as t t.speed(10) t.pensize(8) t.hideturtle() t.screensize(500,

  • python/Matplotlib绘制复变函数图像教程

    今天发现sympy依赖的库mpmath里也有很多数学函数,其中也有在复平面绘制二维图的函数cplot,具体例子如下 from mpmath import * def f1(z): return z def f2(z): return z**3 def f3(z): return (z**4-1)**(1/4) def f4(z): return 1/z def f5(z): return atan(z) def f6(z): return sqrt(z) cplot(f1) cplot(f2)

  • 用python画一只可爱的皮卡丘实例

    效果图 #!/usr/bin/env python # -*- coding:utf-8 -*- from turtle import * ''' 绘制皮卡丘头部 ''' def face(x,y): """画脸""" begin_fill() penup() # 将海龟移动到指定的坐标 goto(x, y) pendown() # 设置海龟的方向 setheading(40) circle(-150, 69) fillcolor("#

  • 用python画一只帅气的皮卡丘

    没错,全网最帅的比卡丘在我这~~~ 为了访问 Python 库,您需要将它导入到您的 Python 环境中,使用以下命令将其导入 turtle到您的 Python 脚本中. import turtle 首先,让我们创建一个 Screen 实例. wn = turtle.Screen() 现在,创建一个 Turtle 实例. self.t = turtle.Turtle() 让我们将速度设置为 3 使用 speed 方法,这意味着皮卡丘不会只是出现在屏幕上,绘图也会有一些动画.如果您想更改背景颜色

  • 用Python制作一个可以聊天的皮卡丘版桌面宠物

    目录 导语 开发工具 原理简介 步骤实现 导语 前段时间有小伙伴留言说想让我带大家写写桌面小挂件,今天就满足一下留过类似言的小伙伴的请求呗~不过感觉写桌面的挂历啥的没意思,就简单带大家做一只桌面宠物吧~ 废话不多说,让我们愉快地开始吧~ 开发工具 Python版本:3.6.4 相关模块: PyQt5模块: 以及一些Python自带的模块 原理简介 既然要写个桌面宠物,首先当然是要找宠物的图片素材啦.这里我们使用的是来自shimiji这款手机APP上的宠物图片素材,例如皮卡丘: 我下了大约60多种

  • Python+Turtle实现绘制可爱的小仓鼠

    目录 一.效果展示 二.代码详解 1.导入库 2.播放音乐 3.定义画小仓鼠头的函数 4.定义画左眼和右眼的函数 5.定义画嘴的函数 一.效果展示 在介绍代码之前,先来看下本文的实现效果. 可以参考下面步骤把Python文件转化成exe,发给未安装Python的他/她. Pinstaller(Python打包为exe文件) 之前自己把 Python 文件打包成 exe 的时候,折腾了很久,本文将详细地讲述如何快速生成在不安装 Python 的电脑上也能执行的文件 1. 在 prompt 中运行

  • python 画二维、三维点之间的线段实现方法

    如下所示: from mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot as plt # 打开画图窗口1,在三维空间中绘图 fig = plt.figure(1) ax = fig.gca(projection='3d') # 给出点(0,0,0)和(100,200,300) x = [0, 100] y = [0, 200] z = [0, 300] # 将数组中的前两个点进行连线 figure = ax.plot(x, y

  • 使用python画个小猪佩奇的示例代码

    基本原理 选好画板大小,设置好画笔颜色.粗细,定位好位置,依次画鼻子.头.耳朵.眼睛.腮.嘴.身体.手脚.尾巴,完事儿. 都知道,Turtle 是 Python 内置的一个比较有趣味的模块,俗称"海龟绘图",它是基于 Tkinter 模块打造,提供一些简单的绘图工具. 在海龟作图中,我们可以编写指令让一个虚拟的(想象中的)海龟在屏幕上来回移动.这个海龟带着一只钢笔,我们可以让海龟无论移动到哪都使用这只钢笔来绘制线条.通过编写代码,以各种很酷的模式移动海龟,我们可以绘制出令人惊奇的图片.

  • Python+Turtle绘制一个可爱的生日蛋糕

    每当有朋友过生日时,生日蛋糕自然是必不可少的,今天我们来看一下如何用 Python 画一个生日蛋糕. 本文我们用到的 Python 库包括:turtle.math 和 random. 实现的主要代码如下: import math as m import random as r import turtle as t t.speed(0) t.delay(0) # 设置背景颜色及窗口 t.bgcolor("#FFFFFF") t.setup(800, 600) t.penup() t.go

  • 教你使用python画一朵花送女朋友

    本文实例为大家分享了用python画一朵花的具体代码,供大家参考,具体内容如下 第一种,画法 from turtle import * import time setup(600,800,0,0) speed(0) penup() seth(90) fd(340) seth(0) pendown() speed(5) begin_fill() fillcolor('red') circle(50,30) for i in range(10): fd(1) left(10) circle(40,4

随机推荐