canvas怎样做出黑色背景的青色烟花
这次给大家带来canvas怎样做出黑色背景的青色烟花,canvas做出黑色背景的青色烟花的注意事项有哪些,下面就是实战案例,一起来看一下。
html
<canvas></canvas><h1>201<span>8</span></h1>
css
html,body { padding: 0px; margin: 0px; background: #222; font-family: 'Karla', sans-serif; color: #FFF; height: 100%; overflow: hidden; }h1 { z-index: 1000; position: fixed; top: 50%; left: 50%; transform: translateX(-50%) translateY(-100%); font-size: 58px; overflow: hidden; }span { position: relative; display: inline-block; animation: drop 0.75s ease 0s; }canvas { width: 100%; height: 100%; } @keyframes drop { 0% { transform: translateY(-100px); opacity: 0; } 90% { opacity: 1; transform: translateY(10px); } 100% { transform: translateY(0px); } }
js
var ctx = document.querySelector('canvas').getContext('2d')ctx.canvas.width = window.innerWidthctx.canvas.height = window.innerHeightvar sparks = []var fireworks = []var i = 20;while (i--) { fireworks.push( new Firework(Math.random() * window.innerWidth, window.innerHeight * Math.random()) )}render()function render() { setTimeout(render, 1000 / 60) ctx.fillStyle = 'rgba(0, 0, 0, 0.1)'; ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height) for (var firework of fireworks) { if (firework.dead) continue firework.move() firework.draw() } for (var spark of sparks) { if (spark.dead) continue spark.move() spark.draw() } if (Math.random() < 0.05) { fireworks.push(new Firework()) }}function Spark(x, y, color) { this.x = x this.y = y this.dir = Math.random() * (Math.PI * 2) this.dead = false this.color = color this.speed = Math.random() * 3 + 3; this.walker = new Walker({ radius: 20, speed: 0.25 }) this.gravity = 0.25 this.dur = this.speed / 0.1 this.move = function () { this.dur-- if (this.dur < 0) this.dead = true if (this.speed < 0) return if (this.speed > 0) this.speed -= 0.1 var walk = this.walker.step() this.x += Math.cos(this.dir + walk) * this.speed this.y += Math.sin(this.dir + walk) * this.speed this.y += this.gravity this.gravity += 0.05 } this.draw = function () { drawCircle(this.x, this.y, 3, this.color) }}function Firework(x, y) { this.xmove = new Walker({ radius: 10, speed: 0.5 }) this.x = x || Math.random() * ctx.canvas.width this.y = y || ctx.canvas.height this.height = Math.random() * ctx.canvas.height / 2 this.dead = false this.color = randomColor() this.move = function () { this.x += this.xmove.step() if (this.y > this.height) this.y -= 1; else this.burst() } this.draw = function () { drawCircle(this.x, this.y, 1, this.color) } this.burst = function () { this.dead = true var i = 100; while (i--) sparks.push(new Spark(this.x, this.y, this.color)) }}function drawCircle(x, y, radius, color) { color = color || '#FFF' ctx.fillStyle = color ctx.fillRect(x - radius / 2, y - radius / 2, radius, radius)}function randomColor() { return ['#6ae5ab', '#88e3b2', '#36b89b', '#7bd7ec', '#66cbe1'][Math.floor(Math.random() * 5)];}function Walker(options) { this.step = function () { this.direction = Math.sign(this.target) * this.speed this.value += this.direction this.target ? this.target -= this.direction : (this.value) ? (this.wander) ? this.target = this.newTarget() : this.target = -this.value : this.target = this.newTarget() return this.direction } this.newTarget = function () { return Math.round(Math.random() * (this.radius * 2) - this.radius) } this.start = 0 this.value = 0 this.radius = options.radius this.target = this.newTarget() this.direction = Math.sign(this.target) this.wander = options.wander this.speed = options.speed || 1}
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
以上是canvas怎样做出黑色背景的青色烟花的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

win11默认的底部任务栏是浅蓝色的,比较好看,但是有朋友发现突然win11底部状态栏变成了黑色,这可能是更改了主题或背景颜色,改回来就可以了。win11底部状态栏变成了黑色:1、首先点开底部开始菜单,打开“设置”2、接着进入左边栏的“个性化”设置。3、然后打开其中的“颜色”设置。4、进入后,关掉其中的“透明效果”(如果打开后,我们的桌面是黑色的那状态栏就是黑色的)5、如果壁纸不是黑色的,那么把选择模式改为“浅色”即可。6、喜欢别的颜色的话,还可以在主题色里自由选择。

微软邀请Canary和Dev频道的WindowsInsider项目成员,测试和体验新版画图(Paint)应用,最新版本号为11.2306.30.0。本次版本更新最值得关注的新功能是一键抠图功能,用户只需要点击一下,就能自动消除背景,凸显画面主体,便于用户后续操作。整个步骤非常简单,用户在新版画图应用中导入图片,然后点击工具栏上“移除背景”(removebackground)按钮,就可以删除图片中的背景,用户也可以使用矩形来选择要消除背景的区域。

PPT背景替换是一种重要的操作,可快速统一演示文稿的视觉风格。通过修改幻灯片母版或使用“格式背景”功能,可以快速替换整个演示文稿的背景。此外,某些PPT版本还提供批量替换功能,可以轻松替换所有幻灯片的背景。在替换背景时,应注意选择与演示文稿主题相符的背景,并确保背景清晰度和分辨率符合要求。

在iPhone和iPad上,Apple包含的多项辅助功能之一是背景声音。这些声音旨在帮助您保持专注、保持冷静,并帮助您在忙于某事时尽量减少分心。提供的背景声音包括平衡、明亮和黑暗的噪音,以及海洋、雨水和溪流等自然声音。所有声音都可以设置为在后台播放,以掩盖不需要的环境或外部噪音,并且声音混合到其他音频和系统声音中或隐藏在其他音频和系统声音下。在iPhone和iPad上启用背景声音以下步骤介绍如何在运行iOS15/iPadOS15及更高版本的iPhone和iPad上启用背景声音。在iPhone或i

Go语言诞生于Google,旨在解决C++的复杂性和并发支持不足的问题。它的初衷是创造一种简洁易学、高效并发、内存安全、跨平台的语言,以提高程序员的生产力,构建可靠可扩展的系统,并促进代码的移植和共享。

1、打开美图秀秀软件,选择【图片美化】,从相册中导入照片。2、点击底部工具栏的【抠图】,选择【背景替换】功能。3、在【背景】选项中,从纯色方框中挑选所需底色,或上传自定义图片。4、确认选择后,点击【保存】即可完成底色更换。

html2canvas的版本有html2canvas v0.x、html2canvas v1.x等。详细介绍:1、html2canvas v0.x,这是html2canvas的早期版本,目前最新的稳定版本是v0.5.0-alpha1。它是一个成熟的版本,已经被广泛使用,并且在许多项目中得到了验证;2、html2canvas v1.x,这是html2canvas的新版本。

探索Canvas框架:了解常用的Canvas框架有哪些,需要具体代码示例引言:Canvas是HTML5中提供的一个绘图API,通过它我们可以实现丰富的图形和动画效果。为了提高绘图的效率和便捷性,许多开发者开发了不同的Canvas框架。本文将介绍一些常用的Canvas框架,并提供具体代码示例,以帮助读者更深入地了解这些框架的使用方法。一、EaselJS框架Ea
