用python的turtle模組實現給女票畫個小心心
阿新 • • 發佈:2020-01-09
晚上自習無聊
正好拿自己的平板電腦用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模組實現給女票畫個小心心就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援我們。