A review of the canvas pentagram "Junior Trigonometric Functions"

Source: Internet
Author: User
Tags cos

When the program encountered triangular function when I was confused, so Baidu "junior trigonometric Functions",

Forget about these formulas, and punch yourself in the face.

The goal is to draw a pentagram through canvas,

Breakthrough: As long as the radius of the given two outer punctuate, and the radius of the inner punctuate, with the above formula to calculate the coordinates of each pentagram point.

The main code is as follows:

"300" means the radius of the outer ring.

"150" refers to the radius of the inner ring.

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

 var  cvs = document.getElementById ("Canvas" );         var  ctx = Cvs.getcontext ("2d" );        Ctx.linewidth  = 2;                Ctx.beginpath ();  for  (var  i = 0; i < 5; I++) {Ctx.lineto (( + i *)/Math.Cos * Math.PI) * + +,-math.sin ((+ + I *)/+/-Mat            H.PI) * R1 + 400); Ctx.lineto (Math.Cos (( si + i *)/Math.PI) * 400 +,-math.sin ((* * * + i * * * * * * * * * * * * * * * math.pi) * R2        );                } ctx.closepath ();                Ctx.strokestyle  = "Red"  Ctx.stroke (); 

Encapsulation into method

        function draw_star5 (CTX, R1, R2, x, y, rot) {  //  R1 Large circle radius, R2 Small Circle radius, center coordinate x, center coordinate y,rot rotation angle (not available) clockwise /c6>            Ctx.beginpath ();              for  (var i = 0; i < 5; i++) {                Ctx.lineto (math.cos(+ i * 72-rot)/Math.PI + x) -math.sin ((+ i * 72-rot)/math.pi) * r1 + y);                Ctx.lineto (Math.Cos(si + i * 72-rot)/math.pi) * r2 + x,-math.sin ((si + i * 72-rot)/math.pi) * R2 + y);            }                    Ctx.closepath ();        }


A review of the canvas pentagram "Junior Trigonometric Functions"

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.