HTML5 JavaScript canvas API draw tree pattern

Source: Internet
Author: User

HTML5 JavaScript canvas API draw tree pattern

<! Doctype HTML> <title> HTML5 JavaScript canvas API draws a tree pattern </title> <body> <canvas id = "Diagonal" style = "border: 1px solid; "width =" 400 "Height =" 400 "> </canvas> <SCRIPT type =" text/JavaScript "> function createcanopypath (context) {context. beginpath (); context. moveTo (-25,-50); context. lineto (-10,-80); context. lineto (-20,-80); context. lineto (-5,-110); context. lineto (-15,-110); context. lineto (0,-140); context. lineto (15,-110); context. lineto (5,-110); context. lineto (20,-80); context. lineto (10,-80); context. lineto (25,-50); context. closepath ();} function drawtrails () {var canvas = document. getelementbyid ('diagonal'); var context = canvas. getcontext ('2d '); context. save (); context. translate (130,250); createcanopypath (context ); // ========================================/// broaden the context of the line. linewidth = 4; // The context of the smooth path. linejoin = 'round '; // change the color to brown context. strokestyle = '#663300'; // set the fill color to green and fill the canopy context. fillstyle = '#339900'; context. fill (); // ==============================/// draw the trunk context. fillstyle = '#663300'; context. fillrect (-5,-50, 10, 50 ); // =================================== context. stroke (); context. restore (); // ------------------------------------ context. save (); context. translate (-10,350); context. beginpath (); context. moveTo (0, 0); // The first curve is bent to the upper right corner of the context. quadraticcurveto (170,-50,260,-190); // The second curve is bent to the lower right of the context. quadraticcurveto (310,-250,410,-250); context. strokestyle = '#663300'; context. linewidth = 20; context. stroke (); context. restore (); // -------------------------------------} window. addeventlistener ("LOAD", drawtrails, true); </SCRIPT> http://www.cnblogs.com/TerryBlog/archive/2012/02/27/2370048.html <br> HTML5 learning URL: <br> <a href = 'HTTP: // www.cnblogs.com/terryblog/archive/2012/02/27/2370048.html'> http://www.cnblogs.com/TerryBlog/archive/2012/02/27/2370048.html </a> </body> 
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.