程序猿520python表白利器——丘比特之箭
生活随笔
收集整理的這篇文章主要介紹了
程序猿520python表白利器——丘比特之箭
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
? ? ? ? 伙計(jì)們,快到520咯,身為程序猿的你,準(zhǔn)備好給自己心動(dòng)的女神表白嘛!除了必備的鮮花、禮物,不妨也試試用python編程畫一只丘比特之箭給獨(dú)一無(wú)二的女友吧!!!
? ? ? ?首先定義好以下函數(shù)來(lái)進(jìn)行坐標(biāo)軸的定義,用于繪制愛心的大圓的函數(shù)定義,?用于繪制愛心的小圓的函數(shù)定義,用于定義線的速度及粗細(xì)的函數(shù)定義。
def go_to(self, x, y): #定義坐標(biāo)軸turtle.up()turtle.goto(x, y)turtle.down()def big_circle(self, size): # 定義函數(shù)用于繪制愛心的大圓turtle.speed(1)for i in range(180):turtle.forward(size)turtle.right(0.3)def small_circle(self, size): # 定義函數(shù)用于繪制愛心的小圓turtle.speed(1)for i in range(240):turtle.forward(size)turtle.right(0.786)def line(self, size): #定義函數(shù)用于定義線的速度及粗細(xì)turtle.speed(1000)turtle.forward(51 * size)????????用函數(shù)分別定義好兩顆愛心的坐標(biāo)、穿過(guò)兩顆愛心的直線方法、丘比特之箭箭頭的方法。
def heart(self, x, y, size):self.go_to(x, y)turtle.left(150)turtle.begin_fill()self.line(size)self.big_circle(size)self.small_circle(size)turtle.left(120)self.small_circle(size)self.big_circle(size)self.line(size)turtle.end_fill()def arrow(self):turtle.pensize(10)turtle.setheading(0)self.go_to(-400, 0)turtle.left(15)turtle.forward(150)self.go_to(339, 178)turtle.forward(150)def arrow_head(self):turtle.pensize(1)turtle.speed(0)turtle.color('pink', 'pink')turtle.begin_fill()turtle.left(120)turtle.forward(20)turtle.right(150)turtle.forward(35)turtle.right(120)turtle.forward(35)turtle.right(150)turtle.forward(20)turtle.end_fill()????????集合函數(shù)到main()進(jìn)行輸出:
def main():turtle.pensize(2)turtle.color('pink', 'pink')my_heart = MyLove()my_heart.heart(200, 0, 1) # 畫出第一顆心,前面兩個(gè)參數(shù)控制心的位置,函數(shù)最后一個(gè)參數(shù)可控制心的大小turtle.setheading(0) # 使畫筆的方向朝向x軸正方向my_heart.heart(-80, -100, 1.5) # 畫出第二顆心my_heart.arrow() # 畫出穿過(guò)兩顆心的直線my_heart.arrow_head() # 畫出箭的箭頭my_heart.go_to(320, -280)turtle.write("@Darren洋", move=True, align="right", font=("黑體", 28, "normal"))turtle.done() if __name__ == '__main__':main()完整代碼如下:
import turtle class MyLove(object):def go_to(self, x, y):turtle.up()turtle.goto(x, y)turtle.down()def big_circle(self, size): turtle.speed(1)for i in range(180):turtle.forward(size)turtle.right(0.3)def small_circle(self, size): turtle.speed(1)for i in range(240):turtle.forward(size)turtle.right(0.786)def line(self, size):turtle.speed(1000)turtle.forward(51 * size)def heart(self, x, y, size):self.go_to(x, y)turtle.left(150)turtle.begin_fill()self.line(size)self.big_circle(size)self.small_circle(size)turtle.left(120)self.small_circle(size)self.big_circle(size)self.line(size)turtle.end_fill()def arrow(self):turtle.pensize(10)turtle.setheading(0)self.go_to(-400, 0)turtle.left(15)turtle.forward(150)self.go_to(339, 178)turtle.forward(150)def arrow_head(self):turtle.pensize(1)turtle.speed(0)turtle.color('pink', 'pink')turtle.begin_fill()turtle.left(120)turtle.forward(20)turtle.right(150)turtle.forward(35)turtle.right(120)turtle.forward(35)turtle.right(150)turtle.forward(20)turtle.end_fill() def main():turtle.pensize(2)turtle.color('pink', 'pink')my_heart = MyLove()my_heart.heart(200, 0, 1) turtle.setheading(0) my_heart.heart(-80, -100, 1.5) my_heart.arrow() my_heart.arrow_head() my_heart.go_to(320, -280)turtle.write("@Darren洋", move=True, align="right", font=("黑體", 28, "normal"))turtle.done() if __name__ == '__main__':main()效果圖如下:
?
總結(jié)
以上是生活随笔為你收集整理的程序猿520python表白利器——丘比特之箭的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 显示与定位.
- 下一篇: python用户管理系统