-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
317 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<template> | ||
<div class="nice-particle"> | ||
<canvas id="niceCanvas" class="nice-canvas"></canvas> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import $device from '@system.device' | ||
import $app from '@system.app' | ||
const appInfo = $app.getInfo() | ||
|
||
export default { | ||
// 页面级组件的数据模型,影响传入数据的覆盖机制:private内定义的属性不允许被覆盖 | ||
private: { | ||
}, | ||
|
||
public: { | ||
title: appInfo.name, | ||
icon: appInfo.icon, | ||
mCanvas: null, | ||
mContext: null, | ||
mParticleNum: 20, | ||
mParticleIndex: 0, | ||
mParticles: {}, | ||
mWidth: 800, | ||
mHeight: 300 | ||
}, | ||
|
||
onInit () { | ||
}, | ||
|
||
onReady () { | ||
setTimeout(() => { | ||
this.startNiceDraw() | ||
}, 1000) | ||
}, | ||
|
||
onShow () { | ||
}, | ||
|
||
createParticle () { | ||
const that = {} | ||
that.posX = this.mWidth / 2; // position X | ||
that.posY = this.mHeight / 8; // position Y | ||
that.vx = Math.random() * 10 - 5; // velocity X | ||
that.vy = Math.random() * 10 - 5; // velocity Y | ||
that.width = 1; // particle width | ||
that.height = Math.random() * 6 - 3; // particle height | ||
|
||
this.mParticleIndex++ | ||
this.mParticles[this.mParticleIndex] = that | ||
that.id = this.mParticleIndex | ||
|
||
that.life = 0; | ||
that.death = 140; | ||
|
||
// random color | ||
that.colors = [ | ||
"rgba(100, 100, 100," + (Math.random() + .5) + ")", | ||
"rgba(52, 152, 200," + (Math.random() + .5) + ")", | ||
"rgba(41, 128, 250," + (Math.random() + .5) + ")"]; | ||
that.color = that.colors[Math.floor(Math.random() * 3)]; | ||
}, | ||
|
||
drawParticleCanvas(target) { | ||
const gravity = 0.7 | ||
target.posX += target.vx; | ||
target.posY += target.vy; | ||
|
||
target.life++; | ||
|
||
if (target.life >= target.death) { | ||
delete this.mParticles[target.id]; | ||
} | ||
if (target.posY > (this.mCanvas.height - 5)) { | ||
target.vx *= 0.8; | ||
target.vy *= -0.5; | ||
target.posY = (this.mCanvas.height - 5); | ||
} | ||
|
||
target.vy += gravity; | ||
|
||
this.mContext.fillStyle = target.color; | ||
this.mContext.fillRect(target.posX, target.posY, target.width, target.height); | ||
}, | ||
|
||
startNiceDraw() { | ||
this.mCanvas = this.$element('niceCanvas') | ||
this.mContext = this.mCanvas.getContext("2d") | ||
// this.mCanvas.width = $device.screenWidth || 800 | ||
// this.mCanvas.height = $device.screenHeight || 300 | ||
this.mContext.fillRect(0, 0, this.mWidth, this.mHeight); | ||
setInterval(() => { | ||
this.mContext.fillStyle = "rgba(0, 0, 0, 0.8)"; | ||
this.mContext.fillRect(0, 0, this.mWidth, this.mHeight); | ||
|
||
for(let i = 0; i < this.mParticleNum; i++){ | ||
this.createParticle() | ||
} | ||
|
||
for(let i in this.mParticles){ | ||
this.drawParticleCanvas(this.mParticles[i]) | ||
} | ||
}, 1000) | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="less"> | ||
@import './../assets/styles/style.less'; | ||
.nice-particle { | ||
.flex-box-mixins(column, center, center); | ||
width: 100%; | ||
height: 300px; | ||
background-color: rgba(0,0,0,0.4); | ||
.nice-canvas { | ||
width: 100%; | ||
height: 300px; | ||
/* background-color: rgba(0,222,0,0.4); */ | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<template> | ||
<div class="nice-particle"> | ||
<canvas id="waterCanvas" class="water-canvas"></canvas> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { $util } from './../helper' | ||
let tim, bai, a, b, c, s, p, r, x, y, z, x1, y1, max, p2, han, h, pt, hei; | ||
const colorRandomList = [ | ||
[87, 209, 201, 0.3], | ||
[221, 10, 53, 0.3], | ||
[66, 33, 142, 0.3], | ||
[43, 187, 216, 0.3], | ||
[92,242,232, 0.3], | ||
[135,226,147, 0.3], | ||
[0, 255, 0, 0.3], | ||
[255, 0, 0, 0.3], | ||
[245, 223, 101, 0.3], | ||
[17, 141, 240, 0.3], | ||
[31, 138, 255, 0.3] | ||
] | ||
export default { | ||
// 页面级组件的数据模型,影响传入数据的覆盖机制:private内定义的属性不允许被覆盖; | ||
protected: { | ||
mCanvas: null, | ||
mContext: null, | ||
mWidth: 800, | ||
mHeight: 300, | ||
randomIndex: 0 | ||
}, | ||
|
||
onInit () { | ||
this.randomIndex = $util.getRandomInt(0, 10) | ||
}, | ||
|
||
onReady () { | ||
setTimeout(() => { | ||
this.startNiceDraw() | ||
}, 10) | ||
}, | ||
|
||
onShow () { | ||
}, | ||
|
||
startNiceDraw () { | ||
this.mCanvas = this.$element('waterCanvas') | ||
this.mContext =this.mCanvas.getContext('2d'); | ||
this.mCanvas.width = 800; | ||
this.mCanvas.height = 400; | ||
setInterval(() => { | ||
this.drawParticleCanvas() | ||
}, 60) | ||
}, | ||
|
||
drawParticleCanvas() { | ||
this.mContext.globalCompositeOperation = "source-over"; | ||
this.mContext.fillStyle = "rgb(0, 0, 0)"; | ||
this.mContext.fillRect(0, 0, this.mCanvas.width, this.mCanvas.height); | ||
this.mContext.globalCompositeOperation = "lighter"; | ||
tim = new Date().getTime() / 10; | ||
const colorStr = colorRandomList[this.randomIndex].join(',') | ||
this.mContext.strokeStyle = this.mContext.fillStyle = `hsla(${colorStr})`; | ||
|
||
bai = 0.6 + Math.sin(tim / 5) * 0.2; | ||
hei = 0.9 + Math.sin(tim / 100) * 0.3; | ||
|
||
pt = []; | ||
for (c = 0; c < 180; c++) { | ||
s = (c + 1) / 180; | ||
han = Math.cos(s * Math.PI / 2); | ||
h = Math.sin(s * Math.PI / 2); | ||
s = 1 - s; | ||
p = []; | ||
max = (100 * han) | 0; | ||
r = 0; | ||
for (a = 0; a < max; a++) { | ||
x = Math.cos(r) * han; | ||
y = Math.sin(r) * han; | ||
z = this.nami(r, s); | ||
x -= z * s; | ||
p.push([x, y, hei + z * s + h]); | ||
r += Math.PI * 2 / max; | ||
} | ||
pt.push(p); | ||
} | ||
for (c = 0; c < 100; c++) { | ||
s = (c + 1) / 100; | ||
p = []; | ||
max = 100 * s; | ||
r = 0; | ||
for (a = 0; a < max; a++) { | ||
x = Math.cos(r) * s; | ||
y = Math.sin(r) * s; | ||
z = this.nami(r, s); | ||
x -= z * s; | ||
p.push([x, y, hei + z * s]); | ||
r += Math.PI * 2 / max; | ||
} | ||
pt.push(p); | ||
} | ||
for (c = 0; c < pt.length; c++) { | ||
p = pt[c]; | ||
p2 = []; | ||
for (a = 0; a < p.length; a++) { | ||
x = p[a][0]; | ||
y = p[a][1]; | ||
z = p[a][2]; | ||
b = Math.pow(1.5, y / 2); | ||
x1 = x * b * 150 + 200; | ||
y1 = z * b * 200 - hei * 200 + 150; | ||
p2.push([x1, y1]); | ||
} | ||
this.mContext.beginPath(); | ||
for (a = 0; a < p2.length; a++) this.mContext.lineTo(p2[a][0], p2[a][1]); | ||
this.mContext.closePath(); | ||
this.mContext.stroke(); | ||
} | ||
// requestAnimationFrame(this.drawParticleCanvas) | ||
}, | ||
nami(r, s) { | ||
var a = Math.sin(r * 2 - tim / 13 + s * 13) / 20 + Math.sin(r * 5 - tim / 17 + s * 13) / 20 + Math.sin(r * 7 - tim / 19 + s * 13) / 40; | ||
return a * bai; | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="less"> | ||
@import './../assets/styles/style.less'; | ||
.nice-particle { | ||
.flex-box-mixins(column, center, center); | ||
width: 100%; | ||
height: 369px; | ||
background-color: @black; | ||
.water-canvas { | ||
background-color: @black; | ||
width: 400px; | ||
height: 369px; | ||
} | ||
} | ||
</style> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.