canvas 简易时钟

canvas 简易版时钟

图片描述

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>时钟</title>
  <style>
        *{
        margin:0;
        padding:0;
    }
    body{
        background:#fff;
    }
    canvas{
        background:#fff;
        display:block;
        margin:100px auto;
    }
  </style>
 </head>
 <body>
    <canvas id="mycanvas" width='500' height='500'>
    
    </canvas>

    <script>
        var can=document.getElementById("mycanvas");
        var cxt=can.getContext('2d');
        function clock(){
                //清除画布,每次执行重新绘图,解决时钟模糊,边框有锯齿。
                cxt.clearRect(0,0,can.width,can.height);
                var now=new Date();
                var hours=now.getHours();
                var min=now.getMinutes();
                var sec=now.getSeconds();
                min=min+sec/60;
                hours=hours+min/60
                //绘制表盘 绘制分针刻度
                cxt.lineWidth=2;
                for(var i=0;i<60;i++){
                    cxt.beginPath();
                    cxt.strokeStyle="#000";
                    cxt.moveTo(250,250);
                    cxt.arc(250,250,100,i*6*Math.PI/180,(i+1)*6*Math.PI/180,false);
                    cxt.closePath();
                    cxt.stroke();
                }
                cxt.beginPath();
                cxt.arc(250,250,95,0,360,false);
                cxt.closePath();
                cxt.fillStyle="#fff";
                cxt.fill();
            
                //绘制时针刻度
                for(var i=0;i<12;i++){
                    cxt.beginPath();
                    cxt.strokeStyle="#000";
                    cxt.moveTo(250,250);
                    cxt.arc(250,250,100,i*30*Math.PI/180,(i+1)*30*Math.PI/180,false);
                    cxt.lineWidth=3;
                    cxt.closePath();
                    cxt.stroke();
                }
                cxt.beginPath();
                cxt.arc(250,250,90,0,360,false);
                cxt.closePath();
                cxt.fillStyle="#fff";
                cxt.fill();

                //绘制时针
                cxt.beginPath();
                cxt.strokeStyle="#000";
                cxt.moveTo(250,250);
                cxt.arc(250,250,75,(-90+hours*30)*Math.PI/180,(-90+hours*30)*Math.PI/180,false);
                cxt.lineWidth=5;
                cxt.closePath();
                cxt.stroke();        
                //绘制分针
                cxt.beginPath();
                cxt.strokeStyle="#000";
                cxt.moveTo(250,250);
                cxt.arc(250,250,85,(-90+min*6)*Math.PI/180,(-90+min*6)*Math.PI/180,false);
                cxt.lineWidth=3;
                cxt.closePath();
                cxt.stroke();

                //绘制秒针
                cxt.beginPath();
                cxt.moveTo(250,250);
                cxt.arc(250,250,90,(-90+sec*6)*Math.PI/180,(-90+sec*6)*Math.PI/180,false);
                cxt.lineWidth=2;
                cxt.strokeStyle="#f00";
                cxt.closePath();
                cxt.stroke();
                //绘制中心
                cxt.beginPath();
                cxt.arc(250,250,5,0,360,false);
                cxt.fillStyle="#000";
                cxt.closePath();
                cxt.fill();
        }
        //时间关联
        clock();
        setInterval(clock,1000)
    </script>
 </body>
</html>

canvas烟花粒子

