您好,登錄后才能下訂單哦!
晚上自習無聊
正好拿自己的平板電腦用python寫了個小程序,運用turtle模塊畫一個小心心,并在心上畫女票名字的首字母縮寫,單純只為紅顏一笑。
代碼貼出來,很簡單
import turtle import time def liujia(): for i in range (200): turtle.right(1) turtle.forward(1) turtle.color('red','pink') turtle.pensize(2) turtle.speed(10) turtle.goto(0,0) turtle.begin_fill() turtle.left(140) turtle.forward(112) liujia() turtle.left(120) liujia() turtle.forward(112) turtle.end_fill() turtle.pensize(5) turtle.up() turtle.goto(-50,142.7) turtle.left(50) turtle.down() turtle.forward(60) turtle.left(90) turtle.forward(25) turtle.up() turtle.goto(37.5,142.7) turtle.down() turtle.forward(25) turtle.up() turtle.goto(50,142.7) turtle.right(90) turtle.down() turtle.forward(60) for i in range (20): turtle.right(7.8) turtle.forward(0.3) turtle.forward(8) turtle.up() turtle.goto(100,-10) turtle.write("I Love you")
雖然丑丑的,但是她笑了啊
代碼這樣應該好理解了吧,各位老鐵,不要再問怎么改名字了,網上學一下turtle庫怎么使用,很簡單的
import turtle import time Name=['L','J'] def draw_circle(): for i in range (200): turtle.right(1) turtle.forward(1) def draw_love(): turtle.color('red','pink') turtle.pensize(2) turtle.speed(1000) turtle.goto(0,0) turtle.begin_fill() turtle.left(140) turtle.forward(112) draw_circle() turtle.left(120) draw_circle() turtle.forward(112) turtle.end_fill() def draw_name(): turtle.pensize(5) turtle.up() turtle.goto(-50,142.7) if Name[0]=='L': turtle.left(50) turtle.down() turtle.forward(60) turtle.left(90) turtle.forward(25) turtle.up() turtle.goto(37.5,142.7) if Name[1]=='J': turtle.down() turtle.forward(25) turtle.up() turtle.goto(50,142.7) turtle.right(90) turtle.down() turtle.forward(60) for i in range (20): turtle.right(7.8) turtle.forward(0.3) turtle.forward(8) turtle.up() turtle.goto(100,-10) turtle.write("I Love you") draw_love() draw_name()
以上這篇用python的turtle模塊實現給女票畫個小心心就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。