canvas动态彩虹
2015-08-10 13:12
337 查看
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
*{margin:0; padding:0;}
body{width:100%; height:100%; overflow:hidden;}
#canvas{background:url(./images/img_01.gif) no-repeat center center; background-size:100% 100%;}
</style>
</head>
<body>
<canvas id="canvas" width="600" height="500">
您的浏览器不支持canvas
</canvas>
<script>
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
//适配宽高
var pc_width = document.body.clientWidth , pc_height = window.screen.height-60;
canvas.setAttribute('width',pc_width);
canvas.setAttribute('height',pc_height);
canvas.style.backgroundSize = pc_width + "px " + pc_height + "px";
var x = canvas.width/2;
var y = canvas.height/4*3;
var radius = canvas.width/3;
var time = 3000; //绘制时间,每1000表示1秒
var a = 1; //绘制的弧度
var color = ["#f93e26","#f99d23","#f9f924","#73c32a","#39d0c1","#3b7e8e","#884968"];
//线条宽度
var lineWidth = canvas.width/120;
//绘制小人和云彩
var img_1 = new Image();
var img_2 = new Image();
img_1.src = "./images/img_02.png";
img_2.src = "./images/img_03.png";
img_1.onload = function(){
context.drawImage(img_1,canvas.width/9,canvas.height/2,canvas.width/8,canvas.height/4);
context.globalCompositeOperation = "destination-over"; //混合模式
};
img_2.onload = function(){
context.drawImage(img_2,canvas.width/1.5,canvas.height/3,canvas.width/7,canvas.height/10);
context.globalCompositeOperation = "destination-over";
};
function action(){
for(var i=0;i<7;i++){
context.strokeStyle = color[i];
context.lineWidth = lineWidth;
context.beginPath();
context.arc(x,y,radius-(lineWidth*i),Math.PI,a*Math.PI);
context.stroke();
}
}
var t = setInterval(function(){
if(a < 2){
a = a+0.01;
action();
}else if(a >= 2){
clearInterval(t);
}
},time/100);
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<style>
*{margin:0; padding:0;}
body{width:100%; height:100%; overflow:hidden;}
#canvas{background:url(./images/img_01.gif) no-repeat center center; background-size:100% 100%;}
</style>
</head>
<body>
<canvas id="canvas" width="600" height="500">
您的浏览器不支持canvas
</canvas>
<script>
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
//适配宽高
var pc_width = document.body.clientWidth , pc_height = window.screen.height-60;
canvas.setAttribute('width',pc_width);
canvas.setAttribute('height',pc_height);
canvas.style.backgroundSize = pc_width + "px " + pc_height + "px";
var x = canvas.width/2;
var y = canvas.height/4*3;
var radius = canvas.width/3;
var time = 3000; //绘制时间,每1000表示1秒
var a = 1; //绘制的弧度
var color = ["#f93e26","#f99d23","#f9f924","#73c32a","#39d0c1","#3b7e8e","#884968"];
//线条宽度
var lineWidth = canvas.width/120;
//绘制小人和云彩
var img_1 = new Image();
var img_2 = new Image();
img_1.src = "./images/img_02.png";
img_2.src = "./images/img_03.png";
img_1.onload = function(){
context.drawImage(img_1,canvas.width/9,canvas.height/2,canvas.width/8,canvas.height/4);
context.globalCompositeOperation = "destination-over"; //混合模式
};
img_2.onload = function(){
context.drawImage(img_2,canvas.width/1.5,canvas.height/3,canvas.width/7,canvas.height/10);
context.globalCompositeOperation = "destination-over";
};
function action(){
for(var i=0;i<7;i++){
context.strokeStyle = color[i];
context.lineWidth = lineWidth;
context.beginPath();
context.arc(x,y,radius-(lineWidth*i),Math.PI,a*Math.PI);
context.stroke();
}
}
var t = setInterval(function(){
if(a < 2){
a = a+0.01;
action();
}else if(a >= 2){
clearInterval(t);
}
},time/100);
</script>
</body>
</html>
相关文章推荐
- php foreach用法和实例
- 系统操作日志设计
- edgesForExtendedLayout
- java的递归实现原理
- 奔小康赚大钱---hdu2255(最大带权匹配)
- C++中对字符操作的函数集锦
- Java调用系统默认程序打开本地文件
- Android程序员必读电子书推荐
- 日志记录的作用和方法
- Git SSH Key 生成步骤
- PKI(公钥基础设施)基础知识笔记
- 深究递归和迭代的区别、联系、优缺点及实例对比
- Leetcode60 Permutation Sequence
- Qt之显示图片
- HDOJ 3639.Hawk-and-Chicken(Tarjan强连通分量+缩点)
- 程序员学炒股(7) 股指期货收盘价对第二天开盘价有影响吗?
- qq chat image stretch
- hdoj 1159 Common Subsequence【LCS】【DP】
- OVS ARP Responder – Theory and Practice
- ThinkPHP源码分析之核心类文件的加载