使用Python的turtle画小绵羊
今天学习使用turtle画图,本来想实现个3D效果,结果2D都画了半天,画圆被绕晕了
目标图片:

实现代码:
# -*- coding:utf-8 -*-
# __author__ :kusy
# __content__:文件说明
# __date__:2018/8/21 13:08
import turtle
import time
import math as m class Sheep(object): def __init__(self,xsize):
self.t = turtle.Turtle()
self.xsize = xsize
t = self.t
# 画笔设置
t.screen.screensize(canvwidth=1000,canvheight=500,bg='white')
t.pensize(2)
t.speed(10)
# t.hideturtle()
#初始化画笔位置
t.penup()
t.setpos(self.xsize,0)
t.pendown() # 设置画笔坐标
def setxy(self,x,y):
t = self.t
t.penup()
pos_x = t.position()[0]
pos_y = t.position()[1]
t.setpos(pos_x + x,pos_y + y)
t.pendown() def create_sheep(self):
t = self.t
# 羊头
self.setxy(-200,0)
t.fillcolor('black')
t.begin_fill()
t.circle(100)
t.end_fill() # 眼睛
# 眼白
print(t.position())
self.setxy(-20,120) t.fillcolor('white')
t.begin_fill()
t.seth(45)
t.circle(18,-280)
t.seth(45)
t.circle(-20,292)
t.end_fill()
# 眼珠
self.setxy(3,12)
t.fillcolor('black')
t.begin_fill()
t.seth(85)
t.circle(10)
t.seth(85)
t.circle(-10)
t.end_fill()
# 眼心
t.fillcolor('white')
t.begin_fill()
t.seth(85)
t.circle(3)
t.seth(85)
t.circle(-3)
t.end_fill() # 嘴
self.setxy(0,-100)
t.color('red')
t.seth(300)
t.forward(8)
self.setxy(-1, 3)
t.seth(0)
t.circle(80,60)
self.setxy(2, -2)
t.seth(145)
t.forward(8)
t.color('black') # 耳朵
self.setxy(-145,120)
p1 = t.position()
t.fillcolor('black')
t.begin_fill()
t.seth(0)
t.circle(-120,20)
p2 = t.position()
t.setpos(p1)
t.seth(60)
t.circle(-30,120)
t.goto(p2)
t.end_fill() # 身体
self.setxy(41,12)
t.seth(45)
t.circle(-150,100)
t.pensize(5)
t.seth(0)
t.circle(-120,30)
t.seth(60)
t.circle(-15,320)
t.seth(330)
t.circle(-80,180)
t.seth(210)
t.circle(-80,90) #4条腿
t.pensize(2)
for leg in range(4):
self.setxy(8+15*leg,0)
t.seth(270)
t.forward(80)
t.seth(0)
t.forward(8)
t.seth(90)
t.forward(80) #草
self.setxy(-200,-80)
p3 = t.position()
t.color('green')
t.fillcolor('green')
t.begin_fill()
t.seth(120)
t.forward(30)
t.seth(330)
t.forward(30)
t.seth(60)
t.forward(40)
t.seth(260)
t.forward(45)
t.setpos(p3)
t.end_fill() if __name__ == '__main__':
for x in (0,350):
sheep = Sheep(x)
sheep.create_sheep()
time.sleep(5)
实际效果(2只羊):

