JavaScript+html5 canvas_javascript 기술로 생성된 원 안의 원 효과의 예

WBOY
풀어 주다: 2016-05-16 15:17:41
원래의
1580명이 탐색했습니다.

이 기사의 예에서는 JavaScript+html5 캔버스에서 생성되는 원 안의 원 효과를 설명합니다. 참고할 수 있도록 모든 사람과 공유하세요. 자세한 내용은 다음과 같습니다.

런닝 효과 스크린샷은 다음과 같습니다.

구체적인 코드는 다음과 같습니다.

<!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 프로그래밍에 종사하는 모든 사람에게 도움이 되기를 바랍니다.

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!