HTML5 Case Study

Source: Internet
Author: User

1. Draw a Tangram.

<!DOCTYPE HTML><HTML>    <Head>        <MetaCharSet= "Utf-8" />        <title>Draw Tangram</title>    </Head>    <Body>        <CanvasID= "Canvas"style= "border:1px solid #aaa:d isplay:block:margin:50px Auto:">        </Canvas>        <Script>        //Programming Idea: Use an array to represent all of these segmented shapes, and the graphs in the array are represented by dots.         varTangram=[{p:[{x:0, y:0},{x: -, y:0},{x: -, y: -}],color:"#caff67"}, {p:[{x:0, y:0},{x: -, y: -},{x:0, y: -}],color:"#67becf"}, {p:[{x: -, y:0},{x: -, y: -},{x: -, y: -},{x: -, y: $}],color:"#caff67"}, {p:[{x: -, y: $},{x: -, y: -},{x: -, y: -}],color:"#f95la"}, {p:[{x: -, y: -},{x: -, y: -},{x: -, y: -},{x: $, y: -}],color:"#a594c0"}, {p:[{x: $, y: -},{x: -, y: -},{x:0, y: -}],color:"#fa8ccc"}, {p:[{x: -, y: -},{x: -, y: -},{x: -, y: -}],color:"#f6ca29"}] window.onload=function(){                //tool to get paint Vanvas                varCanvas=document.getElementById ('Canvas'); Canvas.width= -; Canvas.height= -; varContext=Canvas.getcontext ('2d'); //Loop Gets the number of array Tangram, trangram[] number of arrays                 for(varI=0; I<Tangram.length;i++) {Draw (tangram[i],context);//invokes a drawing drawing. Tangram[] for the first few graphs, the context indicates that a paint stroke was obtained.                 }            }            //draws a graphic that piece represents the graph {p:[{},{},c],color: ""},CXT represents a paint brush.             functionDraw (PIECE,CXT) {Cxt.beginpath ();//Start PathCxt.moveto (piece.p[0].x,piece.p[0].y);//the first point of a graph                     for(varI=1; I<Piece.p.length;i++) {Cxt.lineto (PIECE.P[I].X,PIECE.P[I].Y); } cxt.closepath ();//End PathCxt.fillstyle=Piece.color;//Fill ColorCxt.fill (); //draw a thick line boxCxt.strokestyle="Red"; Cxt.linewidth=3;            Cxt.stroke (); }                    </Script>    </Body></HTML>
View Code

HTML5 Case Study

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.