PS:circle函数使用记录
turtle.circle(radius, extent=None, steps=None)
描述: 以给定半径画圆
参数:
radius(半径); 半径为正(负),表示圆心在画笔的左边(右边)画圆
extent(弧度) (optional);
steps (optional) (做半径为radius的圆的内切正多边形,多边形边数为steps)
radius > 0,逆时针画圆
radius < 0,顺时针画圆
extent > 0,取正方向的圆
extent < 0,取反方向的圆
参考资料
https://ibaotu.com/sucai/187303.html
https://www.cnblogs.com/nowgood/p/turtle.html#_nav_6
https://www.cnblogs.com/yu-liang/p/9166003.html
https://blog.csdn.net/qq_33733970/article/details/80373247
https://www.jb51.net/article/130181.htm
https://www.jb51.net/article/139349.htm
使用Python的turtle画小绵羊的更多相关文章
- python运用turtle 画出汉诺塔搬运过程
python运用turtle 画出汉诺塔搬运过程 1.打开 IDLE 点击File-New File 新建立一个py文件 2.向py文件中输入如下代码 import turtle class Stac ...
- Python——用turtle画一个月饼
今天是中秋节,首先在这里祝大家中秋快乐!那么提到中秋,我们首先想到的当然是香甜的月饼,所以我今天就在这里画一个月饼送给大家. 那么 要用Python画图,我们必须掌握并运用Turtle库,这个可以自己 ...
- python之turtle画蚊香
原理:利用turtle绘制圆形,并使圆半径逐步增加 代码如下: import turtle turtle.pensize(30) for i in range(30): turtle.circle(i ...
- Python之turtle画同心圆和棋盘
画饼图 import turtle t = turtle.Pen() for i in range(5): t.penup() t.goto(0, -i*30) t.pendown() t.circl ...
- 用python的turtle画分形树
由于分形树具有对称性,自相似性,所以我们可以用递归来完成绘制.只要确定开始树枝长.每层树枝的减短长度和树枝分叉的角度,我们就可以把分形树画出来啦!! 代码如下: # -*- coding: utf-8 ...
- python 用turtle 画小猪佩奇
from turtle import * def nose(x,y):#鼻子 penup()#提起笔 goto(x,y)#定位 pendown()#落笔,开始画 setheading(-30)#将乌龟 ...
- 用python画小王八裤(turtle库)
一,采用Python语言如何画一朵玫瑰花 工具/原料 Python语言包 Win10 一. 准备 1. 打开界面: 打开python 2. 创建文件 二. 编程 1. 编写画图: from turtl ...
- *【Python】【demo实验31】【练习实例】【使用turtle画小猪佩奇】
如下图小猪佩奇: 要求使用turtle画小猪佩奇: 源码: # encoding=utf-8 # -*- coding: UTF-8 -*- # 使用turtle画小猪佩奇 from turtle i ...
- 【Python】【demo实验29】【练习实例】【使用turtle画五角星】
原题: 使用turtle画五角星: 我的代码: #!/usr/bin/python # encoding=utf-8 # -*- coding: UTF-8 -*- from turtle impor ...
随机推荐
- Spring @Scheduled定时任务的fixedRate,fixedDelay,cron的作用和不同
一. 三种定时类型. 1.cron --@Scheduled(cron="0/5 * * * *?") 当时间达到设置的时间会触发事件.上面那个例子会每5秒执行一次. 201 ...
- [Javascript] ES6 Class Constructors and the Super Keyword
When the ES6 class shipped back in 2015, a number of additional keywords came with it. Two of these ...
- PostgreSQL 执行计划
简介 PostgreSQL是“世界上最先进的开源关系型数据库”.因为出现较晚,所以客户人群基数较MySQL少,但是发展势头很猛,最大优势是完全开源. MySQL是“世界上最流行的开源关系型数据库”.当 ...
- ent 基本使用十二 字段
字段或者属性,在schema中是定点的属性,比如user 包含4个字段age,name,username,created_at 图表展示如下: 代码描述 package schema impo ...
- blessed-contrib 开发终端dashboard 的几点说明
以前有说过blessed-contrib 这个很不错的终端dashboard 开发框架,以下是使用中的一些问题 中文编码 模式是不支持中文编码的,但是 我们可以在初始化的时候指定unicode编码 s ...
- 因子分解机 FM
特征组合 人工方式的特征工程,通常有两个问题: 特征爆炸 大量重要的特征组合都隐藏在数据中,无法被专家识别和设计 针对上述两个问题,广度模型和深度模型提供了不同的解决思路. 广度模型包括FM/FFM等 ...
- <转>python列表、元组、集合、字典、json相互转换以及其他基础入门
列表元组转其他 # 列表转集合(去重) list1 = [6, 7, 7, 8, 8, 9] set(list1) # {6, 7, 8, 9} #两个列表转字典 list1 = ['key1','k ...
- 【NOI2002】荒岛野人(信息学奥赛一本通 1637)(洛谷 2421)
题目描述 克里特岛以野人群居而著称.岛上有排列成环行的M个山洞.这些山洞顺时针编号为1,2,…,M.岛上住着N个野人,一开始依次住在山洞C1,C2,…,CN中,以后每年,第i个野人会沿顺时针向前走Pi ...
- UIAutomatorViewer、Inspector获取元素信息
一.UIautomatorViewer 它是Android SDK的一个工具,如果安装了 Android SDK,就可以在cmd窗口直接输入uiautomatorviewer打开. 点击左上角的第二个 ...
- Octopus501工作站 安装记录
cmake libreadline-dev 没有运行程序,nvidia-smi查看GPU-Util 达到100% 解决方案:需要把驱动模式设置为常驻内存才可以,设置命令:nvidia-smi -pm ...