OpenGL Draw Pentagram

Source: Internet
Author: User
Tags cos



Set Pentagram 5 vertices are abcde, vertex to axis origin distance is R,ABCDE each point with R, respectively,



A (0,R);



B (-r*sin (2/5*PI), R*cos (2/5*PI));



C (-r*sin (PI/5),-r*cos (PI/5));






De and CB about y axisymmetric.












After determining the coordinates of the 5 vertices, the Gl_line_loop function is used to connect 5 points, sequentially acebd.



The main code is:


 
 
 1 void Star(void)
 2 {
 3 
 4     GLfloat r = 0.8f;
 5     GLfloat PointA[2] = { 0, r };
 6     GLfloat PointB[2] = { -r*sin(0.4*Pi), r*cos(0.4*Pi) };
 7     GLfloat PointC[2] = { -r*sin(Pi / 5), -r*cos(Pi / 5) };
 8     GLfloat PointD[2] = { r*sin(Pi / 5), -r*cos(Pi / 5) };
 9     GLfloat PointE[2] = { r*sin(0.4*Pi), r*cos(0.4*Pi) };
10 
11     glClear(GL_COLOR_BUFFER_BIT);
12 
13     glBegin(GL_LINE_LOOP);
14     glVertex2fv(PointA);
15     glVertex2fv(PointC);
16     glVertex2fv(PointE);
17     glVertex2fv(PointB);
18     glVertex2fv(PointD);
19 
20     glEnd();
21 
22     glFinish();
23 }


The results of the drawing are as follows:









OpenGL Draw Pentagram


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.