h5-5 canvas

简介:
复制代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
</style>
<script>

window.onload = function(){
    var oC = document.getElementById('c1');
    var oGC = oC.getContext('2d');//绘制环境
    oGC.moveTo(200,200);
    //弧度 = 角度*Math.PI/180
    oGC.arc(200,200,150,0,10*Math.PI/180,true);//画园:圆心坐标,半径,开始角度,结束角度,画的方向true为逆时针。
    oGC.stroke();
};

</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
</body>
</html>
复制代码
复制代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
</style>
<script>

window.onload = function(){
    var oC = document.getElementById('c1');
    var oGC = oC.getContext('2d');
    
    function toDraw(){
        
        var x = 200;
        var y = 200;
        var r = 150;//圆点坐标,半径
        
        oGC.clearRect(0,0,oC.width,oC.height);
        
        var oDate = new Date();
        var oHours = oDate.getHours();
        var oMin = oDate.getMinutes();
        var oSen = oDate.getSeconds();
        
        var oHoursValue = (-90 + oHours*30 + oMin/2) * Math.PI/180;
        var oMinValue = (-90 + oMin*6) * Math.PI/180;
        var oSenValue = (-90 + oSen*6) * Math.PI/180;
        
        
        /*oGC.moveTo(x,y);
        
        oGC.arc(x,y,r,0,6*Math.PI/180,false);
        
        oGC.moveTo(x,y);
        
        oGC.arc(x,y,r,6*Math.PI/180,12*Math.PI/180,false);*/
        
        oGC.beginPath();
        
        for(var i=0;i<60;i++){
            oGC.moveTo(x,y);
            oGC.arc(x,y,r,6*i*Math.PI/180,6*(i+1)*Math.PI/180,false);
        }
        
        oGC.closePath();
        
        oGC.stroke();
        
        
        
        oGC.fillStyle = 'white';
        
        oGC.beginPath();
        
        oGC.moveTo(x,y);
        oGC.arc(x,y,r*19/20,0,360*(i+1)*Math.PI/180,false);
        
        oGC.closePath();
        
        oGC.fill();
        
        
        oGC.lineWidth = 3;
        
        oGC.beginPath();
        
        for(var i=0;i<12;i++){
            oGC.moveTo(x,y);
            oGC.arc(x,y,r,30*i*Math.PI/180,30*(i+1)*Math.PI/180,false);
        }
        
        oGC.closePath();
        
        oGC.stroke();
        
        
        oGC.fillStyle = 'white';
        
        oGC.beginPath();
        
        oGC.moveTo(x,y);
        oGC.arc(x,y,r*18/20,0,360*(i+1)*Math.PI/180,false);
        
        oGC.closePath();
        
        oGC.fill();
        
        
        oGC.lineWidth = 5;
        
        oGC.beginPath();
        oGC.moveTo(x,y);
        
        oGC.arc(x,y,r*10/20,oHoursValue,oHoursValue,false);
        
        oGC.closePath();
        oGC.stroke();
        
        oGC.lineWidth = 3;
        oGC.beginPath();
        oGC.moveTo(x,y);
        
        oGC.arc(x,y,r*14/20,oMinValue,oMinValue,false);
        
        oGC.closePath();
        oGC.stroke();
        
        
        oGC.lineWidth = 1;
        oGC.beginPath();
        oGC.moveTo(x,y);
        
        oGC.arc(x,y,r*19/20,oSenValue,oSenValue,false);
        
        oGC.closePath();
        oGC.stroke();
        
        
    }
    
    setInterval(toDraw,1000);
    
    toDraw();
    
};

</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
</body>
</html>
复制代码
复制代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
</style>
<script>

window.onload = function(){
    var oC = document.getElementById('c1');
    var oGC = oC.getContext('2d');
    oGC.moveTo(100,200);
    oGC.arcTo(100,100,200,100,50);
    oGC.stroke();
};

</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
</body>
</html>
复制代码
复制代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
</style>
<script>

window.onload = function(){
    var oC = document.getElementById('c1');
    var oGC = oC.getContext('2d');
    
    /*oGC.moveTo(100,200);
    oGC.quadraticCurveTo(100,100,200,100);
    oGC.stroke();*/
    oGC.moveTo(100,200);
    oGC.bezierCurveTo(100,100,200,200,200,100);
    oGC.stroke();
};

