JavaScript+html5 canvas制作的圆中圆效果实例
作者:bea
本文实例讲述了JavaScript+html5 canvas制作的圆中圆效果。分享给大家供大家参考,具体如下: 运行效果截图如下: 具体代码如下: <!DOCTYPE html><html> <head> <title>demo</title> <style type="text/css"> #canvas { background:#F2F2F2; height:500px; hei
本文实例讲述了JavaScript+html5 canvas制作的圆中圆效果。分享给大家供大家参考,具体如下:
运行效果截图如下:
具体代码如下:
<!DOCTYPE html>
<html>
<head>
<title>demo</title>
<style type="text/css">
#canvas {
background:#F2F2F2; height:500px; height:500px; margin-top:100px; margin-left:200px;
}
</style>
</head>
<body>
<canvas id="canvas" width="500px" height="500px" ></canvas>
</body>
<script type="text/javascript">
(function() {
var dyl = {};
dyl.getDom = function(id) {
return document.getElementById(id);
}
dyl.getContext = function(canvasID) {
var canvas = this.getDom(canvasID);
if(!canvas) {
return null;
}
return canvas.getContext("2d");
}
if(!window.dyl) {
window.dyl = dyl;
}
})();
cache = {};
cache.context = dyl.getContext('canvas');
// 每个圈的圆个数控制
cache.scaleNmb = 6;
cache.createColor = function() {
var color = "rgb(";
color += Math.round(Math.random()*255);
color += ",";
color += Math.round(Math.random()*255);
color += ",";
color += Math.round(Math.random()*255);
color += ")";
return color;
};
cache.draw = function() {
cache.context.fillRect(-10, -10, 20, 20);
for(var i=1; i<10; i++) {
cache.context.save();
for(var j=0; j<cache.scaleNmb*i; j++) {
cache.context.rotate(Math.PI*2/(cache.scaleNmb*i));
cache.context.fillStyle = cache.createColor();
cache.context.beginPath();
cache.context.arc(0, 20*i, 5, 0,Math.PI*2, true);
cache.context.closePath();
cache.context.fill();
}
cache.context.restore();
}
};
cache.init = function() {
cache.context.translate(250, 250);
cache.draw();
};
cache.init();
</script>
</html>
更多关于js特效相关内容感兴趣的读者可查看本站专题:《jQuery动画与特效用法总结》、《jQuery常见经典特效汇总》及《JavaScript动画特效与技巧汇总》
希望本文所述对大家JavaScript程序设计有所帮助。
有用 | 无用
运行效果截图如下:
具体代码如下:
<!DOCTYPE html>
<html>
<head>
<title>demo</title>
<style type="text/css">
#canvas {
background:#F2F2F2; height:500px; height:500px; margin-top:100px; margin-left:200px;
}
</style>
</head>
<body>
<canvas id="canvas" width="500px" height="500px" ></canvas>
</body>
<script type="text/javascript">
(function() {
var dyl = {};
dyl.getDom = function(id) {
return document.getElementById(id);
}
dyl.getContext = function(canvasID) {
var canvas = this.getDom(canvasID);
if(!canvas) {
return null;
}
return canvas.getContext("2d");
}
if(!window.dyl) {
window.dyl = dyl;
}
})();
cache = {};
cache.context = dyl.getContext('canvas');
// 每个圈的圆个数控制
cache.scaleNmb = 6;
cache.createColor = function() {
var color = "rgb(";
color += Math.round(Math.random()*255);
color += ",";
color += Math.round(Math.random()*255);
color += ",";
color += Math.round(Math.random()*255);
color += ")";
return color;
};
cache.draw = function() {
cache.context.fillRect(-10, -10, 20, 20);
for(var i=1; i<10; i++) {
cache.context.save();
for(var j=0; j<cache.scaleNmb*i; j++) {
cache.context.rotate(Math.PI*2/(cache.scaleNmb*i));
cache.context.fillStyle = cache.createColor();
cache.context.beginPath();
cache.context.arc(0, 20*i, 5, 0,Math.PI*2, true);
cache.context.closePath();
cache.context.fill();
}
cache.context.restore();
}
};
cache.init = function() {
cache.context.translate(250, 250);
cache.draw();
};
cache.init();
</script>
</html>
更多关于js特效相关内容感兴趣的读者可查看本站专题:《jQuery动画与特效用法总结》、《jQuery常见经典特效汇总》及《JavaScript动画特效与技巧汇总》
希望本文所述对大家JavaScript程序设计有所帮助。
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- Bootstrap树形控件使用方法详解
- window.onerror()的用法与实例分析
- 用window.onerror捕获并上报Js错误的方法
- jquery实现可旋转可拖拽的文字效果代码
- jquery+css3实现会动的小圆圈效果
- 再谈JavaScript异步编程
- 简单介绍jsonp 使用小结
- 理解javascript异步编程
- js实现的鼠标滚轮滚动切换页面效果(类似360默认页面滚动切换效果)
- AngularJS转换响应内容
- jQuery+css实现的切换图片功能代码
- javascript中的3种继承实现方法
- jQuery+css实现的换页标签栏效果
- js实现的彩色方块飞舞奇幻效果
- JavaScript下的时间格式处理函数Date.prototype.format
- 基于JavaScript实现瀑布流效果(循环渐近)
- jQuery Easyui学习之datagrid 动态添加、移除editor
- js实现简单排列组合的方法
- jQuery插件开发精品教程让你的jQuery提升一个台阶