HTML5 Canvas Sawtooth Diagram Code Instance

Source: Internet
Author: User

Figure:

Tip: Copy the code to an HTML file and save it and open it to see the effect.

Implementation code:

code is as follows: <!doctype html>


<html lang= "en" >


<head>


<meta charset= "GBK" >


<title> sawtooth Chart </title>


<script type= "Text/javascript" >


Window.addeventlistener ("Load", eventwindowloaded, false);


function eventwindowloaded () {


var x,y;


var Thecanvas = document.getElementById ("Canvas");


var context = Thecanvas.getcontext ("2d");





//box


context.strokestyle = ' #00f ';


context.linewidth=10;


context.strokerect (0, 0, thecanvas.width-0, thecanvas.height-0);


Context.fillstyle = "#00f";


for (x=5;x<=canvas.width;x=x+10) {


Context.beginpath ();


Context.arc (X,5,5,0,math.pi,false);


Context.closepath ();


Context.fill ();


Context.beginpath ();


Context.arc (x,canvas.height-5,5,0,math.pi,true);


Context.closepath ();


Context.fill ();


}


for (y=5;y<=canvas.height;y=y+10) {


Context.beginpath ();


Context.arc (5,y,5,0,math.pi*2,true);


Context.arc (canvas.width-5,y,5,0,math.pi*2,true);


Context.closepath ();


Context.fill ();


}


}


</script>


</head>


<body>


<div style= "Position:absolute; top:100px; left:100px; " >


<canvas id= "Canvas" width= "height=" >


</div>


</body>


</html>

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.