Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body { position: relative; overflow: hidden; } body::after { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0.1; } canvas { width: 100vw; height: 100vh; }
JavaScript
console.clear() class Utils { static randomRange(min, max) { return Math.random() * (max - min) + min } static mapRange (value, inputMin, inputMax, outputMin, outputMax, clamp) { if (Math.abs(inputMin - inputMax) < Number.EPSILON) { return outputMin; } else { var outVal = ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin); if (clamp) { if (outputMax < outputMin) { if (outVal < outputMax) outVal = outputMax; else if (outVal > outputMin) outVal = outputMin; } else { if (outVal > outputMax) outVal = outputMax; else if (outVal < outputMin) outVal = outputMin; } } return outVal; } } } Utils.simplex = new SimplexNoise('seed') class App { constructor() { this.config = { bgColor: chroma({ h: 230, s: 0.5, l: 0.92}).hex(), colorSchema: [ '#5E9FA3', '#DCD1B4', '#FAB87F', '#F87E7B', '#B05574', ], numOfLayers: 9 } this.canvas = document.getElementById('c') this.ctx = this.canvas.getContext('2d') this.shadowCanvas = document.createElement('canvas') this.shadowCtx = this.shadowCanvas.getContext('2d') this.timestamp = 0 this.fpsHistory = [] this.setUpVars() this.setUpListeners() // this.setUpGui() this.update() } setUpGui() { const pane = new Tweakpane() const folder = pane.addFolder({ expanded: false, title: 'Settings', }) folder.addInput(this.config, 'bgColor') } setUpVars() { this.canvas.width = this.shadowCanvas.width = this.wWidth = window.innerWidth this.canvas.height = this.shadowCanvas.height = this.wHeight = window.innerHeight this.wCenterX = this.wWidth / 2 this.wCenterY = this.wHeight / 2 this.wHypot = Math.hypot(this.wWidth, this.wHeight) this.wMin = Math.min(this.wWidth, this.wHeight) this.angle = Math.PI * 0.25 this.layers = this.getLayers() } getLayers() { const layers = [] let currColorId = 0 for (let lid = 0; lid <= this.config.numOfLayers; lid++) { const colorAngle = Math.PI * 2 * (lid / this.config.numOfLayers) layers.push({ id: lid, // used for noise offset progress: 1 - (lid / this.config.numOfLayers), color: this.config.colorSchema[currColorId] }) currColorId++ if (currColorId >= this.config.colorSchema.length) { currColorId = 0 } } return layers } setUpListeners() { window.addEventListener('resize', this.setUpVars.bind(this)) } drawLayer(ctx, layer) { const segmentBaseSize = 10 const segmentCount = Math.round(this.wHypot / segmentBaseSize) const segmentSize = this.wHypot / segmentCount const waveAmplitude = segmentSize * 4 const noiseZoom = 0.03 ctx.save() ctx.translate(this.wCenterX, this.wCenterY) ctx.rotate(Math.sin(this.angle)) ctx.beginPath() ctx.moveTo(-this.wHypot / 2, this.wHypot / 2 - (this.wHypot * layer.progress)) ctx.lineTo(-this.wHypot / 2, this.wHypot / 2) ctx.lineTo(this.wHypot / 2, this.wHypot / 2) ctx.lineTo(this.wHypot / 2, this.wHypot / 2 - (this.wHypot * layer.progress)) for (let sid = 1; sid <= segmentCount; sid++) { const n = Utils.simplex.noise3D(sid * noiseZoom, sid * noiseZoom, layer.id + this.timestamp) const heightOffset = n * waveAmplitude ctx.lineTo((this.wHypot / 2) - (sid * segmentSize), this.wHypot / 2 - (this.wHypot * layer.progress) + heightOffset) } ctx.closePath() ctx.fillStyle = layer.color ctx.fill() ctx.restore() } draw(ctx) { ctx.save() ctx.fillStyle = this.config.bgColor ctx.fillRect(0, 0, this.wWidth, this.wHeight) ctx.restore() this.layers.forEach(layer => this.drawLayer(ctx, layer)) } update(t) { const prevTimestamp = this.timestamp * 5000 if (t) { let shiftNeeded = false this.timestamp = t / 5000 this.angle += 0.001 this.layers.forEach(layer => { layer.progress += 0.001 if (layer.progress > 1 + (1 / (this.layers.length - 1))) { layer.progress = 0 shiftNeeded = true } }) if (shiftNeeded) { this.layers.push(this.layers.shift()) } this.draw(this.shadowCtx) } this.ctx.clearRect(0, 0, this.wWidth, this.wHeight) this.ctx.drawImage(this.shadowCanvas, 0, 0) // show fps const fps = Math.round(1 / (t - prevTimestamp) * 1000) this.fpsHistory.unshift(fps) this.fpsHistory.length = 5 this.ctx.font = '16px sans-serif' this.ctx.fillText(this.fpsHistory.reduce((a,b) => a+b) / 5, 50, 50) window.requestAnimationFrame(this.update.bind(this)) } } new App()
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>canvas彩色海浪-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号