window.requestAnimFrame=(function(){
    return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(callback){
        window.setTimeout(callback,1000/60);
    };
})();

    var can=document.getElementById("canvas");
    // can.width=document.body.clientWidth ;
    // can.height=document.body.clientHeight;
    var cw=window.innerWidth;
    var ch=window.innerHeight;
    can.width=cw ;
    can.height=ch;
    var cxt=can.getContext("2d");

    var circles=[];        //存放圆形粒子池
    var rects=[];        //存放正方形粒子池
    var triangles=[];    //存放三角形粒子池
    var i=0;
    var count=100;
    var x;                //鼠标的位置
    var y;

    /**
     * 圆形粒子对象
     * @param {[type]} x [description] 中心点
     * @param {[type]} y [description] 中心点
     * @param {[type]} r [description] 半径
     */
    function Circle(x,y,r){
        this.x=x;
        this.y=y;
        this.r=r;
        this.speed=Math.random()*0.5+1;    //速度
        this.direction=Math.random()*Math.PI*2;    //方向
    }
    /**
     * 更新圆心坐标
     * @return {[type]} [description]
     */
    Circle.prototype.update=function(){
        this.x+=Math.cos(this.direction)*this.speed;
        this.y+=Math.sin(this.direction)*this.speed;
        if(this.x<this.r){
            this.x=this.r;
            this.direction=Math.PI-this.direction;
        }
        else if(this.x>=(cw-this.r)){
            this.x=cw-this.r;
            this.direction=Math.PI-this.direction;
        }
        if(this.y<this.r){
            this.y=this.r;
            this.direction=-this.direction;
        }
        else if(this.y>=(ch-this.r)){
            this.y=ch-this.r;
            this.direction=-this.direction;
        }
    };

    /**
     * 绘制圆形粒子
     * @return {[type]} [description]
     */
    Circle.prototype.draw=function(){
        cxt.beginPath();
        cxt.arc(this.x,this.y,this.r,0,360,false);
        cxt.closePath();
        cxt.fillStyle="#f66";
        if(this.x>x-50&&this.x<x+50&&this.y>y-50&&this.y<y+50){
            cxt.globalAlpha=1;
        }else{
            cxt.globalAlpha=0.2;
        }
        cxt.fill();
    };
    /**
     * 矩形粒子对象
     * @param {[type]} x 起点位置
     * @param {[type]} y 起点位置
     * @param {[type]} w 矩形宽
     * @param {[type]} h 矩形长
     */
    function Rect(x,y,w,h){
        this.x=x;
        this.y=y;
        this.w=w;
        this.h=h;
        this.x0=Math.random()*cw;    //正方形的中心坐标    为了旋转而设定
        this.y0=Math.random()*ch;    //正方形的中心坐标
        this.r=Math.sqrt(Math.pow(this.w/2,2)+Math.pow(this.h/2,2));
        this.speed=Math.random()*0.5+1;    //速度
        this.direction=Math.random()*Math.PI*2;    //方向
    }
    /**
     * 更新粒子坐标
     * @return {[type]} [description]
     */
    Rect.prototype.update=function(){
        this.x0+=Math.cos(this.direction)*this.speed;
        this.y0+=Math.sin(this.direction)*this.speed;
        if(this.x0<this.r){
            this.x0=this.r;
            this.direction=Math.PI-this.direction;
        }else if(this.x0>cw-this.r){
            this.x0=cw-this.r;
            this.direction=Math.PI-this.direction;
        }
        if(this.y0<this.r){
            this.y0=this.r;
            this.direction=-this.direction;
        }else if(this.y0>ch-this.r){
            this.y0=ch-this.r;
            this.direction=-this.direction;
        }

    };
    /**
     * 绘制正方形粒子
     * @return {[type]} [description]
     */
    Rect.prototype.draw=function(){
        cxt.save();
        cxt.fillStyle="#06c";
        cxt.translate(this.x0,this.y0);        //将坐标原点移至圆心  方便旋转
        cxt.rotate(i*Math.PI/180);
        cxt.beginPath();
        if(this.x0>x-50&&this.x0<x+50&&this.y0>y-50&&this.y0<y+50){
            cxt.globalAlpha=1;
        }else{
            cxt.globalAlpha=0.5;
        }
        cxt.fillRect(this.x,this.y,this.w,this.h);
        cxt.closePath();
        cxt.restore();
    };
    /**
     * 等边三角形粒子 
     * @param  {[type]} h 三角形高
     * @return {[type]}   [description]
     */
    function Triangle(b){
        this.b=b;
        this.x0=Math.random()*cw;
        this.y0=Math.random()*ch;
        this.speed=Math.random()*0.5+1;
        this.direction=Math.random()*Math.PI*2;
        this.r=this.b/2*Math.tan(30*Math.PI/180);
        console.log(this.r+"   "+this.b);
    }
    /**
     * 中心更新
     * @return {[type]} [description]
     */
    Triangle.prototype.update=function(){
        this.x0+=Math.cos(this.direction)*this.speed;
        this.y0+=Math.sin(this.direction)*this.speed;
        if(this.x0<this.r){
            this.x0=this.r;
            this.direction=Math.PI-this.direction;
        }else if(this.x0>cw-this.r){
            this.x0=cw-this.r;
            this.direction=Math.PI-this.direction;
        }
        if(this.y0<this.r){
            this.y0=this.r;
            this.direction=-this.direction;
        }else if(this.y0>ch-this.r){
            this.y0=ch-this.r;
            this.direction=-this.direction;
        }
    };

    Triangle.prototype.draw=function(){
        cxt.save();
        cxt.fillStyle="#86c";
        cxt.translate(this.x0,this.y0);
        cxt.rotate(i*Math.PI/180);
        cxt.beginPath();
        cxt.moveTo(-this.b/2,-this.r);
        cxt.lineTo(0,Math.sin(60*Math.PI/180)*this.b-this.r);
        cxt.lineTo(this.b/2,-this.r);
        
        
        cxt.closePath();
        if(this.x0>=x-50&&this.x0<=x+50&&this.y0>=y-50&&this.y0<=y+50){
            cxt.globalAlpha=1;
        }else{
            cxt.globalAlpha=0.2;
        }
        cxt.fill();
        cxt.restore();

    };
    while(count--){
        var w=Math.random()*cw;
        var h=Math.random()*ch;
        circles.push(new Circle(w,h,5));
        rects.push(new Rect(-5,5,10,10));
        triangles.push(new Triangle(10));
    }

    canvas.onmousemove=function(ev){
        var ev=ev||window.event;
        x=ev.pageX;
        y=ev.pageY;
        console.log(x+"..."+y);
    };
    /**
     * 在画布中绘制圆形粒子
     * @return {[type]} [description]
     */
    function loop(){
        requestAnimFrame(loop);
        i++;
        if(i>10000){
            i=0;
        }
        cxt.globalCompositeOperation="destination-out";
        cxt.fillStyle="rgba(0,0,0,1)";
        //透明度
        cxt.globalAlpha=1;
        cxt.fillRect(0,0,cw,ch);
        //显示重叠的部分
        cxt.globalCompositeOperation="lighter";
        var n=circles.length;
        while(n--){
            circles[n].draw();
            circles[n].update();
        }
        var n=rects.length;
        while(n--){
            rects[n].draw();
            rects[n].update();
        }

        var n=triangles.length;
        while(n--){
            triangles[n].draw();
            triangles[n].update();
        }
    }
    window.onload=loop;    
