python 實現(xiàn)turtle畫圖并導(dǎo)出圖片格式的文件
如下所示:
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是一種頁面描述語言,主要用于高質(zhì)量打印。
# 以下代碼,將畫好的圖案按指定格式保存到當(dāng)前文件目錄
# 可以使用 .eps格式,對于.jpg格式,即使生成圖片,也因為jpeg標(biāo)識符段長度太短,導(dǎo)致文件不完整無法打開。
ts = turtle.getscreen()
ts.getcanvas().postscript(file="work.eps")
#在當(dāng)前工作目錄下生成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 實現(xiàn)turtle畫圖并導(dǎo)出圖片格式的文件就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python Switch Case三種實現(xiàn)方法代碼實例
這篇文章主要介紹了Python Switch Case2種實現(xiàn)方法代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-06-06
python實現(xiàn)調(diào)用其他python腳本的方法
python實現(xiàn)調(diào)用其他python腳本的方法,是一個比較實用的技巧,需要的朋友可以參考下2014-10-10
Python數(shù)據(jù)類型中的“冒號“[::]——分片與步長操作示例
這篇文章主要介紹了Python數(shù)據(jù)類型中的“冒號“[::]——分片與步長操作,結(jié)合實例形式分析了Python基本數(shù)據(jù)類型中的分片與步長使用方法及相關(guān)操作技巧,需要的朋友可以參考下2018-01-01
Python如何爬取51cto數(shù)據(jù)并存入MySQL
這篇文章主要介紹了Python如何爬取51cto數(shù)據(jù)并存入MySQL,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-08-08
Python3.7安裝PyQt5 運行配置Pycharm的詳細教程
這篇文章主要介紹了Python3.7成功安裝心得PyQt5 PyQt5-tools QT designer.exe運行配置Pycharm 將.ui文件翻譯成.py文件,本文給大家介紹的非常詳細,需要的朋友可以參考下2020-10-10
Django 忘記管理員或忘記管理員密碼 重設(shè)登錄密碼的方法
今天小編就為大家分享一篇Django 忘記管理員或忘記管理員密碼 重設(shè)登錄密碼的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-05-05

