用python畫豬頭的方法:先設定畫布和畫筆,程式碼為【a.screensize(400,300)a.setup(width=400,height=300)】;然後畫臉型,程式碼為【. goto(-100,100)】;最後留存影像在畫布上即可。
【相關學習推薦:#python影片】
用python畫豬頭的方法:
畫布和畫筆設定
import turtle as a a.screensize(400,300)//设置屏幕大小 a.setup(width=400,height=300)//设置画布大小 a.pensize(15)//设置画笔宽度 a.speed(5)//设置画笔速度 a.hideturtle()//隐藏画笔
畫臉盤
a.penup()//提笔 a.goto(-100,100)//移动画笔位置 a.setheading(180)//设置朝向正西 a.pencolor("pink") a.pendown()//放笔 a.circle(200)
取名字
a.penup()//取名 a.goto(-150,10) yourname=a.textinput("请老实回答","你的名字是?") name=yourname+"崽崽" a.pendown() a.write(name,font=("elephant",25,"bold"))//打印文本
畫眼睛
a.penup()//画左眼 a.goto(-200,0) a.pendown() a.circle(25) a.penup() a.goto(-200,-14) a.pendown() a.circle(9) a.penup()//光晕 a.goto(-190,-20) a.pencolor("white") a.pendown() a.dot(10) a.penup()//画右眼 a.pencolor("pink") a.goto(0,0) a.pendown() a.circle(25) a.penup()//光晕 a.goto(0,-14) a.pendown() a.circle(9) a.penup() a.goto(-10,-20) a.pencolor("white") a.pendown() a.dot(10)
畫鼻子
a.penup()//画鼻子 a.speed(10)//设置画笔速度 a.pencolor("pink") a.goto(-150,-75) a.setheading(45) a.pendown() for i in range(90): a.forward(1.5) a.right(1) for i in range(3): //圆化棱角,每转16度向前走3个像素 a.right(16) a.forward(3) a.forward(15) for i in range(3): //圆化棱角 a.right(16) a.forward(3) a.setheading(225) for i in range(90): a.forward(1.5) a.right(1) for i in range(3): //圆化棱角 a.right(16) a.forward(3) a.forward(15) for i in range(3): //圆化棱角 a.right(16) a.forward(3) a.penup() a.speed(5)//设置画笔速度 a.goto(-125,-70)//第一条杠 a.setheading(270) a.pendown() a.forward(50) a.penup() a.goto(-70,-65)//第二条杠 a.pendown() a.forward(55)
#畫嘴巴
a.penup()//画嘴巴 a.speed(10)//设置画笔速度 a.goto(-135,-165) a.setheading(305) a.pendown() for i in range(120): a.forward(1) a.left(1)
畫耳朵
a.penup()//画右耳朵 a.speed(5) a.setheading(0) a.goto(-17,90) a.pendown() a.forward(60) a.penup() a.goto(28,75)//跳到下一笔起始位置 a.setheading(45) a.pendown() a.forward(110) a.right(45) a.forward(40) a.setheading(225) a.forward(40) a.setheading(270) for i in range(7): //圆化棱角 a.right(2.5) a.forward(10) a.forward(80) a.penup()//画左耳朵 a.goto(-183,90) a.setheading(180) a.pendown() a.forward(60) a.penup() a.goto(-230,75)//跳到下一笔起始位置 a.setheading(135) a.pendown() a.forward(110) a.left(45) a.forward(40) a.setheading(-45) a.forward(40) a.setheading(270) for i in range(10): //圆化棱角 a.left(2.5) a.forward(15)
畫腮紅
a.penup()//画左腮红 a.pencolor("tomato")//设置成番茄色 a.goto(-250,-100) a.setheading(270) a.pendown() a.forward(20) a.penup() a.goto(-210,-100) a.pendown() a.forward(20) a.penup()//画右腮红 a.goto(10,-100) a.pendown() a.forward(20) a.penup() a.goto(50,-100) a.pendown() a.forward(20)
a.done() //留存图像在画布上
##以完整原始碼
#!/usr/bin/env python3.7 #指明用什么可执行程序运行这个文件代码 #-*- coding:UTF-8 -*- #保证能顺利解析中文 #author:Boosirit time:2020/4/5 import turtle as a a.screensize(400,300)#设置屏幕大小 a.setup(width=400,height=300)#设置画布大小 a.pensize(15)#设置画笔宽度 a.speed(5)#设置画笔速度 a.hideturtle()#隐藏画笔 a.penup()#画脸 a.goto(-100,100) a.setheading(180)#设置朝向正西 a.pencolor("pink") a.pendown() a.circle(200) a.penup()#取名 a.goto(-150,10) yourname=a.textinput("请老实回答","你的名字是?") name=yourname+"崽崽" a.pendown() a.write(name,font=("elephant",25,"bold"))#打印文本 a.penup()#画左眼 a.goto(-200,0) a.pendown() a.circle(25) a.penup() a.goto(-200,-14) a.pendown() a.circle(9) a.penup()#光晕 a.goto(-190,-20) a.pencolor("white") a.pendown() a.dot(10) a.penup()#画右眼 a.pencolor("pink") a.goto(0,0) a.pendown() a.circle(25) a.penup()#光晕 a.goto(0,-14) a.pendown() a.circle(9) a.penup() a.goto(-10,-20) a.pencolor("white") a.pendown() a.dot(10) a.penup()#画鼻子 a.speed(10)#设置画笔速度 a.pencolor("pink") a.goto(-150,-75) a.setheading(45) a.pendown() for i in range(90): a.forward(1.5) a.right(1) for i in range(3):#圆化棱角,每转16度向前走3个像素 a.right(16) a.forward(3) a.forward(15) for i in range(3):#圆化棱角 a.right(16) a.forward(3) a.setheading(225) for i in range(90): a.forward(1.5) a.right(1) for i in range(3):#圆化棱角 a.right(16) a.forward(3) a.forward(15) for i in range(3):#圆化棱角 a.right(16) a.forward(3) a.penup() a.speed(5)#设置画笔速度 a.goto(-125,-70)#第一条杠 a.setheading(270) a.pendown() a.forward(50) a.penup() a.goto(-70,-65)#第二条杠 a.pendown() a.forward(55) a.penup()#画嘴巴 a.speed(10)#设置画笔速度 a.goto(-135,-165) a.setheading(305) a.pendown() for i in range(120): a.forward(1) a.left(1) a.penup()#画右耳朵 a.speed(5) a.setheading(0) a.goto(-17,90) a.pendown() a.forward(60) a.penup() a.goto(28,75)#跳到下一笔起始位置 a.setheading(45) a.pendown() a.forward(110) a.right(45) a.forward(40) a.setheading(225) a.forward(40) a.setheading(270) for i in range(7):#圆化棱角 a.right(2.5) a.forward(10) a.forward(80) a.penup()#画左耳朵 a.goto(-183,90) a.setheading(180) a.pendown() a.forward(60) a.penup() a.goto(-230,75)#跳到下一笔起始位置 a.setheading(135) a.pendown() a.forward(110) a.left(45) a.forward(40) a.setheading(-45) a.forward(40) a.setheading(270) for i in range(10):#圆化棱角 a.left(2.5) a.forward(15) a.penup()#画左腮红 a.pencolor("tomato")#设置成番茄色 a.goto(-250,-100) a.setheading(270) a.pendown() a.forward(20) a.penup() a.goto(-210,-100) a.pendown() a.forward(20) a.penup()#画右腮红 a.goto(10,-100) a.pendown() a.forward(20) a.penup() a.goto(50,-100) a.pendown() a.forward(20) a.done()#留存图像在画布上
想了解更多程式設計學習,請關注php培訓欄位!
#
以上是如何用python畫豬頭的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Python在遊戲和GUI開發中表現出色。 1)遊戲開發使用Pygame,提供繪圖、音頻等功能,適合創建2D遊戲。 2)GUI開發可選擇Tkinter或PyQt,Tkinter簡單易用,PyQt功能豐富,適合專業開發。

