使用python画一只佩奇
打开界面:
打开python shell界面。
建立脚本:
单击"file"——"new file"来建立脚本。
编写代码:
具体的代码如下。
- import turtle as t
- '''''
- t.pu() 提起画笔
- t.pd() 移动时绘制图形,缺省时也为绘制
- t.seth 设置当前朝向为angle角度
- t.begin_fill() 准备开始填充图形
- t.color 同时设置pencolor=color1, fillcolor=color2
- t.goto 设置笔的坐标
- t.circle(70,20) 半径 度数
- 15,124,215 乔治裤子颜色外面
- 66,163,242 乔治裤子颜色里面
- 134 196 247 天空的颜色
- 123,245,95 草地的颜色
- 253,6,6 鞋子外面
- 253,70,70 鞋子里面
- 130,119,100 泥坑
- '''
- r_a=0.8
- wight = 1100
- height = 700
- #t.pensize(4)
- t.hideturtle()
- t.colormode(255)
- t.color((255,155,192),"pink")
- t.setup(wight,height)
- t.speed(10)
- def move_pen(x,y):
- t.pu()
- t.goto(x-wight/2+50,y-height/2+50)
- t.pd()
- def pen_set(size,r1,g1,b1,r2=0,g2=0,b2=0):
- t.pensize(size)
- t.color((r1,g1,b1),(r2,g2,b2))
- def draw_grid():
- pen_set(1,0,0,0,0,0,0)
- for i in range(20):
- move_pen(0+i*50,0)
- t.seth(90)
- t.fd(600)
- for i in range(12):
- move_pen(0,0+i*50)
- t.seth(0)
- t.fd(1000)
- def draw_bg():
- #画草地
- move_pen(0,350)
- pen_set(4,123,245,95, 123,245,95)
- t.begin_fill()
- t.seth(-90)
- t.fd(350)
- t.seth(0)
- t.fd(1000)
- t.seth(90)
- t.fd(350)
- t.end_fill()
- #画天空
- move_pen(0,350)
- pen_set(4,134,196,247, 134,196,247)
- t.begin_fill()
- t.seth(90)
- t.fd(250)
- t.seth(0)
- t.fd(1000)
- t.seth(-90)
- t.fd(250)
- a=-180 + r_a
- for i in range(50):
- a = a - r_a/50
- t.seth(a)
- t.fd(500/50)
- a =180
- for i in range(50):
- a = a - r_a/50
- t.seth(a)
- t.fd(500/50)
- t.end_fill()
- def draw_mud_pit():
- #画泥坑
- pen_set(5,130,119,100, 130,119,100)
- move_pen(350,150)
- t.begin_fill()
- t.seth(-180)
- t.circle(50,125)
- t.seth(-20)
- t.circle(350,60)
- t.seth(20)
- t.circle(50,30)
- t.seth(10)
- t.circle(50,30)
- t.seth(0)
- t.circle(50,30)
- t.seth(40)
- t.circle(50,90)
- t.seth(170)
- t.circle(500,45)
- t.end_fill()
- def draw_shoes():
- pen_set(3,253,6,6, 253,70,70)
- move_pen(400,100)
- t.begin_fill()
- t.seth(0)
- t.fd(50)
- t.seth(87)
- t.fd(50)
- t.seth(180)
- t.fd(25)
- t.seth(-93)
- t.fd(20)
- t.seth(-180)
- t.fd(25)
- t.seth(-120)
- t.circle(45,38)
- t.end_fill()
- move_pen(470,100)
- t.begin_fill()
- t.seth(0)
- t.fd(50)
- t.seth(87)
- t.fd(50)
- t.seth(180)
- t.fd(25)
- t.seth(-93)
- t.fd(20)
- t.seth(-180)
- t.fd(25)
- t.seth(-120)
- t.circle(45,38)
- t.end_fill()
- def draw_leg():
- pen_set(6,255,155,192, 255,155,192)
- move_pen(440,140)
- t.seth(90)
- t.fd(20)
- move_pen(510,140)
- t.seth(90)
- t.fd(20)
- def draw_trousers():
- move_pen(400,300)
- pen_set(6,15,124,215, 66,163,242)
- t.begin_fill()
- d_a = 100
- a=-130
- for i in range(60):
- a = a + 2
- t.seth(a)
- t.fd(3)
- for i in range(14):
- a = a + 0.02
- t.seth(a)
- t.fd(2)
- a = 0-a
- for i in range(14):
- a = a + 0.02
- t.seth(a)
- t.fd(2)
- for i in range(60):
- a = a + 2.2
- t.seth(a)
- t.fd(3)
- t.end_fill()
- def draw_tile():
- move_pen(550,177)
- pen_set(6,255,155,192, 255,155,192)
- a=-60
- for i in range(25):
- a = a + 4
- t.seth(a)
- t.fd(1)
- t.circle(5)
- a = -a
- for i in range(30):
- a = a + 4
- t.seth(a)
- t.fd(1)
- def draw_hands():
- move_pen(550,250)
- pen_set(6,255,155,192, 255,155,192)
- t.seth(20)
- t.fd(70)
- move_pen(600,270)
- t.seth(60)
- t.fd(20)
- move_pen(600,270)
- t.seth(-20)
- t.fd(20)
- move_pen(380,250)
- t.seth(160)
- t.fd(50)
- move_pen(350,260)
- t.seth(100)
- t.fd(20)
- move_pen(350,260)
- t.seth(-140)
- t.fd(20)
- def draw_face():
- move_pen(400,360)
- pen_set(4,255,155,192, 255,196,218)
- t.begin_fill()
- a=-120
- for i in range(20):
- a = a + 2.5
- t.seth(a)
- t.fd(2.2)
- for i in range(130):
- a = a + 1.3
- t.seth(a)
- t.fd(1.8)
- for i in range(35):
- a = a + 1.4
- t.seth(a)
- t.fd(2)
- for i in range(50):
- a = a + 0.35
- t.seth(a)
- t.fd(2)
- for i in range(50):
- a = a + 0.2
- t.seth(a)
- t.fd(2)
- n=0.4
- for i in range(180):
- if 0<=i<30 or 60<=i<90 or 120<=i<150 :
- n=n+0.08
- 度
- t.fd(n) #向前走a的步长
- else:
- n=n-0.08
- t.lt(3)
- t.fd(n)
- a=-50
- for i in range(20):
- a = a + 2.8
- t.seth(a)
- t.fd(5)
- t.end_fill()
- def draw_other():
- move_pen(310,440)
- pen_set(6,255,145,192, 255,145,192)
- t.begin_fill()
- t.circle(3)
- t.end_fill()
- move_pen(330,430)
- t.begin_fill()
- t.circle(3)
- t.end_fill()
- pen_set(6,255,145,192, 255,255,255)
- move_pen(410,425)
- t.begin_fill()
- t.circle(10)
- t.end_fill()
- move_pen(460,395)
- t.begin_fill()
- t.circle(10)
- t.end_fill()
- pen_set(6,0,0,0,0,0,0)
- move_pen(405,429)
- t.begin_fill()
- t.circle(3)
- t.end_fill()
- move_pen(455,399)
- t.begin_fill()
- t.circle(3)
- t.end_fill()
- move_pen(510,310)
- pen_set(6,255,155,192, 255,155,192)
- t.begin_fill()
- t.circle(25)
- t.end_fill()
- move_pen(410,340)
- pen_set(6,255,145,192, 255,145,192)
- a=-80
- for i in range(20):
- a = a + 6
- t.seth(a)
- t.fd(3)
- move_pen(430,445)
- pen_set(4,255,155,192, 255,196,218)
- t.begin_fill()
- a=120
- for i in range(40):
- a = a - 2
- t.seth(a)
- t.fd(1.2)
- a=-a
- for i in range(45):
- a = a - 2
- t.seth(a)
- t.fd(1.2)
- t.end_fill()
- move_pen(480,430)
- t.begin_fill()
- a=70
- for i in range(40):
- a = a -1.5
- t.seth(a)
- t.fd(1.5)
- a=-80
- for i in range(45):
- a = a -1.5
- t.seth(a)
- t.fd(1.5)
- t.end_fill()
- draw_bg()
- draw_mud_pit()
- #draw_grid()
- draw_leg()
- draw_shoes()
- draw_trousers()
- draw_tile()
- draw_hands()
- draw_face()
- draw_other()
- t.mainloop()
4.保存脚本:
5执行脚本及效果:
6.结果:
使用python画一只佩奇的更多相关文章
- python画一只佩奇
用python画一只佩奇 from turtle import* def nose(x,y):#鼻子 penup()#提起笔 goto(x,y)#定位 pendown()#落笔,开始画 sethead ...
- python 画个小猪佩奇
不知道大家小时候有没有学习过logo语言,就是操纵一只小王八,来画各种图案.博主小学微机课就学习了这个,最近发现python的turtle包就是logo语言,所以画个小猪佩奇和大家分享. 代码来自知乎 ...
- python 画小猪佩奇
转自:python画个小猪佩奇 # -*- coding: utf-8 -*- """ Created on Mon May 20 11:36:03 2019 @auth ...
- 沉淀再出发:用python画各种图表
沉淀再出发:用python画各种图表 一.前言 最近需要用python来做一些统计和画图,因此做一些笔记. 二.python画各种图表 2.1.使用turtle来画图 import turtle as ...
- 为什么学Python语言,只需四步全面了解Python语言
为什么学Python语言,只需四步全面了解Python语言每个时代都会悄悄犒赏会选择的人,Python现在风口的语言Python--第三大主流编程语言Python , 是一种面向对象的解释型计算机程序 ...
- python画樱花
用python画简单的樱花 代码如下: import turtle as T import random import time # 画樱花的躯干(60,t) def Tree(branch, t): ...
- 利用Python制作一个只属于和她的聊天器,再也不用担心隐私泄露啦!
------------恢复内容开始------------ 是否担心微信的数据流会被监视?是否担心你和ta聊天的小秘密会被保存到某个数据库里?没关系,现在我们可以用Python做一个只属于你和ta的 ...
- div+css画一个小猪佩奇
用DIV+CSS画一个小猪佩奇,挺可爱的,嘻嘻. HTML部分(全是DIV) <!-- 小猪佩奇整体容器 --> <div class="pig_container&quo ...
- 用python画 pareto front
用python画 pareto front 觉得有用的话,欢迎一起讨论相互学习~Follow Me 2D pf import os import matplotlib.pyplot as plt im ...
随机推荐
- Qt文件系统之QFile
QFile文件操作 文件打开方式: QIODevice::NotOpen 0x0000 设备不打开.QIODevice::ReadOnly 0x0001 设备 以只读的方式打开.Q ...
- GVIM 设置 vimrc
set expandtab set nobackup set nosmartindent set noautoindent set ruler au BufRead,BufNewFile *.sv s ...
- 自制按钮图标的两种方法: image sprite和svg字体文件
用image sprite和svg字体文件这两种方法,都能够极大地减少小图形文件的数量, 从而减少服务器请求和带宽需求.提高网页的响应速度. 一.建立SVG字体文件 iconmoon 是一个在线工具, ...
- 2018-2019-2 20175328李欣颖实验二《Java面向对象程序设计》实验报告
2018-2019-2 20175328李欣颖实验二<Java面向对象程序设计>实验报告 面向对象程序设计-1 用程序解决问题时,要会写三种码: 1.伪代码 此处百分制转五分制: 如果成绩 ...
- Appium java环境搭建(Windows版)
注意:如果初次学习appium的话,则需要你做好准备因为安装过程并不简单 1.安装appium Appium 官方网站:http://appium.io/ 安装Appium之前需要先安装node.js ...
- vs 为什么使用#include "stdafx.h"
原因:1.减少编译次数 2.减少不必要的处理 流程图: 这个跟宏定义#ifndef xx #define xx coding here #endif //xx 区别在于: 宏定义是防止头文件重复包含 ...
- scrapy爬去京东书籍信息
# -*- coding: utf-8 -*- import scrapy import urllib import json from copy import deepcopy class JdSp ...
- Android短信过滤项目中的观察者模式
观察者模式: 观察者模式定义了对象之间的一对多依赖,当一个对象改变状态时,它的所有依赖者都会收到通知并自动更新. 观察者模式提供了一种对象设计, 让主题和观察者之间松耦合.主题只知道观察者实现了某个接 ...
- twisted的task之cooperator和scrapy的parallel()函数
def handle_spider_output(self, result, request, response, spider): if not result: return defer_succe ...
- sqlserver 存储过程 自定义函数 游标???
create proc cur_fun( @cur cursor --输入参数 ) as begin declare @mytpye tb1_type ) fetch next from @cur i ...