1. 打开界面:

打开python shell界面。

  1. 建立脚本:

单击"file"——"new file"来建立脚本。

  1. 编写代码:

具体的代码如下。

  1. import turtle as t  
  2. ''''' 
  3. t.pu()  提起画笔 
  4. t.pd()  移动时绘制图形,缺省时也为绘制 
  5. t.seth  设置当前朝向为angle角度 
  6. t.begin_fill()  准备开始填充图形 
  7. t.color      同时设置pencolor=color1, fillcolor=color2 
  8. t.goto       设置笔的坐标 
  9. t.circle(70,20) 半径 度数 
  10. 15,124,215  乔治裤子颜色外面 
  11. 66,163,242  乔治裤子颜色里面 
  12.    
  13. 134  196  247  天空的颜色 
  14. 123,245,95 草地的颜色 
  15. 253,6,6  鞋子外面 
  16. 253,70,70  鞋子里面 
  17. 130,119,100 泥坑 
  18.    
  19.    
  20. '''  
  21. r_a=0.8  
  22. wight = 1100  
  23. height = 700  
  24. #t.pensize(4)  
  25. t.hideturtle()  
  26. t.colormode(255)  
  27. t.color((255,155,192),"pink")  
  28. t.setup(wight,height)  
  29. t.speed(10)  
  30. def move_pen(x,y):  
  31.     t.pu()  
  32.     t.goto(x-wight/2+50,y-height/2+50)  
  33.     t.pd()  
  34. def pen_set(size,r1,g1,b1,r2=0,g2=0,b2=0):  
  35.     t.pensize(size)  
  36.     t.color((r1,g1,b1),(r2,g2,b2))  
  37. def draw_grid():  
  38.     pen_set(1,0,0,0,0,0,0)  
  39.     for i in range(20):  
  40.         move_pen(0+i*50,0)  
  41.         t.seth(90)  
  42.         t.fd(600)  
  43.     for i in range(12):  
  44.         move_pen(0,0+i*50)  
  45.         t.seth(0)  
  46.         t.fd(1000)  
  47.     
  48. def draw_bg():  
  49.     #画草地  
  50.         
  51.     move_pen(0,350)  
  52.     pen_set(4,123,245,95, 123,245,95)  
  53.     t.begin_fill()  
  54.     t.seth(-90)  
  55.     t.fd(350)  
  56.     t.seth(0)  
  57.     t.fd(1000)  
  58.     t.seth(90)  
  59.     t.fd(350)  
  60.     t.end_fill()  
  61.     #画天空  
  62.     move_pen(0,350)  
  63.     pen_set(4,134,196,247, 134,196,247)  
  64.     t.begin_fill()  
  65.     t.seth(90)  
  66.     t.fd(250)  
  67.     t.seth(0)  
  68.     t.fd(1000)  
  69.     t.seth(-90)  
  70.     t.fd(250)  
  71.     a=-180 + r_a  
  72.     for i in range(50):  
  73.         a = a - r_a/50  
  74.         t.seth(a)  
  75.         t.fd(500/50)  
  76.     a =180  
  77.     for i in range(50):  
  78.         a = a - r_a/50  
  79.         t.seth(a)  
  80.         t.fd(500/50)  
  81.     t.end_fill()  
  82.         
  83. def draw_mud_pit():  
  84.     #画泥坑  
  85.     pen_set(5,130,119,100, 130,119,100)  
  86.     move_pen(350,150)  
  87.     t.begin_fill()  
  88.     t.seth(-180)  
  89.     t.circle(50,125)  
  90.     t.seth(-20)  
  91.     t.circle(350,60)  
  92.     t.seth(20)  
  93.     t.circle(50,30)  
  94.     t.seth(10)  
  95.     t.circle(50,30)  
  96.     t.seth(0)  
  97.     t.circle(50,30)  
  98.     t.seth(40)  
  99.     t.circle(50,90)  
  100.     t.seth(170)  
  101.     t.circle(500,45)  
  102.     t.end_fill()  
  103.         
  104. def draw_shoes():  
  105.     pen_set(3,253,6,6, 253,70,70)  
  106.     move_pen(400,100)  
  107.     t.begin_fill()  
  108.     t.seth(0)  
  109.     t.fd(50)  
  110.     t.seth(87)  
  111.     t.fd(50)  
  112.     t.seth(180)  
  113.     t.fd(25)  
  114.     t.seth(-93)  
  115.     t.fd(20)  
  116.     t.seth(-180)  
  117.     t.fd(25)  
  118.     t.seth(-120)  
  119.     t.circle(45,38)  
  120.     t.end_fill()  
  121.     move_pen(470,100)  
  122.     t.begin_fill()  
  123.     t.seth(0)  
  124.     t.fd(50)  
  125.     t.seth(87)  
  126.     t.fd(50)  
  127.     t.seth(180)  
  128.     t.fd(25)  
  129.     t.seth(-93)  
  130.     t.fd(20)  
  131.     t.seth(-180)  
  132.     t.fd(25)  
  133.     t.seth(-120)  
  134.     t.circle(45,38)  
  135.     t.end_fill()  
  136. def draw_leg():   
  137.     pen_set(6,255,155,192, 255,155,192)  
  138.     move_pen(440,140)  
  139.     t.seth(90)  
  140.     t.fd(20)  
  141.     move_pen(510,140)  
  142.     t.seth(90)  
  143.     t.fd(20)  
  144. def draw_trousers():  
  145.     move_pen(400,300)  
  146.     pen_set(6,15,124,215, 66,163,242)  
  147.     t.begin_fill()  
  148.     d_a = 100  
  149.     a=-130   
  150.     for i in range(60):  
  151.         a = a + 2  
  152.         t.seth(a)  
  153.         t.fd(3)  
  154.     for i in range(14):  
  155.         a = a + 0.02  
  156.         t.seth(a)  
  157.         t.fd(2)  
  158.     a = 0-a  
  159.     for i in range(14):  
  160.         a = a + 0.02  
  161.         t.seth(a)  
  162.         t.fd(2)  
  163.     for i in range(60):  
  164.         a = a + 2.2  
  165.         t.seth(a)  
  166.         t.fd(3)  
  167.     t.end_fill()  
  168. def draw_tile():  
  169.     move_pen(550,177)  
  170.     pen_set(6,255,155,192, 255,155,192)  
  171.     a=-60   
  172.     for i in range(25):  
  173.         a = a + 4  
  174.         t.seth(a)  
  175.         t.fd(1)  
  176.     t.circle(5)  
  177.     a = -a  
  178.     for i in range(30):  
  179.         a = a + 4  
  180.         t.seth(a)  
  181.         t.fd(1)  
  182. def draw_hands():  
  183.     move_pen(550,250)  
  184.     pen_set(6,255,155,192, 255,155,192)  
  185.     t.seth(20)  
  186.     t.fd(70)  
  187.     move_pen(600,270)  
  188.     t.seth(60)  
  189.     t.fd(20)  
  190.     move_pen(600,270)  
  191.     t.seth(-20)  
  192.     t.fd(20)  
  193.         
  194.     move_pen(380,250)  
  195.     t.seth(160)  
  196.     t.fd(50)  
  197.     move_pen(350,260)  
  198.     t.seth(100)  
  199.     t.fd(20)  
  200.     move_pen(350,260)  
  201.     t.seth(-140)  
  202.     t.fd(20)  
  203.         
  204. def draw_face():  
  205.     move_pen(400,360)  
  206.     pen_set(4,255,155,192, 255,196,218)  
  207.     t.begin_fill()  
  208.     a=-120   
  209.     for i in range(20):  
  210.         a = a + 2.5  
  211.         t.seth(a)  
  212.         t.fd(2.2)  
  213.     for i in range(130):  
  214.         a = a + 1.3  
  215.         t.seth(a)  
  216.         t.fd(1.8)  
  217.     for i in range(35):  
  218.         a = a + 1.4  
  219.         t.seth(a)  
  220.         t.fd(2)  
  221.     for i in range(50):  
  222.         a = a + 0.35  
  223.         t.seth(a)  
  224.         t.fd(2)  
  225.     for i in range(50):  
  226.         a = a + 0.2  
  227.         t.seth(a)  
  228.         t.fd(2)  
  229.     n=0.4  
  230.     for i in range(180):  
  231.         if 0<=i<30 or 60<=i<90 or 120<=i<150 :  
  232.             n=n+0.08  
  233. 度  
  234.             t.fd(n) #向前走a的步长  
  235.         else:  
  236.             n=n-0.08  
  237.             t.lt(3)  
  238.             t.fd(n)  
  239.     a=-50  
  240.     for i in range(20):  
  241.         a = a + 2.8  
  242.         t.seth(a)  
  243.         t.fd(5)  
  244.     t.end_fill()  
  245. def draw_other():  
  246.     move_pen(310,440)  
  247.     pen_set(6,255,145,192, 255,145,192)  
  248.     t.begin_fill()  
  249.     t.circle(3)  
  250.     t.end_fill()  
  251.     move_pen(330,430)  
  252.     t.begin_fill()  
  253.     t.circle(3)  
  254.     t.end_fill()  
  255.         
  256.     pen_set(6,255,145,192, 255,255,255)  
  257.     move_pen(410,425)  
  258.     t.begin_fill()  
  259.     t.circle(10)  
  260.     t.end_fill()  
  261.     move_pen(460,395)  
  262.     t.begin_fill()  
  263.     t.circle(10)  
  264.     t.end_fill()  
  265.         
  266.     pen_set(6,0,0,0,0,0,0)  
  267.     move_pen(405,429)  
  268.     t.begin_fill()  
  269.     t.circle(3)  
  270.     t.end_fill()  
  271.     move_pen(455,399)  
  272.     t.begin_fill()  
  273.     t.circle(3)  
  274.     t.end_fill()  
  275.         
  276.     move_pen(510,310)  
  277.     pen_set(6,255,155,192, 255,155,192)  
  278.     t.begin_fill()  
  279.     t.circle(25)  
  280.     t.end_fill()  
  281.         
  282.     move_pen(410,340)  
  283.     pen_set(6,255,145,192, 255,145,192)  
  284.     a=-80   
  285.     for i in range(20):  
  286.         a = a + 6  
  287.         t.seth(a)  
  288.         t.fd(3)  
  289.     move_pen(430,445)  
  290.     pen_set(4,255,155,192, 255,196,218)  
  291.     t.begin_fill()  
  292.     a=120   
  293.     for i in range(40):  
  294.         a = a - 2  
  295.         t.seth(a)  
  296.         t.fd(1.2)  
  297.     a=-a  
  298.     for i in range(45):  
  299.         a = a - 2  
  300.         t.seth(a)  
  301.         t.fd(1.2)  
  302.     t.end_fill()  
  303.     move_pen(480,430)  
  304.     t.begin_fill()  
  305.     a=70   
  306.     for i in range(40):  
  307.         a = a -1.5  
  308.         t.seth(a)  
  309.         t.fd(1.5)  
  310.     a=-80  
  311.     for i in range(45):  
  312.         a = a -1.5  
  313.         t.seth(a)  
  314.         t.fd(1.5)  
  315.     t.end_fill()  
  316. draw_bg()  
  317. draw_mud_pit()  
  318. #draw_grid()  
  319. draw_leg()  
  320. draw_shoes()  
  321. draw_trousers()  
  322. draw_tile()  
  323. draw_hands()  
  324. draw_face()  
  325. draw_other()  
  326. t.mainloop()  

