<address id="ttjl9"></address>

      <noframes id="ttjl9"><address id="ttjl9"><nobr id="ttjl9"></nobr></address>
      <form id="ttjl9"></form>
        <em id="ttjl9"><span id="ttjl9"></span></em>
        <address id="ttjl9"></address>

          <noframes id="ttjl9"><form id="ttjl9"></form>

          代碼寫春聯【js+html版本與python版本】

          2022-1-24    前端達人

          文章來源:人人都是產品經理   作者:新榜

          分享此文一切功德,皆悉回向給文章原作者及眾讀者.

          免責聲明:藍藍設計尊重原作者,文章的版權歸原作者。如涉及版權問題,請及時與我們取得聯系,我們立即更正或刪除。

          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服務

          一、春聯一

          1.前言

          需要代碼文末公眾號找我 回復【春聯】即可獲取
          在這里插入圖片描述

          效果展示

          在這里插入圖片描述

          3.代碼展示

          index.html

          <!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <title>css3春聯切換</title> <link rel="stylesheet" href="css/style.css"> </head> <body> <div class="rotating-text"> <p>春聯Show</p> <p> <span class="word alizarin">上聯:這個需求很簡單</span> <span class="word wisteria">下聯:怎么實現我不管</span> <span class="word peter-river">橫批:明天上線!</span> </p> </div> <script src="js/script.js"></script> </body> </html>  
          
          • 1
          • 2
          • 3
          • 4
          • 5
          • 6
          • 7
          • 8
          • 9
          • 10
          • 11
          • 12
          • 13
          • 14
          • 15
          • 16
          • 17
          • 18
          • 19
          • 20
          • 21
          • 22
          • 23
          • 24

          style.css

          @import url(https://fonts.googleapis.com/css?family=Lato:600); body { display: flex; justify-content: center; align-items: center; height: 100vh; background: #222; } .rotating-text { font-family: Lato, sans-serif; font-weight: 600; font-size: 36px; color: white; transform: translateX(-80px); } .rotating-text p { display: inline-flex; margin: 0; vertical-align: top; } .rotating-text p .word { position: absolute; display: flex; opacity: 0; } .rotating-text p .word .letter { transform-origin: center center 25px; } .rotating-text p .word .letter.out { transform: rotateX(90deg); transition: 0.32s cubic-bezier(0.6, 0, 0.7, 0.2); } .rotating-text p .word .letter.in { transition: 0.38s ease; } .rotating-text p .word .letter.behind { transform: rotateX(-90deg); } .alizarin { color: #e74c3c; } .wisteria { color: #8e44ad; } .peter-river { color: #3498db; } .emerald { color: #2ecc71; } .sun-flower { color: #f1c40f; }  
          
          • 1
          • 2
          • 3
          • 4
          • 5
          • 6
          • 7
          • 8
          • 9
          • 10
          • 11
          • 12
          • 13
          • 14
          • 15
          • 16
          • 17
          • 18
          • 19
          • 20
          • 21
          • 22
          • 23
          • 24
          • 25
          • 26
          • 27
          • 28
          • 29
          • 30
          • 31
          • 32
          • 33
          • 34
          • 35
          • 36
          • 37
          • 38
          • 39
          • 40
          • 41
          • 42
          • 43
          • 44
          • 45
          • 46
          • 47
          • 48
          • 49
          • 50
          • 51
          • 52
          • 53
          • 54
          • 55
          • 56
          • 57
          • 58
          • 59

          script.js

          var words = document.querySelectorAll(".word"); words.forEach(function (word) { var letters = word.textContent.split(""); word.textContent = ""; letters.forEach(function (letter) { var span = document.createElement("span"); span.textContent = letter; span.className = "letter"; word.append(span); }); }); var currentWordIndex = 0; var maxWordIndex = words.length - 1; words[currentWordIndex].style.opacity = "1"; var rotateText = function () { var currentWord = words[currentWordIndex]; var nextWord = currentWordIndex === maxWordIndex ? words[0] : words[currentWordIndex + 1]; // rotate out letters of current word Array.from(currentWord.children).forEach(function (letter, i) { setTimeout(function () { letter.className = "letter out"; }, i * 80); }); // reveal and rotate in letters of next word nextWord.style.opacity = "1"; Array.from(nextWord.children).forEach(function (letter, i) { letter.className = "letter behind"; setTimeout(function () { letter.className = "letter in"; }, 340 + i * 80); }); currentWordIndex = currentWordIndex === maxWordIndex ? 0 : currentWordIndex + 1; }; rotateText(); setInterval(rotateText, 4000);  
          
          • 1
          • 2
          • 3
          • 4
          • 5
          • 6
          • 7
          • 8
          • 9
          • 10
          • 11
          • 12
          • 13
          • 14
          • 15
          • 16
          • 17
          • 18
          • 19
          • 20
          • 21
          • 22
          • 23
          • 24
          • 25
          • 26
          • 27
          • 28
          • 29
          • 30
          • 31
          • 32
          • 33
          • 34
          • 35
          • 36

          二、春聯二

          1.環境準備

          1.當缺少庫時會有相應提示 黑窗口執行下方命令+包名即可下載安裝
          2.博主此處用的idea 直接Alt+Enter直接下載就成了
          3.idea配置python環境也可以參考此文:Python(含PyCharm及配置)下載安裝以及簡單使用(Idea)

          2.效果展示

          在這里插入圖片描述
          在這里插入圖片描述

          3.代碼

          import io from PIL import Image #import numpy as np import requests def get_word(ch, quality): """獲取單個漢字(字符)的圖片
              ch          - 單個漢字或英文字母(僅支持大寫)
              quality     - 單字分辨率,H-640像素,M-480像素,L-320像素
              """ fp = io.BytesIO(requests.post(url='http://xufive.sdysit.com/tk', data={'ch': ch}).content) im = Image.open(fp) w, h = im.size if quality == 'M': w, h = int(w * 0.75), int(0.75 * h) elif quality == 'L': w, h = int(w * 0.5), int(0.5 * h) return im.resize((w, h)) def get_bg(quality): """獲取春聯背景的圖片""" return get_word('bg', quality) def write_couplets(text, HorV='V', quality='L', out_file=None): """生成春聯
          
              text        - 春聯內容,以空格斷行
              HorV        - H-橫排,V-豎排
              quality     - 單字分辨率,H-640像素,M-480像素,L-320像素
              out_file    - 輸出文件名
              """ usize = {'H': (640, 23), 'M': (480, 18), 'L': (320, 12)} bg_im = get_bg(quality) text_list = [list(item) for item in text.split()] rows = len(text_list) cols = max([len(item) for item in text_list]) if HorV == 'V': ow, oh = 40 + rows * usize[quality][0] + (rows - 1) * 10, 40 + cols * usize[quality][0] else: ow, oh = 40 + cols * usize[quality][0], 40 + rows * usize[quality][0] + (rows - 1) * 10 out_im = Image.new('RGBA', (ow, oh), '#f0f0f0') for row in range(rows): if HorV == 'V': row_im = Image.new('RGBA', (usize[quality][0], cols * usize[quality][0]), 'white') offset = (ow - (usize[quality][0] + 10) * (row + 1) - 10, 20) else: row_im = Image.new('RGBA', (cols * usize[quality][0], usize[quality][0]), 'white') offset = (20, 20 + (usize[quality][0] + 10) * row) for col, ch in enumerate(text_list[row]): if HorV == 'V': pos = (0, col * usize[quality][0]) else: pos = (col * usize[quality][0], 0) ch_im = get_word(ch, quality) row_im.paste(bg_im, pos) row_im.paste(ch_im, (pos[0] + usize[quality][1], pos[1] + usize[quality][1]), mask=ch_im) out_im.paste(row_im, offset) if out_file: out_im.convert('RGB').save(out_file) out_im.show() text = '思前想后幾行代碼筑萬載春秋 扶內保外一千精英帶五千干將' #對聯內容 write_couplets(text, HorV='V', quality='M', out_file='春聯.jpg') #生成普天同慶.jpg對聯圖片  
                      
          • 1
          • 2
          • 3
          • 4
          • 5
          • 6
          • 7
          • 8
          • 9
          • 10
          • 11
          • 12
          • 13
          • 14
          • 15
          • 16
          • 17
          • 18
          • 19
          • 20
          • 21
          • 22
          • 23
          • 24
          • 25
          • 26
          • 27
          • 28
          • 29
          • 30
          • 31
          • 32
          • 33
          • 34
          • 35
          • 36
          • 37
          • 38
          • 39
          • 40
          • 41
          • 42
          • 43
          • 44
          • 45
          • 46
          • 47
          • 48
          • 49
          • 50
          • 51
          • 52
          • 53
          • 54
          • 55
          • 56
          • 57
          • 58
          • 59
          • 60
          • 61
          • 62
          • 63
          • 64
          • 65
          • 66
          • 67
          • 68
          • 69
          • 70
          • 71
          • 72
          • 73
          • 74
          白哥Java
          微信公眾號
          獲取Java面試資料/簡歷模板/項目資料
          3.代碼

          import io from PIL import Image #import numpy as np import requests def get_word(ch, quality): """獲取單個漢字(字符)的圖片 ch - 單個漢字或英文字母(僅支持大寫) quality - 單字分辨率,H-640像素,M-480像素,L-320像素 """ fp = io.BytesIO(requests.post(url='http://xufive.sdysit.com/tk', data={'ch': ch}).content) im = Image.open(fp) w, h = im.size if quality == 'M': w, h = int(w * 0.75), int(0.75 * h) elif quality == 'L': w, h = int(w * 0.5), int(0.5 * h) return im.resize((w, h)) def get_bg(quality): """獲取春聯背景的圖片""" return get_word('bg', quality) def write_couplets(text, HorV='V', quality='L', out_file=None): """生成春聯 text - 春聯內容,以空格斷行 HorV - H-橫排,V-豎排 quality - 單字分辨率,H-640像素,M-480像素,L-320像素 out_file - 輸出文件名 """ usize = {'H': (640, 23), 'M': (480, 18), 'L': (320, 12)} bg_im = get_bg(quality) text_list = [list(item) for item in text.split()] rows = len(text_list) cols = max([len(item) for item in text_list]) if HorV == 'V': ow, oh = 40 + rows * usize[quality][0] + (rows - 1) * 10, 40 + cols * usize[quality][0] else: ow, oh = 40 + cols * usize[quality][0], 40 + rows * usize[quality][0] + (rows - 1) * 10 out_im = Image.new('RGBA', (ow, oh), '#f0f0f0') for row in range(rows): if HorV == 'V': row_im = Image.new('RGBA', (usize[quality][0], cols * usize[quality][0]), 'white') offset = (ow - (usize[quality][0] + 10) * (row + 1) - 10, 20) else: row_im = Image.new('RGBA', (cols * usize[quality][0], usize[quality][0]), 'white') offset = (20, 20 + (usize[quality][0] + 10) * row) for col, ch in enumerate(text_list[row]): if HorV == 'V': pos = (0, col * usize[quality][0]) else: pos = (col * usize[quality][0], 0) ch_im = get_word(ch, quality) row_im.paste(bg_im, pos) row_im.paste(ch_im, (pos[0] + usize[quality][1], pos[1] + usize[quality][1]), mask=ch_im) out_im.paste(row_im, offset) if out_file: out_im.convert('RGB').save(out_file) out_im.show() text = '思前想后幾行代碼筑萬載春秋 扶內保外一千精英帶五千干將' #對聯內容 write_couplets(text, HorV='V', quality='M', out_file='春聯.jpg') #生成普天同慶.jpg對聯圖片
           
          


          11

          222

          文章來源:csdn  作者: 分享此文一切功德,皆悉回向給文章原作者及眾讀者.
          免責聲明:藍藍設計尊重原作者,文章的版權歸原作者。如涉及版權問題,請及時與我們取得聯系,我們立即更正或刪除。
          藍藍設計( www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服務

          日歷

          鏈接

          個人資料

          藍藍設計的小編 http://www.syprn.cn

          存檔

          亚洲va欧美va天堂v国产综合