Canvas rotation-Special Effects of HTML5

Source: Internet
Author: User

The content of translate.html is as follows:


[Html]
<! Doctype html>
<Html>
<Head>
<Script type = "text/javascript" src = "jquery-1.7.2.min.js"> </script>
<Script type = "text/javascript" src = "translate. js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
 
});
</Script>
</Head>
<Body>
<Canvas id = "simple"> </canvas>
</Body>
</Html>

<! Doctype html>
<Html>
<Head>
<Script type = "text/javascript" src = "jquery-1.7.2.min.js"> </script>
<Script type = "text/javascript" src = "translate. js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){

});
</Script>
</Head>
<Body>
<Canvas id = "simple"> </canvas>
</Body>
</Html>

The code for translate. js is as follows:


[Javascript]
(Function (){
Var canvas = null,
Context = null,
Angle = 0;
Function resetCanvas (){
Canvas = document. getElementById ("simple ");
Canvas. width = window. innerWidth;
Canvas. height = window. innerHeight;
Context = canvas. getContext ("2d ");
}
Function animate (){
Context. save ();
Try {
// Clear the canvas
Context. clearRect (0, 0, canvas. width, canvas. height );
// Set the origin
Context. translate (canvas. width * 0.5, canvas. height * 0.5 );
// Rotation Angle
Context. rotate (angle );
// Set the fill color
Context. fillStyle = "# FF0000 ";
// Draw a rectangle
Context. fillRect (-30,-30, 60, 60 );
Angle ++ = 0.05 * Math. PI;
}
Finally {
Context. restore ();
}
}
$ (Window). bind ("resize", resetCanvas). bind ("reorient", resetCanvas );
$ (Document). ready (function (){
Window. scrollTo (0, 1 );
ResetCanvas ();
SetInterval (animate, 40 );
});
})();

(Function (){
Var canvas = null,
Context = null,
Angle = 0;
Function resetCanvas (){
Canvas = document. getElementById ("simple ");
Canvas. width = window. innerWidth;
Canvas. height = window. innerHeight;
Context = canvas. getContext ("2d ");
}
Function animate (){
Context. save ();
Try {
// Clear the canvas
Context. clearRect (0, 0, canvas. width, canvas. height );
// Set the origin
Context. translate (canvas. width * 0.5, canvas. height * 0.5 );
// Rotation Angle
Context. rotate (angle );
// Set the fill color
Context. fillStyle = "# FF0000 ";
// Draw a rectangle
Context. fillRect (-30,-30, 60, 60 );
Angle ++ = 0.05 * Math. PI;
}
Finally {
Context. restore ();
}
}
$ (Window). bind ("resize", resetCanvas). bind ("reorient", resetCanvas );
$ (Document). ready (function (){
Window. scrollTo (0, 1 );
ResetCanvas ();
SetInterval (animate, 40 );
});
})();
Open translate.html with a browser supporting hmtl5to see a red circle

Related Article

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.