</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
</body>
</html>
复制代码
复制代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
</style>
<script>

window.onload = function(){
    var oC = document.getElementById('c1');
    var oGC = oC.getContext('2d');
    oGC.translate(100,100);
    oGC.rotate(20*Math.PI/180);
    oGC.rotate(25*Math.PI/180);
    oGC.scale(2,2);
    oGC.fillRect(0,0,100,100);
};

</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
</body>
</html>
复制代码
复制代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body{ background:black;}
#c1{ background:white;}
</style>
<script>

window.onload = function(){
    var oC = document.getElementById('c1');
    var oGC = oC.getContext('2d');
    var num = 0;
    var num2 = 0;
    var value = 1;
    setInterval(function(){            
        num++;    
        oGC.save();    
        oGC.clearRect(0,0,oC.width,oC.height);    
        oGC.translate(100,100);    
        if(num2 == 100){
            value = -1;
        }
        else if(num2 == 0){
            value = 1;
        }    
        num2 += value;    
        oGC.scale( num2*1/50,num2*1/50 );//改变尺寸    
        oGC.rotate(num*Math.PI/180);    //旋转
        oGC.translate(-50,-50);    
        oGC.fillRect(0,0,100,100);    
        oGC.restore();      
    },30);
};

</script>
</head>

<body>
<canvas id="c1" width="400" height="400"></canvas>
</body>
</html>
复制代码

 


本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/5358929.html,如需转载请自行联系原作者

相关文章
|
7月前
|
机器学习/深度学习 数据采集 自然语言处理
深度学习实践技巧:提升模型性能的详尽指南
深度学习模型在图像分类、自然语言处理、时间序列分析等多个领域都表现出了卓越的性能,但在实际应用中,为了使模型达到最佳效果,常规的标准流程往往不足。本文提供了多种深度学习实践技巧,包括数据预处理、模型设计优化、训练策略和评价与调参等方面的详细操作和代码示例,希望能够为应用实战提供有效的指导和支持。
|
7月前
|
存储 关系型数据库 MySQL
MySQL进阶突击系列(09)数据磁盘存储模型 | 一行数据怎么存?
文中详细介绍了MySQL数据库中一行数据在磁盘上的存储机制,包括表空间、段、区、页和行的具体结构,以及如何设计和优化行数据存储以提高性能。
|
人工智能 Cloud Native 数据可视化
优秀技术人,如何做到高效沟通?
世界上有两件最难的事:把别人的钱装进自己的口袋;把自己的思想装进别人的脑袋。
优秀技术人,如何做到高效沟通?
|
弹性计算 容灾 安全
阿里云服务器如何购买?三种购买方式图文教程
阿里云服务器如何购买?三种购买方式图文教程,2023阿里云服务器购买流程更新,选购云服务器有两个入口,一个是选择活动机,只需要选择云服务器地域、系统、带宽即可;另一个是在云服务器页面,自定义选择云服务器配置,这种方式购买云服务器较为复杂,需要选付费方式、地域及可用区、ECS实例规格、镜像、网络、公网IP、安全组等配置,阿里云百科来阿里云服务器购买流程指南2023新版教程:
2232 1
阿里云服务器如何购买?三种购买方式图文教程
|
数据采集 人工智能 运维
|
存储 安全 Java
IDEA插件:FindBugs-- 在Java程序中查找错误
IDEA插件:FindBugs-- 在Java程序中查找错误
IDEA插件:FindBugs-- 在Java程序中查找错误
|
BI
吕氏餐饮:用宜搭智能考核绩效,人事管理更高效
钉钉宜搭帮助吕氏餐饮快速构建了绩效考核系统,实现了在人力资源管理方面质的变化。
1015 0
吕氏餐饮:用宜搭智能考核绩效,人事管理更高效
|
定位技术 数据中心
阿里云服务器如何选择地域节点和可用区?3分钟教你选择
阿里云地域和可用区的选择是很重要的,如何选择地域和可用区:
|
JSON NoSQL 数据挖掘
Python之tushare:tushare库的简介、安装、使用方法之详细攻略
Python之tushare:tushare库的简介、安装、使用方法之详细攻略
Python之tushare:tushare库的简介、安装、使用方法之详细攻略