4.保存脚本:

5执行脚本及效果:

6.结果:

使用python画一只佩奇的更多相关文章

  1. python画一只佩奇

    用python画一只佩奇 from turtle import* def nose(x,y):#鼻子 penup()#提起笔 goto(x,y)#定位 pendown()#落笔,开始画 sethead ...

  2. python 画个小猪佩奇

    不知道大家小时候有没有学习过logo语言,就是操纵一只小王八,来画各种图案.博主小学微机课就学习了这个,最近发现python的turtle包就是logo语言,所以画个小猪佩奇和大家分享. 代码来自知乎 ...

  3. python 画小猪佩奇

    转自:python画个小猪佩奇 # -*- coding: utf-8 -*- """ Created on Mon May 20 11:36:03 2019 @auth ...

  4. 沉淀再出发:用python画各种图表

    沉淀再出发:用python画各种图表 一.前言 最近需要用python来做一些统计和画图,因此做一些笔记. 二.python画各种图表 2.1.使用turtle来画图 import turtle as ...

  5. 为什么学Python语言,只需四步全面了解Python语言

    为什么学Python语言,只需四步全面了解Python语言每个时代都会悄悄犒赏会选择的人,Python现在风口的语言Python--第三大主流编程语言Python , 是一种面向对象的解释型计算机程序 ...

  6. python画樱花

    用python画简单的樱花 代码如下: import turtle as T import random import time # 画樱花的躯干(60,t) def Tree(branch, t): ...

  7. 利用Python制作一个只属于和她的聊天器,再也不用担心隐私泄露啦!

    ------------恢复内容开始------------ 是否担心微信的数据流会被监视?是否担心你和ta聊天的小秘密会被保存到某个数据库里?没关系,现在我们可以用Python做一个只属于你和ta的 ...

  8. div+css画一个小猪佩奇

    用DIV+CSS画一个小猪佩奇,挺可爱的,嘻嘻. HTML部分(全是DIV) <!-- 小猪佩奇整体容器 --> <div class="pig_container&quo ...

  9. 用python画 pareto front

    用python画 pareto front 觉得有用的话,欢迎一起讨论相互学习~Follow Me 2D pf import os import matplotlib.pyplot as plt im ...

