SimplexNoise模仿siri听你说话的声纹动画波动效果
代码语言:html
所属分类:动画
代码描述:SimplexNoise模仿siri听你说话的声纹动画波动效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> html, body { overflow: hidden; } body { position: relative; background: #000; color: #fff; font-size: 2rem; line-height: 1.5; } a { text-decoration: none; color: #fff; } #mes1, #mes2 { padding: 1.6rem; position: absolute; opacity: 0; } .siri { -webkit-animation-name: fadeIn; animation-name: fadeIn; -webkit-animation-duration: 4s; animation-duration: 4s; -webkit-animation-iteration-count: 1; animation-iteration-count: 1; -webkit-animation-fill-mode: backwards; animation-fill-mode: backwards; } @-webkit-keyframes fadeIn { 0% { opacity: 0; -webkit-transform: translateY(100px); transform: translateY(100px); } 30% { opacity: 1; -webkit-transform: translateY(0); transform: translateY(0); } 80% { opacity: 1; -webkit-transform: translateY(0); transform: translateY(0); } 100% { opacity: 0; -webkit-transform: translateY(-100px); transform: translateY(-100px); } } @keyframes fadeIn { 0% { opacity: 0; -webkit-transform: translateY(100px); transform: translateY(100px); } 30% { opacity: 1; -webkit-transform: translateY(0); transform: translateY(0); } 80% { opacity: 1; -webkit-transform: translateY(0); transform: translateY(0); } 100% { opacity: 0; -webkit-transform: translateY(-100px); transform: translateY(-100px); } } #list { padding: 1.6rem; max-height: 60%; opacity: 0; display: none; position: absolute; overflow: scroll; } .slideUp { opacity: 1; -webkit-animation-name: slideUp; animation-name: slideUp; -webkit-animation-duration: 1s; animation-duration: 1s; -webkit-animation-iteration-count: 1; animation-iteration-count: 1; -webkit-animation-fill-mode: forwards; animation-fill-mode: forwards; } @-webkit-keyframes slideUp { 0% { -webkit-transform: translateY(100px); transform: translateY(100px); } 100% { -webkit-transform: translate(0); transform: translate(0); } } @keyframes slideUp { 0% { -webkit-transform: translateY(100px); transform: translateY(100px); } 100% { -webkit-transform: translate(0); transform: translate(0); } } ul { margin: 1.6rem 0; } ul li { list-style-type: disc; list-style-position: inside; } ul li a { font-size: 1.2rem; } </style> </head> <body translate="no" > <div id="mes1" class="siri"> <p>What can I help you with?</p> </div> <div id="mes2"> <p>Go ahead, I'm listening...</p> </div> <div id="list"> <p>Some things you can ask me.</p> <ul> </ul> </div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/simplex-noise.min.js"></script> <script> /* * File Name / heySiri.js * Created Date / Sep 17, 2020 * Aurhor / Toshiya Marukubo * Twitter / https://twitter.com/toshiyamarukubo */ /* Common Tool. */ class Tool { // random number. static randomNumber(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } // random color rgb. static randomColorRGB() { return ( "rgb(" + this.randomNumber(0, 255) + ", " + this.randomNumber(0, 255) + ", " + this.randomNumber(0, 255) + ")"); } // random color hsl. static randomColorHSL(hue, saturation, lightness) { return ( "hsl(" + hue + ", " + saturation + "%, " + lightness + "%)"); } // gradient color. static gradientColor(ctx, cr, cg, cb, ca, x, y, r) { const col = cr + "," + cg + "," + cb; const g = ctx.createRadialGradient(x, y, 0, x, y, r); g.addColorStop(0, "rgba(" + col + ", " + ca * 1 + ")"); g.addColorStop(0.5, "rgba(" + col + ", " + ca * 0.5 + ")"); g.addColorStop(1, "rgba(" + col + ", " + ca * 0 + ")"); return g; }} /* When want to use angle. */ class Angle { constructor(angle) { this.a = angle; this.rad = this.a * Math.PI / 180; } incDec(num) { this.a += num; this.rad = this.a * Math.PI / 180; return this.rad; }} /* When want to use controller. */ class Controller { constructor(id) { this.id = document.getElementById(id); } getVal() { return this.id.value; }} /* When want to use time. */ class Time { constructor(time) { this.startTime = time; this.lastTime; this.elapsedTime; } getElapsedTime() { this.lastTime = Date.now(); this.elapsedTime = (this.startTime - this.lastTime) * -1; return this.elapsedTime; }} /* When want to use time. */ let canvas; const simplex = new SimplexNoise(); class Canvas { constructor(bool) { // create canvas. this.canvas = document.createElement("canvas"); // if on screen. if (bool === true) { this.canvas.style.display = 'block'; this.canvas.style.top = 0; this.canvas.style.left = 0; document.getElementsByTagName("body")[0].appendChild(this.canvas); } this.ctx = this.canvas.getContext("2d"); this.width = this.canvas.width = window.innerWidth; this.height = this.canvas.height = window.innerHeight; // mouse infomation. this.mouseX = null; this.mouseY = null; // shape this.shapeNum = 3; this.shapes = []; // time this.behavior = 0; this.time = new Time(Date.now()); // glitch this.glitch; this.glitchSwitch = false; // dom this.mes1 = document.getElementById('mes1'); this.mes2 = document.getElementById('mes2'); this.list = document.getElementById('list'); this.ul = this.list.lastElementChild; this.asks = [ "I'm sorry, Siri.", 'I love Apple and Siri!', 'It\'s a expensive', 'Are you Alexa?', 'Do you hate Fortninte?', 'OK Google!', 'Do you like windows?', 'I don\'t like safari.']; for (let i = 0; i < 100; i++) { let li = document.createElement('li'); let a = document.createElement('a'); a.setAttribute('href', '#'); a.textContent = this.asks[Tool.randomNumber(0, this.asks.length - 1)]; li.appendChild(a); this.ul.appendChild(li); } this.a = document.getElementsByTagName('a'); for (let i = 0; i < this.a.length; i++) { this.a[i].addEventListener('click', function (e) { e.preventDefault(); canvas.glitchSwitch = true; for (let i = 0; i < canvas.shapes.length; i++) { canvas.shapes[i].cr = 150; } if (this.textContent === 'I love Apple and Siri!' || this.textContent === "I'm sorry, Siri.") { canvas.glitchSwitch = false; for (let i = 0; i < canvas.shapes.length; i++) { canvas.shapes[i].cr = 150; for (let i = 0; i < canvas.shapes.length; i++) { canvas.shapes[i].c = { r: Tool.randomNumber(0, 255), g: Tool.randomNumber(0, 255), b: Tool.randomNumber(0, 255), a: 1 }; } } } if (canvas.glitchSwitch === true) { for (let i = 0; i < canvas.shapes.length; i++) { .........完整代码请登录后点击上方下载按钮下载查看
网友评论0