基于遗传算法的新的异构分布式系统任务调度算法研究(Matlab代码实现)内容概要:本文档围绕基于遗传算法的异构分布式系统任务调度算法展开研究,重点介绍了一种结合遗传算法的新颖优化方法,并通过Matlab代码实现验证其在复杂调度问题中的有效性。文中还涵盖了多种智能优化算法在生产调度、经济调度、车间调度、无人机路径规划、微电网优化等领域的应用案例,展示了从理论建模到仿真实现的完整流程。此外,文档系统梳理了智能优化、机器学习、路径规划、电力系统管理等多个科研方向的技术体系与实际应用场景,强调“借力”工具与创新思维在科研中的重要性。; 适合人群:具备一定Matlab编程基础,从事智能优化、自动化、电力系统、控制工程等相关领域研究的研究生及科研人员,尤其适合正在开展调度优化、路径规划或算法改进类课题的研究者; 使用场景及目标:①学习遗传算法及其他智能优化算法(如粒子群、蜣螂优化、NSGA等)在任务调度中的设计与实现;②掌握Matlab/Simulink在科研仿真中的综合应用;③获取多领域(如微电网、无人机、车间调度)的算法复现与创新思路; 阅读建议:建议按目录顺序系统浏览,重点关注算法原理与代码实现的对应关系,结合提供的网盘资源下载完整代码进行调试与复现,同时注重从已有案例中提炼可迁移的科研方法与创新路径。
【微电网】【创新点】基于非支配排序的蜣螂优化算法NSDBO求解微电网多目标优化调度研究(Matlab代码实现)内容概要:本文提出了一种基于非支配排序的蜣螂优化算法(NSDBO),用于求解微电网多目标优化调度问题。该方法结合非支配排序机制,提升了传统蜣螂优化算法在处理多目标问题时的收敛性和分布性,有效解决了微电网调度中经济成本、碳排放、能源利用率等多个相互冲突目标的优化难题。研究构建了包含风、光、储能等多种分布式能源的微电网模型,并通过Matlab代码实现算法仿真,验证了NSDBO在寻找帕累托最优解集方面的优越性能,相较于其他多目标优化算法表现出更强的搜索能力和稳定性。; 适合人群:具备一定电力系统或优化算法基础,从事新能源、微电网、智能优化等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于微电网能量管理系统的多目标优化调度设计;②作为新型智能优化算法的研究与改进基础,用于解决复杂的多目标工程优化问题;③帮助理解非支配排序机制在进化算法中的集成方法及其在实际系统中的仿真实现。; 阅读建议:建议读者结合Matlab代码深入理解算法实现细节,重点关注非支配排序、拥挤度计算和蜣螂行为模拟的结合方式,并可通过替换目标函数或系统参数进行扩展实验,以掌握算法的适应性与调参技巧。
本项目是一个以经典51系列单片机——STC89C52为核心,设计实现的一款高性价比数字频率计。它集成了信号输入处理、频率测量及直观显示的功能,专为电子爱好者、学生及工程师设计,旨在提供一种简单高效的频率测量解决方案。 系统组成 核心控制器:STC89C52单片机,负责整体的运算和控制。 信号输入:兼容多种波形(如正弦波、三角波、方波)的输入接口。 整形电路:采用74HC14施密特触发器,确保输入信号的稳定性和精确性。 分频电路:利用74HC390双十进制计数器/分频器,帮助进行频率的准确测量。 显示模块:LCD1602液晶显示屏,清晰展示当前测量的频率值(单位:Hz)。 电源:支持标准电源输入,保证系统的稳定运行。 功能特点 宽频率测量范围:1Hz至12MHz,覆盖了从低频到高频的广泛需求。 高灵敏度:能够识别并测量幅度小至1Vpp的信号,适合各类微弱信号的频率测试。 直观显示:通过LCD1602液晶屏实时显示频率值,最多显示8位数字,便于读取。 扩展性设计:基础版本提供了丰富的可能性,用户可根据需要添加更多功能,如数据记录、报警提示等。 资源包含 原理图:详细的电路连接示意图,帮助快速理解系统架构。 PCB设计文件:用于制作电路板。 单片机程序源码:用C语言编写,适用于Keil等开发环境。 使用说明:指导如何搭建系统,以及基本的操作方法。 设计报告:分析设计思路,性能评估和技术细节。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值