python 实现turtle画图并导出图片格式的文件

yipeiwu_com6年前Python基础

如下所示:

from turtle import*
import turtle
setup(800,700,300,50)
penup()
seth(90)
fd(100)
seth(0)
fd(-200)
pendown()
pensize(3)
pencolor("black")
seth(0)
fd(210)
seth(90)
fd(20)
seth(115)
circle(120,129)
seth(270)
fd(20)
seth(270)
fd(15)
seth(0)
fd(217)
seth(90)
fd(19)
penup()
seth(150)
fd(155)
pendown()
pencolor("blue")
pensize(2)
seth(200)
circle(70,40)
circle(5,40)
circle(20,90)
circle(10,140)
fd(5)
seth(330)
circle(-10,140)
seth(120)
circle(5,40)
seth(160)
circle(-30,30)
seth(65)
circle(-70,50)
penup()
seth(10)
fd(25)
seth(-25)
pendown()
circle(-70,40)
circle(-5,40)
circle(-20,90)
circle(-10,140)
seth(-30)
circle(5,40)
seth(180)
seth(225)
fd(-5)
seth(140)
circle(17,260)
seth(5)
circle(28,120)
penup()
seth(200)
fd(150)
seth(210)
fd(30)
seth(270)
fd(30)
seth(0)
fd(18)
pendown()
pencolor("black")
seth(270)
fd(160)
seth(0)
fd(70)
seth(0)
fd(50)
seth(90)
 
 
 
 
fd(160)
ts = turtle.getscreen()
ts.getcanvas().postscript(file="work.eps")

PostScript是一种页面描述语言,主要用于高质量打印。

# 以下代码,将画好的图案按指定格式保存到当前文件目录

# 可以使用 .eps格式,对于.jpg格式,即使生成图片,也因为jpeg标识符段长度太短,导致文件不完整无法打开。

ts = turtle.getscreen()

ts.getcanvas().postscript(file="work.eps")

#在当前工作目录下生成work.eps格式图片,这种格式使用photoshop可以打开。生成过程中控制台会输出如下语句:

'-81.1893121271068 426.860206316411 moveto\n-86.1893121271068 417.860206316411 lineto\n-81.1893121271068 419.860206316411 lineto\n-76.1893121271068 417.860206316411 lineto\n-81.1893121271068 426.860206316411 lineto\n0.000 0.000 0.000 setrgbcolor AdjustColor\neofill\n-81.1893121271068 426.860206316411 moveto\n-86.1893121271068 417.860206316411 lineto\n-81.1893121271068 419.860206316411 lineto\n-76.1893121271068 417.860206316411 lineto\n-81.1893121271068 426.860206316411 lineto\n1 setlinejoin 1 setlinecap\n1 setlinewidth\n[] 0 setdash\n0.000 0.000 0.000 setrgbcolor AdjustColor\nstroke\n'

有可能是你的绘图痕迹。

ts.getcanvas().postscript(file=r"C:\work.eps")

#这样就是指定图片生成的位置为c盘下了。

以上这篇python 实现turtle画图并导出图片格式的文件就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Django Celery异步任务队列的实现

背景 在开发中,我们常常会遇到一些耗时任务,举个例子: 上传并解析一个 1w 条数据的 Excel 文件,最后持久化至数据库。 在我的程序中,这个任务耗时大约 6s,对于用户来说,...

Python生成数字图片代码分享

本文向大家分享了几段Python生成数字图片的代码,喜欢的朋友可以参考。具体如下: 最终版本 # -*- coding:utf-8 -*- from PIL import Image...

从零学Python之入门(二)基本数据类型

简单的数据类型以及赋值 变量不需要声明 Python的变量不需要声明,你可以直接输入: 复制代码 代码如下:>>>a = 10 那么你的内存里就有了一个变量a, 它的值...

pandas 数据结构之Series的使用方法

1. Series Series 是一个类数组的数据结构,同时带有标签(lable)或者说索引(index)。 1.1 下边生成一个最简单的Series对象,因为没有给Series指定索...

Python使用matplotlib绘制Logistic曲线操作示例

Python使用matplotlib绘制Logistic曲线操作示例

本文实例讲述了Python使用matplotlib绘制Logistic曲线操作。分享给大家供大家参考,具体如下: 标准Logistic函数为: f(x) = 1 / ( 1 + ex...