HTML5 Canvas彩色小球碰撞运动特效

脚本简介HTML5Canvas彩色小球碰撞运动特效是一款基于canvas加面向对象制作的运动小球动画特效。效果展示 http://hovertree.com/texiao/html5/

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

脚本简介

HTML5 Canvas彩色小球碰撞运动特效是一款基于canvas加面向对象制作的运动小球动画特效。
 
 
效果图如下:


HTML5 Canvas彩色小球碰撞运动特效

代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>HTML5 Canvas彩色小球碰撞运动特效 - 何问起</title>
    <base target="_blank" />

    <style>
        #hovertreeball {
            border: 1px dashed #999;
            box-shadow: 0px 4px 40px #233;
            background: black;
        }
        .hovertreeinfo{text-align:center;}
        a{color:blue;}
    </style>
</head>
<body>
    <div class="hovertreeinfo" >
        提示:可以点击按钮改变背景颜色<br />
        <canvas id="hovertreeball" width="800" height="600"></canvas>
    </div>
<script type="text/javascript">
    var canvas = document.getElementById("ho"+"vertreeball");
    var context = canvas.getContext("2d");
    var maxWidth = canvas.width;
    var maxHeight = canvas.height;
    var colors = ["#33B5E5", "#0099CC", "#AA66CC", "#9933CC", "#99CC00", "#669900", "#FFBB33", "#FF8800", "#FF4444", "#CC0000"]

    //随机数
    function random(min, max) {
        return Math.floor(Math.random() * (max - min) + min)
    }

    //构造函数
    function Ball() {
        this.a = true;
        this.b = true;
        this.r = random(10, 30);
        this.ballColor = { color: colors[Math.floor(Math.random() * colors.length)] }
        this.vx = random(30, maxWidth - 30);
        this.vy = random(30, maxHeight - 30);
        this.ispeed = random(1, 10);
        this.ispeed2 = random(1, 10);
    }

    // 面向对象
    Ball.prototype.moveBall = function () {
        context.beginPath();
        if (this.a) {
            this.vx += this.ispeed;
            if (this.vx >= maxWidth - this.r) {
                this.a = false;
            }

        } else {
            this.vx -= this.ispeed;
            if (this.vx <= this.r) {
                this.a = true;
            }
        }

        if (this.b) {
            this.vy += this.ispeed2;
            if (this.vy >= maxHeight - this.r) {
                this.b = false;
            }

        } else {
            this.vy -= this.ispeed2;
            if (this.vy <= this.r) {
                this.b = true;
            }
        }

        context.fillStyle = this.ballColor.color;
        context.arc(this.vx, this.vy, this.r, 0, Math.PI * 2, false);
        context.fill();
    }

    var Aball = [];
    for (var i = 0; i < 100; i++) {
        Aball[i] = new Ball();
    }

    setInterval(function () {
        context.clearRect(0, 0, canvas.width, canvas.height)
        for (var i = 0; i < 100; i++) {
            Aball[i].moveBall();
        }

    }, 30)
    function hovertreecolor() {
        if (canvas.style.backgroundColor != "white") {
            canvas.style.backgroundColor = "white";
        }
        else {
            canvas.style.backgroundColor = "black";
        }
    }
</script>

<div style="text-align:center;margin:10px 0; font:normal 14px/24px 'MicroSoft YaHei';">
    <button id="hovertreechange">改变背景颜色</button>
<p>适用浏览器:FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗等. 不支持IE8及以下浏览器。</p>
<p>来源:<a href="http://hovertree.com/" target="_blank">何问起</a> <a href="http://hovertree.com/menu/texiao/">网页特效</a>
<a href="http://hovertree.com/h/bjaf/mll8cpr3.htm">代码说明</a></p>
</div>
    <script>
        document.getElementById("hover" + "treechange").addEventListener("click", hovertreecolor)
    </script>
</body>
</html>

转自:http://hovertree.com/h/bjaf/mll8cpr3.htm

更多特效:http://www.cnblogs.com/roucheng/p/texiao.html

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

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/120304.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 音视频协议-RTP协议

    音视频协议-RTP协议1协议简介2协议格式介绍3协议解析4协议三方库使用

    2022年6月28日
    43
  • MSN contactlist grabber

    MSN contactlist grabber——msn_contact_grab.class.php——(转)/*Copyright 2007 Jonathan Street jonathan@torrentialwebdev.comThis program is free software; you can redistribute it and/or modify    it under the terms of

    2025年6月18日
    7
  • webstorm激活码最新2021【2021最新】

    (webstorm激活码最新2021)本文适用于JetBrains家族所有ide,包括IntelliJidea,phpstorm,webstorm,pycharm,datagrip等。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月22日
    110
  • windows关闭端口方法[通俗易懂]

    windows关闭端口方法[通俗易懂]windows关闭端口方法在介绍各种端口的作用前,这里先介绍一下在Windows中如何关闭/打开端口,因为默认的情况下,有很多不安全的或没有什么用的端口是开启的,比如Telnet服务的23端口、FT

    2022年8月5日
    5
  • 8080端口被system占用_windows端口被占用但找不到进程

    8080端口被system占用_windows端口被占用但找不到进程端口1080被占用

    2025年9月29日
    2
  • 全012路规律_双元素集合怎么判断

    全012路规律_双元素集合怎么判断堆题目链接将一系列给定数字顺序插入一个初始为空的小顶堆H[]。随后判断一系列相关命题是否为真。命题分下列几种:x is the root:x是根结点;x and y are siblings:x和y是兄弟结点;x is the parent of y:x是y的父结点;x is a child of y:x是y的一个子结点。输入格式:每组测试第1行包含2个正整数N(≤ 1000)和M(≤ 20),分别是插入元素的个数、以及需要判断的命题数。下一行给出区间[−10000,10000]内的N个要被

    2022年8月8日
    5

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号