Javascript+canvas to realize Chiseban effect example _javascript technique

Source: Internet
Author: User

This article illustrates the effect of Javascript+canvas implementation Chiseban. Share to everyone for your reference, specific as follows:

The effect chart is as follows:

Html:

<canvas id= "Canvas" class= "Canvas" width= "" "Height=" ></canvas>

Css:

html,body{margin:0;padding:0}
. canvas{display:block; margin-left:auto;margin-right:auto;margin-top:50px;}

Javascript:

var disk = [{area:[{x:0,y:0},{x:600,y:0},{x:300,y:300}], color: "#CBF263"}, {area:[{x:0,
      Y:0},{X:0,Y:600},{X:300,Y:300}], color: "#5CB6D0"}, {area:[{x:0,y:600},{x:300,y:600},{x:150,y:450}], Color: "#FE9CCD"}, {area:[{x:150,y:450},{x:300,y:300},{x:450,y:450},{x:300,y:600}], color: "#A69 6c3 "}, {area:[{x:300,y:600},{x:600,y:600},{x:600,y:300}], color:" #FBC421 "}, {area:[{ X:600,Y:300},{X:600,Y:0},{X:450,Y:150},{X:450,Y:450}], color: "#FF5061"}, {area:[{x:450,y:450},{x:450 , y:150},{x:300,y:300}], color: "#FDEA11"}] window.onload = function () {var canvasdom = Document.getelementb
    Yid ("Canvas");
    var ctx = Canvasdom.getcontext ("2d");
      Drawdisk (DISK,CTX)} function Drawdisk (DISK,CTX) {for (var i = 0;i<disk.length;i++) {Ctx.beginpath ();
      Ctx.moveto (DISK[I].AREA[0].X,DISK[I].AREA[0].Y); for (var j = 1;j<disk[i]["area")"].length;j++" {Ctx.lineto (DISK[I].AREA[J].X,DISK[I].AREA[J].Y);
      } ctx.closepath ();
      Ctx.fillstyle = disk[i]["Color"];
    Ctx.fill ();

 }
}

For more information on JavaScript-related content readers can view the site topics: "JavaScript animation effects and tips Summary", "JavaScript expansion skills Summary", "JavaScript movement effect and Skills summary", " A summary of JavaScript mathematical operational usage and the JavaScript-oriented introductory tutorial

I hope this article will help you with JavaScript programming.

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.