使用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 ...
随机推荐
- ios Aspects面向切面沉思录—面向结构编程—面向修改记录编程—面向运行时结构编程—元编程?
1.将主功能看成一个巨大的结构: 2.将切面注入的交叉业务看成是一组结构修改的注册:目标对象+方法是修改的键值: 3.Aspects引擎是修改的执行者.记录者.和维护者: 4.函数和方法是它操作和面对 ...
- Spring @Scheduled定时任务的fixedRate,fixedDelay,cron的作用和不同
一. 三种定时类型. 1.cron --@Scheduled(cron="0/5 * * * *?") 当时间达到设置的时间会触发事件.上面那个例子会每5秒执行一次. 201 ...
- ZOJ3261-Connections in Galaxy War-(逆向并查集+离线处理)
题意: 1.有n个星球,每个星球有一个编号(1-n)和一个能量值. 2.一开始将某些星球连通. 3.开战后有很多个操作,查询某个星球能找谁求救或者摧毁两颗星球之间的连通路径,使其不能连通.如果连通则可 ...
- 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这三个人 ...
- cube.js 集成cratedb 的尝试
cratedb 提供了pg协议的兼容,我们可以直接使用pg client 连接,但是也不是完整实现pg 协议的 以下是 cube.js 集成cratedb 的一些尝试 环境准备 docker-comp ...
- P4211 [LNOI2014]LCA LCT
P4211 [LNOI2014]LCA 链接 loj luogu 思路 多次询问\(\sum\limits_{l \leq i \leq r}dep[LCA(i,z)]\) 可以转化成l到r上的点到根 ...
- 【11NOIP提高组】选择客栈(信息学奥赛一本通 1546)(洛谷 1311)
题目描述 丽江河边有nn家很有特色的客栈,客栈按照其位置顺序从 11到nn编号.每家客栈都按照某一种色调进行装饰(总共 kk 种,用整数 00 ~k-1k−1 表示),且每家客栈都设有一家咖啡店,每家 ...
- ZooKeeper入门实战教程(一)-介绍与核心概念
1.ZooKeeper介绍与核心概念1.1 简介ZooKeeper最为主要的使用场景,是作为分布式系统的分布式协同服务.在学习zookeeper之前,先要对分布式系统的概念有所了解,否则你将完全不知道 ...
- 分析WordPress数据表之文章表(功能篇)
数据表分析 wp_posts(文章表) 表字段如下:ID(文章ID)post_author(文章作者名,我想可以是为用户名,也可以是用户ID)post_date(文章发布日期)post_date_gm ...
- spring以及json,fastjson和jackson
(一) @RestController 以及 @RequestBody spring的这两个注解都需要使用对应的 message-converters 实现 pojo到字符串的转换, 需要配置实现了 ...