自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

今天來(lái)復(fù)刻一顆會(huì)呼吸的心

系統(tǒng) OpenHarmony
分析原劇要素,首先是一個(gè)愛(ài)心的輪廓,愛(ài)心內(nèi)外有許多隨機(jī)分布的點(diǎn),且心的內(nèi)部擴(kuò)張程度要大于外側(cè)擴(kuò)張程度,所以才有呼吸的效果。但顯然原劇中的愛(ài)心應(yīng)該不是單單依靠代碼實(shí)現(xiàn)。

??想了解更多關(guān)于開(kāi)源的內(nèi)容,請(qǐng)?jiān)L問(wèn):??

??51CTO 開(kāi)源基礎(chǔ)軟件社區(qū)??

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

今天來(lái)復(fù)刻一個(gè)會(huì)呼吸的心,在前些陣子電視劇《燃燒我,溫暖你》中一顆會(huì)呼吸的心引起了眾多開(kāi)發(fā)者的復(fù)刻…

一、效果

原劇中

#盲盒+碼# 【FFH】一顆會(huì)呼吸的心-開(kāi)源基礎(chǔ)軟件社區(qū)


復(fù)刻效果

#盲盒+碼# 【FFH】一顆會(huì)呼吸的心-開(kāi)源基礎(chǔ)軟件社區(qū)

二、逆向工程

分析原劇要素,首先是一個(gè)愛(ài)心的輪廓,愛(ài)心內(nèi)外有許多隨機(jī)分布的點(diǎn),且心的內(nèi)部擴(kuò)張程度要大于外側(cè)擴(kuò)張程度,所以才有呼吸的效果。但顯然原劇中的愛(ài)心應(yīng)該不是單單依靠代碼實(shí)現(xiàn)。
我們完成一下要素即可:

  • 最外層的愛(ài)心輪廓。
  • 輪廓周圍隨機(jī)分布的點(diǎn)。
  • 內(nèi)層跳動(dòng)大于外層。
    要想內(nèi)外擴(kuò)張程度不一樣的話,我們可能需要用到兩個(gè)畫布實(shí)例,為他們添加動(dòng)畫,并且內(nèi)部擴(kuò)大程度大于外側(cè)畫布。