Python适合数据科学、Web开发和自动化任务,而C 适用于系统编程、游戏开发和嵌入式系统。Python以简洁和强大的生态系统著称,C 则以高性能和底层控制能力闻名。

2小時內可以學會Python的基本編程概念和技能。 1.學習變量和數據類型,2.掌握控制流(條件語句和循環),3.理解函數的定義和使用,4.通過簡單示例和代碼片段快速上手Python編程。

Python在web開發、數據科學、機器學習、自動化和腳本編寫等領域有廣泛應用。 1)在web開發中,Django和Flask框架簡化了開發過程。 2)數據科學和機器學習領域,NumPy、Pandas、Scikit-learn和TensorFlow庫提供了強大支持。 3)自動化和腳本編寫方面,Python適用於自動化測試和系統管理等任務。

兩小時內可以學到Python的基礎知識。 1.學習變量和數據類型,2.掌握控制結構如if語句和循環,3.了解函數的定義和使用。這些將幫助你開始編寫簡單的Python程序。

如何在10小時內教計算機小白編程基礎?如果你只有10個小時來教計算機小白一些編程知識,你會選擇教些什麼�...

使用FiddlerEverywhere進行中間人讀取時如何避免被檢測到當你使用FiddlerEverywhere...

Python3.6環境下加載Pickle文件報錯:ModuleNotFoundError:Nomodulenamed...


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

記事本++7.3.1
好用且免費的程式碼編輯器

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

SublimeText3漢化版
中文版,非常好用