成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

HarmonyOS自定義JS組件—代碼情詩

系統 OpenHarmony
人人說程序員很呆板,其實Coder也可以很浪漫,不信?今天就給大家在鴻蒙系統上實現一個代碼情詩。

??想了解更多內容,請訪問:??

??51CTO和華為官方合作共建的鴻蒙技術社區??

??https://harmonyos.51cto.com??

前言

人人說程序員很呆板,其實Coder也可以很浪漫(悶騷),不信?今天就給大家在鴻蒙系統上實現一個代碼情詩。

效果圖

實現思路

我們要實現一個致Alice的情詩,情詩大體分為三個部分,收信人,情詩,寄信人。

  • 收信人:這個簡單,就是兩個text,帶下劃線通過樣式border-bottom實現
  • 情詩:情詩有兩個不規則的背景組成,背景可以通過canvas來繪制封閉的線段,并填充。文本當然也是text了
  • 寄信人:同收信人
  • 動畫:這里使用的是鴻蒙JS的組件動畫,兩個平移,一個縮放。
  • 切換詩歌:首先我們需要一個詩歌集,然后需要一個指針指向當前詩歌,通過更改指針切換詩歌內容。

具體實現

收信人

<div ref='part1' style="flex-direction : row;
margin-start : 50;
margin-top : 30;
margin-bottom : 40;">
<text>{{ To }}</text>
<text class="underlineTxt">{{ Recipients }}</text>
</div>

情詩

<stack ref='part2' style="margin-start : 50; margin-end : 20; background-color : transparent;
align-items : center;
">
<canvas ref="frame1" style="width : 100%;"></canvas>
<text class="poetry">{{ poetry }}</text>
</stack>

<stack ref='part3' style="margin-start : 50; margin-end : 20;
background-color : transparent;
width : {{ frame2_w }};
height : {{ frame2_h }};
margin-top : 10fp;
align-items : center;
">
<canvas ref="frame2" style="width : 100%;"></canvas>
<text class="head">{{ footnote }}</text>
<text class="footer">{{ footnote }}</text>

</stack>

情詩的兩個不規則背景

drawFrame1() {
const frame1 = this.$refs.frame1
let ctx = frame1.getContext('2d')
ctx.beginPath()
ctx.moveTo(0, 0)
ctx.lineTo(this.frame_w, 0)
ctx.lineTo(this.frame_w * 0.9, this.frame_h * 0.5)
ctx.lineTo(this.frame_w, this.frame_h)
ctx.lineTo(0, this.frame_h)
ctx.closePath()
ctx.fillStyle = "#dc3e3f"
ctx.fill();
},
drawFrame2() {
const frame2 = this.$refs.frame2
let ctx = frame2.getContext('2d')
ctx = frame2.getContext('2d')
ctx.beginPath()
ctx.moveTo(0, 0)
ctx.lineTo(this.frame2_w * 0.9, 0)
ctx.lineTo(this.frame2_w, this.frame2_h)
ctx.lineTo(0, this.frame2_h)
ctx.closePath()
ctx.fillStyle = "#dc3e3f"
ctx.fill();
}

注:兩個不規則的背景懂事通過context畫線然后填充。

寄件人

<div ref='part4' style="flex-direction : column; width : 100%; align-items : flex-end;
margin-end : 50; margin-top : 20;">
<div style="flex-direction : row; width : 100%; justify-content : flex-end;
">
<text>{{ From }}</text>
<text class="underlineTxt">{{ name }}</text>
</div>
<div style="flex-direction : row; width : 100%; justify-content : flex-end; margin-top : 20;">
<text>{{ DatePrefix }}</text>
<text class="underlineTxt">{{ date }}</text>
</div>
</div>

動畫

   showPart1() {
let options = {
duration: 2000,
delay: 0
};
let keyframes = [
{
transform: {
translate: '-400px 0px',
},
},
{
transform: {
translate: '0px 0px',
},
}
]
let animation = this.$refs.part1.animate(keyframes, options);
animation.play();
},

注:這里只是提供了第一個部分的動畫,其他部分類似,故不贅述。

切換詩歌

詩歌的集合:

const poetries = [
` function newTime(effort) {
if (effort == true)
return success
}
`,

` While (timeleft()>0)
If(canmove()==true)
Printf ("Protect you" )
`,
...
]

當前顯示的詩歌pointer和文本

export default {
data: {
pointer: 0,
poetry: poetries[0],

切換方法

 prePeotry() {
this.pointer = Math.max(this.pointer-1, 0);
console.log('this.pointer:'+this.pointer)
this.poetry = poetries[this.pointer]
this.draw()
},

注:這里我們隊pointer進行移位,然后更改poetry,重繪當前界面。

??想了解更多內容,請訪問:??

??51CTO和華為官方合作共建的鴻蒙技術社區??

??https://harmonyos.51cto.com??

責任編輯:jianghua 來源: 鴻蒙社區
相關推薦

2021-11-01 10:21:36

鴻蒙HarmonyOS應用

2021-09-15 10:19:15

鴻蒙HarmonyOS應用

2022-10-26 15:54:46

canvas組件鴻蒙

2022-10-25 15:12:24

自定義組件鴻蒙

2022-07-06 20:24:08

ArkUI計時組件

2022-02-16 15:25:31

JS代碼Canvas鴻蒙

2022-02-16 16:09:12

鴻蒙游戲操作系統

2022-05-20 14:34:20

list組件鴻蒙操作系統

2022-04-24 15:17:56

鴻蒙操作系統

2021-02-20 12:34:53

鴻蒙HarmonyOS應用開發

2021-11-24 10:02:53

鴻蒙HarmonyOS應用

2023-02-20 15:20:43

啟動頁組件鴻蒙

2021-03-09 15:23:45

鴻蒙HarmonyOS應用開發

2022-06-20 15:43:45

switch開關鴻蒙

2021-12-21 15:22:22

鴻蒙HarmonyOS應用

2022-06-30 14:02:07

鴻蒙開發消息彈窗組件

2022-07-15 16:45:35

slider滑塊組件鴻蒙

2022-05-23 10:53:54

canvas柱狀圖鴻蒙

2009-06-24 15:13:36

自定義JSF組件

2021-11-22 10:00:33

鴻蒙HarmonyOS應用
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 欧美日韩精选 | 精品一区久久 | 欧美成人一区二区三区 | 国产乱人伦 | 黄色一级电影在线观看 | 999久久久国产精品 欧美成人h版在线观看 | 色婷婷一区二区三区四区 | 少妇诱惑av | 成人精品一区 | 九九九视频 | 韩日精品在线观看 | 91久久久久久久久久久 | 免费在线观看黄视频 | 成人国产精品免费观看 | 日韩精彩视频 | 成人做爰9片免费看网站 | 成在线人视频免费视频 | 成人免费视频观看 | 福利久久 | 天天操精品视频 | 国产精品视频网 | 国产精品毛片一区二区三区 | 日韩在线不卡视频 | 精品视频一区二区三区 | 懂色av色香蕉一区二区蜜桃 | 国产一二区视频 | 亚洲国产视频一区二区 | 91免费在线视频 | 欧美精品成人一区二区三区四区 | 天天操综合网站 | 国产精品国产精品国产专区不片 | 国产精品欧美一区二区三区 | 欧美成人精品一区 | 日韩男人天堂 | 欧美性一区二区三区 | 国产成人亚洲精品自产在线 | 懂色中文一区二区三区在线视频 | av电影一区二区 | 欧美久久久 | 我想看一级黄色毛片 | 午夜小视频在线播放 |