国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JavaScript+html5 canvas制作的圓中圓效果實例

2019-11-20 10:40:54
字體:
來源:轉載
供稿:網友

本文實例講述了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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 茌平县| 嘉禾县| 古丈县| 平湖市| 阿鲁科尔沁旗| 江西省| 巩义市| 磴口县| 邻水| 孟村| 永安市| 越西县| 大同市| 定日县| 昌江| 保亭| 渑池县| 沂水县| 洮南市| 富平县| 龙门县| 磐石市| 玉山县| 门源| 陆良县| 芷江| 蓝田县| 肃北| 边坝县| 丰镇市| 七台河市| 新昌县| 泸定县| 江门市| 炎陵县| 上思县| 射阳县| 蕲春县| 于田县| 顺平县| 南昌县|