Create Kaleidoscope animation effects with HTML5 's canvas

Source: Internet
Author: User

1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <style>5 #canvas{6 Background-color:#cccccc;7          8      }9 </style>Ten <Script> One window.onload=function(){ A    varCanvas=document.getElementById ("Canvas"); -    varCObj=Canvas.getcontext ("2d"); -    //var num=150; the     vararr=[]; -     //var angle=0; - SetInterval (function(){ - Cobj.clearrect (0,0, -, -); +           for(varI=0; I<Arr.length;i++) -          { +               A Cobj.save (); at Cobj.translate ( -, -); - Cobj.scale (Arr[i].scale,arr[i].scale); - cobj.rotate (Arr[i].angle*Math.PI/);//The center of the rotation is defined as the origin position of the canvas before the rotation, and the position of the origin is changed only to the subsequent drawing, and the following rectangle is where the origin is (50,50), and the center of rotation is at (100,100) - Cobj.beginpath (); - Cobj.fillstyle=Arr[i].color; - Cobj.rect (Arr[i].num,arr[i].num, -, -); in Cobj.fill (); - Cobj.restore (); to          } +         -         the }, -) * SetInterval (function(){ $          for(varI=0; I<Arr.length;i++)Panax Notoginseng         { -          if(Arr[i].num<=0) the           { + Arr.splice (i,1);//remove the current element; A              Continue;//at the same time exit this cycle the               +           } -           //changes in the storage settings are important, if the change of the storage is not set up, it may not be able to achieve the effect $ Arr[i].angle+=2; $ Arr[i].num-=0.2; - Arr[i].scale-=0.002; -           if(Arr[i].scale<=0.2) the Arr[i].scale=0.2; -         }Wuyi           the     }, -) - SetInterval (function(){ Wu         varrect={angle:0, Num: Max, Scale:1, Color:"RGB ("+parseint (Math.random ()*255)+","+parseint (Math.random ()*255)+","+parseint (Math.random ()*255)+")"} ; - Arr.push (rect); About    }, +) $     -    } -    </Script> - </Head> A <Body> + <CanvasID= "Canvas"width=600pxHeight=600px> the your browser is out of date!  - </Canvas> $  the </Body> the </HTML>

Create Kaleidoscope animation effects with HTML5 's canvas

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.