随机推荐

  1. flask同源策略解决办法及flask-cors只允许特定域名跨域

    falsk 同源策略解决办法: 使用 flask-cors 包 并且 在代码里 加响应的一行代码解决. from flask import Flask, session from flask_cors ...

  2. windows 杀死进程

    查看所有进程: tasklist 查看某一个进程: tasklist | findstr python 杀死进程:taskkill /F /PID python.exe 查看端口占用情况:netsta ...

  3. Python笔记:编码问题

    1. python2的编码: python2中使用的是ASCII码,所以不支持中文,如果要在python2中写入中文编码,需要在文件头编写: #-*- encoding:utf-8 -*- 2. 不同 ...

  4. sql 查询语句的练习2

    --14.列出所有雇员的雇员名称.部门名称和薪金. select e.ename,d.dname,e.sal from emp e,dept d where e.deptno = d.deptno;- ...

  5. Maven 下载、安装、配置学习

    一.Maven 下载与安装 电脑已安装:JDK.Eclipse 1.下载Maven:http://maven.apache.org/download.cgi 2.解压并安装:解压路径名不能有中文! 3 ...

  6. strace参数

    strace参数 -c 统计每一系统调用的所执行的时间,次数和出错的次数等. -d 输出strace关于标准错误的调试信息. -f 跟踪由fork调用所产生的子进程. -ff 如果提供-o filen ...

  7. 嵌入式linux——点亮led灯(二)

    刚才在jz2440板子上写了一个点亮中间led的程序,前前后后十几分钟才好.最终代码 本节内容: 1. 汇编点灯 2. C点灯 3. 参数选择点灯 4. 按键点灯 1. 汇编点灯 .text .glo ...

  8. dojo里添加目录树

    其实循环生成目录树这个方法不仅仅局限于在使用dojo的情况下,只要明白了其中的原理,在任何一种语言下都能动态循环生成. 1. 数据结构 在这里先说明一下数据结构,我这里循环生成目录树的数据结构是像这样 ...

  9. Intellij IDEA 中如何查看maven项目中所有jar包的依赖关系图(转载)

    Intellij IDEA 中如何查看maven项目中所有jar包的依赖关系图 2017年04月05日 10:53:13 李学凯 阅读数:104997更多 所属专栏: Intellij Idea   ...

  10. python+requests库,接口自动化

    1.requests库的使用 requests是python的一个HTTP客户端库,跟urllib,urllib2类似,那为什么要用requests而不用urllib2呢?官方文档中是这样说明的: “ ...