三、代碼實(shí)現(xiàn)

  • javascript
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
},
onShow(){
this.heart();
this.heart2();
},
heart(){
const cvs = this.$refs.canvas;
const ctx = cvs.getContext('2d');
const width=1080;
const height=1080;
//計(jì)算弧度
let radian = 0
let radian_add = Math.PI / 180
//調(diào)整位置
ctx.translate(width / 3, height / 2)
//陰影
ctx.shadowBlur = 10
//拐彎角圓滑
ctx.lineJoin = 'round'
//顏色
ctx.shadowColor = 'rgba(255, 255, 255, 1.00)'
ctx.strokeStyle = 'rgba(255, 0, 114, 1.00)'
//兩個(gè)點(diǎn)矩陣,都是用來(lái)畫愛(ài)心,一個(gè)大一點(diǎn)一個(gè)小一點(diǎn)增加層次
const points = []
const mpoints=[]
while (radian <= Math.PI * 2) {
radian += radian_add
//(x,y)表示愛(ài)心坐標(biāo),16的愛(ài)心大一點(diǎn)
let x = this.getX(radian,16)
let y = this.getY(radian,16)
points.push({
x,
y,
//隨機(jī)分布
list: new Array(10).fill('').map(v => {
const fw = 100
const fx = x + Math.random() * fw - fw / 2
const fy = y + Math.random() * fw - fw / 2
return {
x: x,
y: y,
endX: fx,
endY: fy,
stepX: x > fx ? -1 : 1,
stepY: y > fy ? -1 : 1,
parentX: x,
parentY: y
}
})
})
//再存一個(gè)小一點(diǎn)的愛(ài)心
x = this.getX(radian,14)
y = this.getY(radian,14)
// ctx.lineTo(x, y)
mpoints.push({
x,
y,
list: new Array(10).fill('').map(v => {
const fw = 100
const fx = x + Math.random() * fw - fw / 2
const fy = y + Math.random() * fw - fw / 2
return {
x: x,
y: y,
endX: fx,
endY: fy,
stepX: x > fx ? -1 : 1,
stepY: y > fy ? -1 : 1,
parentX: x,
parentY: y
}
})
})
}
const render = () => {
ctx.beginPath()
ctx.clearRect(-width/2, -height/2, width, height)
//設(shè)置粗細(xì)
ctx.lineWidth = 1
//繪制
mpoints.forEach(v => {
v.list.forEach(k => {
ctx.moveTo(k.x, k.y)
ctx.lineTo(k.x + ctx.lineWidth, k.y + ctx.lineWidth)
k.x += k.stepX
k.y += k.stepY
if (k.stepX > 0) {
if (k.x > k.endX) {
k.x = k.endX
}
} else {
if (k.x < k.endX) {
k.x = k.endX
}
}
if (k.stepY > 0) {
if (k.y > k.endY) {
k.y = k.endY
}
} else {
if (k.y < k.endY) {
k.y = k.endY
}
}
if (k.x === k.endX && k.y === k.endY) {
k.x = k.parentX
k.y = k.parentY
}
})
})
ctx.stroke()
ctx.beginPath()
ctx.lineWidth = 2
//繪制
points.forEach(v => {
v.list.forEach(k => {
ctx.moveTo(k.x, k.y)
ctx.lineTo(k.x + ctx.lineWidth, k.y + ctx.lineWidth)
k.x += k.stepX
k.y += k.stepY
if (k.stepX > 0) {
if (k.x > k.endX) {
k.x = k.endX
}
} else {
if (k.x < k.endX) {
k.x = k.endX
}
}
if (k.stepY > 0) {
if (k.y > k.endY) {
k.y = k.endY
}
} else {
if (k.y < k.endY) {
k.y = k.endY
}
}
if (k.x === k.endX && k.y === k.endY) {
k.x = k.parentX
k.y = k.parentY
}
})
})
ctx.stroke()
ctx.lineWidth = 2
points.forEach(k => {
v=>{
ctx.lineTo(v.x,v.y)
}
})
ctx.stroke()
requestAnimationFrame(render)}
render()
},
//依據(jù)愛(ài)心方程繪制
getX(t,w) {
return w * (12 * Math.sin(t) - 4 * Math.sin(3 * t))
},
getY(t, w,bl = 1) {
return (
-w *
(13 * Math.cos(t) -
5 * Math.cos(2 * t) -
2 * Math.cos(3 * t) -
Math.cos(4 * t))
)
},
heart2(){
//代碼類似,但是是基于第二個(gè)畫布,愛(ài)心更小一點(diǎn),為了制作出呼吸的效果
}

}
  • css
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
background-color: black;
}
.my_canvas{
animation: run infinite 1s linear;
width: 100%;
height: 100%;
background-color: black;
}
.my_canvs2{
position: absolute;
width: 100%;
height: 100%;
z-index: 10;
animation: run2 infinite 1s linear;
}
@keyframes {
0% {
transform: scale(1);
}
50% {
transform: scale(1.05);
}
100% {
transform: scale(1);
}
}
@keyframes {
0% {
transform: scale(1);
}
50% {
transform: scale(1.2);
}
100% {
transform: scale(1);
}
}
  • hml
<div class="container">

<canvas class="my_canvas" ref="canvas">

</canvas>
<canvas class="my_canvs2" ref="canvas2">

</canvas>
</div>

??想了解更多關(guān)于開(kāi)源的內(nèi)容,請(qǐng)?jiān)L問(wèn):??

??51CTO 開(kāi)源基礎(chǔ)軟件社區(qū)??

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

責(zé)任編輯:jianghua 來(lái)源: 51CTO 開(kāi)源基礎(chǔ)軟件社區(qū)
相關(guān)推薦

2014-07-30 16:19:13

敏捷華為

2017-02-23 10:50:32

Python微博數(shù)據(jù)

2017-02-24 19:32:39

微博數(shù)據(jù)Python

2015-05-18 16:12:32

信息化轉(zhuǎn)型油氣行業(yè)華為

2020-06-30 15:38:17

戴爾

2009-06-10 18:15:36

電腦下鄉(xiāng)家電下鄉(xiāng)

2013-09-29 11:08:10

Bay Trail平板電腦

2013-04-16 13:57:36

2021-03-15 14:17:38

射頻芯片5G手機(jī)信號(hào)

2015-11-20 17:30:34

天翼

2010-07-30 15:58:18

2022-08-26 12:13:40

黑客網(wǎng)絡(luò)攻擊

2015-01-12 11:07:22

2021-08-13 08:19:31

狀態(tài)機(jī)設(shè)計(jì)模式

2016-09-24 23:21:57

2021-05-12 19:19:44

字典樹(shù)數(shù)據(jù)結(jié)構(gòu)

2009-04-21 18:04:04

雙核Nehalemintel

2024-06-11 08:32:37

JavaScrip隨機(jī)樹(shù)UI

2021-06-30 13:20:05

Windows 11芯片PC

2021-01-21 21:14:53

人工智能AIOpenAI
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)