整合營銷服務商

          電腦端+手機端+微信端=數據同步管理

          免費咨詢熱線:

          送你一朵太空中的玫瑰花

          送你一朵太空中的玫瑰花

          與氧波段中的玫瑰星云,由Arno Rottal拍攝。

          來源:https://apod.nasa.gov/apod/ap150225.html

          玫瑰星云并非宇宙中唯一可以讓人聯想到花的氣體和塵埃的宇宙云,但它是最著名的。玫瑰星云位于麒麟座(Monoceros)大分子云團邊緣,距離我們約為5000光年。玫瑰星云中心區域編錄號為NGC 2237,直徑約50光年。朝著麒麟座方向,使用小型望遠鏡中就能看到這團星云。

          玫瑰星云,上圖右側區域為NGC 2237。

          天520,有些人在思考如何脫單,有些人在思考如何表白,有些人在思考如何秀恩愛,可今天還要上班怎么破?

          其實很多時候禮物不一定就需要花錢買,今天我們就用代碼來一次表白吧,把你中意的代碼發給她,看她能不能看懂,哈哈哈!

          一、入門級


          1、一行代碼畫愛心

          print('\n'.join([''.join([('Love'[(x-y)%4]if((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3<=0 else' ')for x in range(-30,30)])for y in range(15,-15,-1)]))
          

          效果圖

          2、用turtle庫畫愛心加文字

          import turtle
          import math
          turtle.pen()
          t=turtle
          t.up()
          t.goto(0,150)
          t.down()
          t.color('red')
          t.begin_fill()
          t.fillcolor('red')
          t.speed(1)
          t.left(45)
          t.forward(150)
          t.right(45)
          t.forward(100)
          t.right(45)
          t.forward(100)
          t.right(45)
          t.forward(100)
          t.right(45)
          t.forward(250+math.sqrt(2)*100)
          t.right (90)
          t.speed(2)
          t.forward(250+100*math.sqrt(2))
          t.right(45)
          t.forward(100)
          t.right(45)
          t.forward(100)
          t.right(45)
          t.forward(100)
          t.right(45)
          t.forward(150)
          t.end_fill()
          t.goto(-10,0)
          t.pencolor('white')
          #L
          t.pensize(10)
          t.goto(-50,0)
          t.goto(-50,80)
          t.up ()
          #I
          t.goto(-100,0)
          t.down()
          t.goto(-160,0)
          t.goto(-130,0)
          t.goto(-130,80)
          t.goto(-160,80)
          t.goto(-100,80)
          t.up()
          #O
          t.goto(10,25)
          t.down()
          t.right(45)
          t.circle(25,extent=180)
          t.goto(60,55)
          t.circle(25,extent=180)
          t.goto(10,25)
          t.up()
          t.goto(75,80)
          t.down()
          t.goto(100,0)
          t.goto(125,80)
          t.up()
          t.goto(180,80)
          t.down()
          t.goto(140,80)
          t.goto(140,0)
          t.goto(180,0)
          t.up()
          t.goto(180,40)
          t.down()
          t.goto(140,40)
          #U
          t.up()
          t.goto(-40,-30)
          t.down()
          t.goto(-40,-80)
          t.circle(40,extent=180)
          t.goto(40,-30)
          t.hideturtle()
          

          效果圖

          二、進階級

          1、 用turtle庫畫一朵玫瑰花

          #!/usr/bin/env python
          # coding: utf-8
          #繪制玫瑰花并添加文字
          import turtle
          # 設置畫布大小
          # turtle.screensize(canvwidth=None, canvheight=None, bg=None)
          turtle.setup(width=0.6, height=0.6)
          # 設置初始位置
          turtle.penup()
          turtle.left(90)
          turtle.fd(200)
          turtle.pendown()
          turtle.right(90)
           
          # 輸出文字
          printer=turtle.Turtle()
          printer.hideturtle()
          printer.penup()
          printer.back(200)
          printer.write("贈給親愛的 XX\n\n", align="right", font=("楷體", 16, "bold"))
          printer.write("from XXX", align="center", font=("楷體", 12, "normal"))
           
          # 花蕊
          turtle.fillcolor("red")
          turtle.begin_fill()
          turtle.circle(10, 180)
          turtle.circle(25, 110)
          turtle.left(50)
          turtle.circle(60, 45)
          turtle.circle(20, 170)
          turtle.right(24)
          turtle.fd(30)
          turtle.left(10)
          turtle.circle(30, 110)
          turtle.fd(20)
          turtle.left(40)
          turtle.circle(90, 70)
          turtle.circle(30, 150)
          turtle.right(30)
          turtle.fd(15)
          turtle.circle(80, 90)
          turtle.left(15)
          turtle.fd(45)
          turtle.right(165)
          turtle.fd(20)
          turtle.left(155)
          turtle.circle(150, 80)
          turtle.left(50)
          turtle.circle(150, 90)
          turtle.end_fill()
           
          # 花瓣1
          turtle.left(150)
          turtle.circle(-90, 70)
          turtle.left(20)
          turtle.circle(75, 105)
          turtle.setheading(60)
          turtle.circle(80, 98)
          turtle.circle(-90, 40)
           
          # 花瓣2
          turtle.left(180)
          turtle.circle(90, 40)
          turtle.circle(-80, 98)
          turtle.setheading(-83)
           
          # 葉子1
          turtle.fd(30)
          turtle.left(90)
          turtle.fd(25)
          turtle.left(45)
          turtle.fillcolor("green")
          turtle.begin_fill()
          turtle.circle(-80, 90)
          turtle.right(90)
          turtle.circle(-80, 90)
          turtle.end_fill()
          turtle.right(135)
          turtle.fd(60)
          turtle.left(180)
          turtle.fd(85)
          turtle.left(90)
          turtle.fd(80)
           
          # 葉子2
          turtle.right(90)
          turtle.right(45)
          turtle.fillcolor("green")
          turtle.begin_fill()
          turtle.circle(80, 90)
          turtle.left(90)
          turtle.circle(80, 90)
          turtle.end_fill()
          turtle.left(135)
          turtle.fd(60)
          turtle.left(180)
          turtle.fd(60)
          turtle.right(90)
          turtle.circle(200, 60)
           
          turtle.done()
          

          效果圖

          2、用turtle庫畫愛心加文字

          import turtle
          import random
          def love(x, y):  # 在(x,y)處畫愛心lalala
              lv=turtle.Turtle()
              lv.hideturtle()
              lv.up()
              lv.goto(x, y)  # 定位到(x,y)
              def curvemove():  # 畫圓弧
                  for i in range(20):
                      lv.right(10)
                      lv.forward(2)
              lv.color('red', 'pink')
              lv.speed(10000000)
              lv.pensize(1)
              # 開始畫愛心lalala
              lv.down()
              lv.begin_fill()
              lv.left(140)
              lv.forward(22)
              curvemove()
              lv.left(120)
              curvemove()
              lv.forward(22)
              lv.write("YZ", font=("Arial", 12, "normal"), align="center")  # 寫上表白的人的名字
              lv.left(140)  # 畫完復位
              lv.end_fill()
          def tree(branchLen, t):
              if branchLen > 5:  # 剩余樹枝太少要結束遞歸
                  if branchLen < 20:  # 如果樹枝剩余長度較短則變綠
                      t.color("green")
                      t.pensize(random.uniform((branchLen + 5) / 4 - 2, (branchLen + 6) / 4 + 5))
                      t.down()
                      t.forward(branchLen)
                      love(t.xcor(), t.ycor())  # 傳輸現在turtle的坐標
                      t.up()
                      t.backward(branchLen)
                      t.color("brown")
                      return
                  t.pensize(random.uniform((branchLen + 5) / 4 - 2, (branchLen + 6) / 4 + 5))
                  t.down()
                  t.forward(branchLen)
                  # 以下遞歸
                  ang=random.uniform(15, 45)
                  t.right(ang)
                  tree(branchLen - random.uniform(12, 16), t)  # 隨機決定減小長度
                  t.left(2 * ang)
                  tree(branchLen - random.uniform(12, 16), t)  # 隨機決定減小長度
                  t.right(ang)
                  t.up()
                  t.backward(branchLen)
          myWin=turtle.Screen()
          t=turtle.Turtle()
          t.hideturtle()
          t.speed(1000)
          t.left(90)
          t.up()
          t.backward(200)
          t.down()
          t.color("brown")
          t.pensize(32)
          t.forward(60)
          tree(100, t)
          myWin.exitonclick()
          

          效果圖

          三、高階版1、星空下的告白

          """
          代碼用途:表白
          作者:開源Linux
          """
          def bgpic(self, picname=None):
                  """Set background image or return name of current backgroundimage.
           
                  Optional argument:
                  picname -- a string, name of a gif-file or "nopic".
           
                  If picname is a filename, set the corresponding image as background.
                  If picname is "nopic", delete backgroundimage, if present.
                  If picname is None, return the filename of the current backgroundimage.
           
                  Example (for a TurtleScreen instance named screen):
                  >>> screen.bgpic()
                  'nopic'
                  >>> screen.bgpic("landscape.gif")
                  >>> screen.bgpic()
                  'landscape.gif'
                  """
                  if picname is None:
                      return self._bgpicname
                  if picname not in self._bgpics:
                      self._bgpics[picname]=self._image(picname)
                  self._setbgpic(self._bgpic, self._bgpics[picname])
                  self._bgpicname=picname
          # coding: utf-8
          import pygame
          import os
          import sys
          from pygame.locals import *
          os.chdir('F:/微信公眾號/Python/29.加載音樂')
          os.getcwd()
          pygame.init()
          pygame.mixer.init()
          pygame.mixer.music.load("告白.mp3")
          #pygame.mixer.music.set_volume(0.4)
          pygame.mixer.music.play()
          bg_size=width, height=300, 200
          bg_rgb=(255, 255, 255)
          screen1=pygame.display.set_mode(bg_size)
          pygame.display.set_caption("告白音樂")
          clock=pygame.time.Clock()
          play_image=pygame.image.load("開始和暫停按鈕2.png").convert_alpha()
          pause_image=pygame.image.load("開始和暫停按鈕2.png").convert_alpha()
          pause_rect=pause_image.get_rect()
          print(pause_rect.width,pause_rect.height)
          pause_rect.left, pause_rect.top=(width - pause_rect.width) // 2, (height - pause_rect.height) // 2
          from turtle import *
          from random import random,randint
          os.chdir('F:/微信公眾號/Python/0.已發表')
          screen=Screen()
          width ,height=900,700
          screen.setup(width,height)
          screen.title("告白")
          screen.bgcolor("black")
          screen.bgpic(r'./星空下互相告白的兩個人2.gif')
          screen.mode("logo")
          screen.delay(0)
          printer=Turtle()
          printer.hideturtle()
          printer.penup()
          printer.color('red')
          printer.goto(-100,-350)
          printer.write("In the whole universe\n\n",move=True, align="left", font=("Italic", 30, "bold"))
          printer.goto(-50,-400)
          printer.write("YZ I only love you!\n\n",move=True, align="left", font=("Italic", 30, "bold"))
          t=Turtle(visible=False,shape='circle')
          t.pencolor("white")
          t.fillcolor("white")
          t.penup()
          t.setheading(-90)
          t.goto(width/2,randint(-height/2,height/2))
          stars=[]
          for i in range(300):
              star=t.clone()
              s=random()/3
              if  s>0.01 and s<0.03:
                  star.pencolor("black")
                  star.fillcolor("black")
              elif s>0.03 and s<0.04:
                  star.pencolor("lightcoral")
                  star.fillcolor("lightcoral")
              elif s>0.05 and s<0.1:
                  star.pencolor("green")
                  star.fillcolor("green")
              elif s>0.15 and s<0.16:
                  star.pencolor("yellow")
                  star.fillcolor("yellow")
              elif s>0.19 and s<0.2:
                  star.pencolor("red")
                  star.fillcolor("red")
              elif s>0.21 and s<0.22:
                  star.pencolor("purple")
                  star.fillcolor("purple")
              elif s>0.29 and s<0.3:
                  star.pencolor("darkorange")
                  star.fillcolor("darkorange")
              elif s>0.31 and s<0.32:
                  star.pencolor("red")
                  star.fillcolor("yellow")
              elif s>0.32 and s<0.33:
                  star.pencolor("yellow")
                  star.fillcolor("white")
              star.shapesize(s,s)
              star.speed(int(s*30))
              star.setx(width/2 + randint(1,width))
              star.sety( randint(-height/2,height/2))
              #star.showturtle()
              stars.append(star)
          i=0
          pause=False
          while True:
              i +=0
              for star in stars:
                  star.setx(star.xcor() - 3 * star.speed())
                  if star.xcor()<-width/2:
                      star.hideturtle()
                      star.setx(width/2 + randint(1,width))
                      star.sety( randint(-height/2,height/2))
                      star.showturtle()
              if i>=100:
                  break
              
              # 查找隊列事件
              for event in pygame.event.get():
                  # 查找點擊關閉窗口事件
                  if event.type==QUIT:
                      sys.exit
                  # 查找鼠標左右擊事件
                  if event.type==MOUSEBUTTONDOWN:
                      if event.button==1:
                          pause=not pause
                      if event.button==3:
                          pause=not pause
           
                  if event.type==KEYDOWN:
                      if event.key==K_SPACE:
                          pause=not pause
              screen1.fill(bg_rgb)
              if pause:
                  pygame.mixer.music.pause()
                  screen1.blit(pause_image, pause_rect)
              else:
                  pygame.mixer.music.unpause()
                  screen1.blit(play_image, pause_rect)
              pygame.display.flip()
              clock.tick(30)
          

          效果圖

          注:如需源代碼和照片,請在公眾號中回復“520”,即可免費獲取。

          2、照片墻

          #!/usr/bin/env python
          # encoding: utf-8
          from PIL import Image
          import cv2
          import os
          os.chdir(r"F:\微信公眾號\Python\30.520表白\代碼\照片墻\new")
          img=cv2.imread("start.jpg")
          height,width,channels=img.shape
          unit_size=120
          y_index=height//unit_size
          x_index=width//unit_size
          new_img=Image.new('RGB',(width,height),'#FFFFFF')
          pic_list=[]
          for item in os.listdir("small_pictures"):
              if item.endswith(".jpg") or item.endswith(".JPG") :
                  pic_list.append(item)
          total=len(pic_list)
          x=0
          y=0
          for i in range(x_index*y_index):
              print(f"目前進度{i}/{x_index*y_index}")
              test=Image.open("small_pictures/" + pic_list[i%total]).resize((unit_size,unit_size), Image.ANTIALIAS)
              new_img.paste(test,(x*unit_size,y*unit_size))
              x+=1
              if x==x_index:
                  x=0
                  y+=1
          print("素材圖合成完畢!")
          new_img.save("out.jpg",quality=100)
          src1=cv2.imread("start.jpg")
          src2=cv2.imread("out.jpg")
          result=cv2.addWeighted(src1,0.7,src2,0.3,0)
          cv2.imwrite("result.jpg",result)
          

          效果圖


          注:如需照片墻源代碼和照片,請在公眾號中回復“520”,即可免費獲取。

          參考文獻

          https://zhuanlan.zhihu.com/p/77129961https://www.cnblogs.com/ooo888ooo/p/10629205.htmlhttps://www.zhihu.com/question/306127738/answer/558080822?utm_source=wechat_session&utm_medium=social&utm_oi=1090367802518536192



          最后祝大家520、521節日快樂,有情人終成眷屬

          結語

          公眾號『開源Linux』,專注分享Linux/Unix相關內容,包括Linux運維、Linux系統開發、網絡編程、以及虛擬化和云計算等技術干貨。后臺回復『學習』,送你一套學習Linux的系列書籍,期待與你相遇。


          主站蜘蛛池模板: 蜜桃传媒一区二区亚洲AV| 亚洲色无码一区二区三区| 无码一区二区三区免费视频| 亚洲AV无码一区二区三区系列| 冲田杏梨高清无一区二区| 高清一区二区三区视频| 国产一区二区三区免费视频| 国产日韩精品一区二区在线观看播放| 亚洲av乱码中文一区二区三区| 亚洲欧美日韩中文字幕一区二区三区| AA区一区二区三无码精片| 日本一区二区三区免费高清| 精品一区二区久久久久久久网精| 精品人妻无码一区二区三区蜜桃一| 毛片一区二区三区无码| 国产精品视频无圣光一区| 精品一区二区三区无码免费直播| 色综合视频一区二区三区 | 在线|一区二区三区| 日本无卡码免费一区二区三区| 国产成人av一区二区三区不卡 | 无码一区二区三区爆白浆| 无码国产精品久久一区免费| 国产在线视频一区二区三区| 亚洲国产一区二区视频网站| 国产精品无码AV一区二区三区| 免费播放一区二区三区| 手机福利视频一区二区 | 竹菊影视欧美日韩一区二区三区四区五区 | 中文字幕VA一区二区三区| 色婷婷一区二区三区四区成人网 | 伊人色综合视频一区二区三区| 综合一区自拍亚洲综合图区| 无码国产亚洲日韩国精品视频一区二区三区 | 风流老熟女一区二区三区| 国产精华液一区二区区别大吗 | 亚洲一区二区三区在线| 成人免费一区二区三区在线观看| 杨幂AV污网站在线一区二区| 精品一区二区久久久久久久网站| 亚洲日韩AV一区二区三区四区|