今天学习使用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画小绵羊的更多相关文章

  1. python运用turtle 画出汉诺塔搬运过程

    python运用turtle 画出汉诺塔搬运过程 1.打开 IDLE 点击File-New File 新建立一个py文件 2.向py文件中输入如下代码 import turtle class Stac ...

  2. Python——用turtle画一个月饼

    今天是中秋节,首先在这里祝大家中秋快乐!那么提到中秋,我们首先想到的当然是香甜的月饼,所以我今天就在这里画一个月饼送给大家. 那么 要用Python画图,我们必须掌握并运用Turtle库,这个可以自己 ...

  3. python之turtle画蚊香

    原理:利用turtle绘制圆形,并使圆半径逐步增加 代码如下: import turtle turtle.pensize(30) for i in range(30): turtle.circle(i ...

  4. Python之turtle画同心圆和棋盘

    画饼图 import turtle t = turtle.Pen() for i in range(5): t.penup() t.goto(0, -i*30) t.pendown() t.circl ...

  5. 用python的turtle画分形树

    由于分形树具有对称性,自相似性,所以我们可以用递归来完成绘制.只要确定开始树枝长.每层树枝的减短长度和树枝分叉的角度,我们就可以把分形树画出来啦!! 代码如下: # -*- coding: utf-8 ...

  6. python 用turtle 画小猪佩奇

    from turtle import * def nose(x,y):#鼻子 penup()#提起笔 goto(x,y)#定位 pendown()#落笔,开始画 setheading(-30)#将乌龟 ...

  7. 用python画小王八裤(turtle库)

    一,采用Python语言如何画一朵玫瑰花 工具/原料 Python语言包 Win10 一. 准备 1. 打开界面: 打开python 2. 创建文件 二. 编程 1. 编写画图: from turtl ...

  8. *【Python】【demo实验31】【练习实例】【使用turtle画小猪佩奇】

    如下图小猪佩奇: 要求使用turtle画小猪佩奇: 源码: # encoding=utf-8 # -*- coding: UTF-8 -*- # 使用turtle画小猪佩奇 from turtle i ...

  9. 【Python】【demo实验29】【练习实例】【使用turtle画五角星】

    原题: 使用turtle画五角星: 我的代码: #!/usr/bin/python # encoding=utf-8 # -*- coding: UTF-8 -*- from turtle impor ...

随机推荐

  1. Codeforces Round #552 (Div. 3)-1154E-Two Teams-(模拟+双指针)

    http://codeforces.com/contest/1154/problem/E 解题: 举例n=10,k=1 1,2,10,4,7,6,9,8,5,3 第一次,1队先挑2,10,4这三个人 ...

  2. HDU 6583 Typewriter(后缀自动机)

    Typewrite \[ Time Limit: 1500 ms\quad Memory Limit: 262144 kB \] 题意 给出一个字符串 \(s\),现在你需要构造出这个字符串,你每次可 ...

  3. RPM包——查询

    1.rpm -q (1)    查询是否已经安装某一个rpm包: 例如:rpm -q httpd (2)-qa:查询所有的已经安装的包: 2.查询软件包的详细信息: rpm -qi -i :查询软件包 ...

  4. [SDOI2019]热闹又尴尬的聚会 构造,贪心

    [SDOI2019]热闹又尴尬的聚会 链接 luogu loj 思路 第一问贪心?的从小到大删除入度最小的点,入度是动态的,打个标记. 当然不是最大独立集. 第二问第一问的顺序选独立集,不行就不要.选 ...

  5. Android编程权威指南笔记

    学习android开发,你需要对java语言,包括类,对象,接口,监听器,包,内部类,匿名内部类有所了解. android studio 的下载与安装 可以从android开发者网站下载android ...

  6. ubuntu14.04 安装python3.7

    下载源码:https://www.python.org/downloads/release/python-373/ 一.先安装需要的包zlib1g,libffisudo apt-get update ...

  7. 从工厂流水线小妹到Google上班程序媛,看完后,我跪服了!

    阅读本文大概需要 10.2 分钟. 文作者:Ling Sun 原文链接:https://www.zhihu.com/question/68154951/answer/546265013 我家境很不好, ...

  8. Fiddler添加过滤条件

  9. 【转】解决chrome浏览器不支持audio和video标签的autoplay自动播放

    声音无法自动播放这个在 IOS/Android 上面一直是个惯例,桌面版的 Safari 在 2017 年的 11 版本也宣布禁掉带有声音的多媒体自动播放功能,紧接着在 2018 年 4 月份发布的 ...

  10. Python知乎上推荐的项目

    原文地址:https://www.zhihu.com/question/29372574/answer/88744491 作者:Wayne Shi链接:https://www.zhihu.com/qu ...