canvas怎样做出黑色背景的青色烟花

这次给大家带来canvas怎样做出黑色背景的青色烟花,canvas做出黑色背景的青色烟花的注意事项有哪些,下面就是实战案例,一起来看一下。

1.png

html

2018

登录后复制

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) 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}

登录后复制

相信看了本文案例你已经掌握了方法,更多精彩请关注【创想鸟】其它相关文章!

推荐阅读:

JS中的async/await

canvas怎样做出黑色背景的红色烟花

以上就是canvas怎样做出黑色背景的青色烟花的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2783286.html

(0)
上一篇 2025年3月8日 16:47:19
下一篇 2025年2月23日 10:42:42

AD推荐 黄金广告位招租... 更多推荐

相关推荐

  • js实现将canvas生成图片保存或直接保存一张图片

    本文主要和大家分享js实现将canvas生成图片保存或直接保存一张图片,希望能帮助到大家。 将canvas数组保存 function downLoadImage(canvas,name) {    var a = document.crea…

    编程技术 2025年3月8日
    200
  • js与canvas合成图片做出微信公众号海报功能

    这次给大家带来js与canvas合成图片做出微信公众号海报功能,js与canvas合成图片做出微信公众号海报功能的注意事项有哪些,下面就是实战案例,一起来看一下。 在微信公众号开发中,很多时候都有个需求是一张图加上头像和昵称或者其他数据生成…

    2025年3月8日 编程技术
    200
  • js和canvas实现滑动拼图验证码功能

    本文主要和大家分享js和canvas实现滑动拼图验证码功能,现在经常会遇到滑动拼图验证,希望能帮助到大家。   上图为网易云盾的滑动拼图验证码,其应该有一个专门的图片库,裁剪的位置是固定的。我的想法是,随机生成图片,随机生成位置,再用can…

    2025年3月8日 编程技术
    200
  • js和canvas实现图片预览压缩上传

    本文主要大家分享js和canvas实现图片预览压缩上传的方法,结合实例代码和大家讲解,希望能帮助到大家。 第一步:用户选择需要上传的图片 登录后复制 在选定了图片后 upload 函数将被触发,我们需要在这个函数中,获取到图片的资源,将它压…

    2025年3月8日
    200
  • canvas怎么实现轨迹回放

    这次给大家带来canvas怎么实现轨迹回放,canvas实现轨迹回放的注意事项有哪些,下面就是实战案例,一起来看一下。 本文通过json机构,HTML代码以及JS代码详细给大家分析了canvas轨迹回放功能实现的过程,以下是全部内容。 js…

    编程技术 2025年3月8日
    200
  • Particles.js实现粒子动态背景动画

    这次给大家带来Particles.js实现粒子动态背景动画,Particles.js实现粒子动态背景动画的注意事项有哪些,下面就是实战案例,一起来看一下。 操作过程: 网上有基本流程,可以参考一下,不过直接用在登录页面 会有小bug,需要调…

    编程技术 2025年3月8日
    200
  • canvas与JS实现动态时钟动画

    这次给大家带来canvas与js实现动态时钟动画,canvas与js实现动态时钟动画的注意事项有哪些,下面就是实战案例,一起来看一下。 先来看看运行效果: 完整实例代码: canvas时钟 canvas { border: 1px soli…

    2025年3月8日
    200
  • js怎么封装Canvas成插件

    这次给大家带来js怎么封装Canvas成插件,js封装Canvas成插件的注意事项有哪些,下面就是实战案例,一起来看一下。 之前就说过,我想写一个canvas画统计图的插件,现在写好了 先说下实现的功能吧:   1.可以通过自定义X轴坐标属…

    编程技术 2025年3月8日
    200
  • canvas怎么编辑操作图像

    这次给大家带来canvas怎么编辑操作图像,canvas编辑操作图像的注意事项有哪些,下面就是实战案例,一起来看一下。 本次文章将分为几个小功能的形式来详细介绍canvas图像编辑 缩放 下面是一张分析图,假设默认情况下,图片和canvas…

    编程技术 2025年3月8日
    200
  • Vue利用canvas实现移动端手写板的方法

    这篇文章主要介绍了关于vue利用canvas实现移动端手写板的方法,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下 本文介绍了Vue利用canvas实现移动端手写板的方法,分享给大家,具体如下:   清除 保存  Canvas…

    编程技术 2025年3月8日
    200

发表回复

登录后才能评论