# Thread: Drawing to code 5 point star function C++

1. ## Drawing to code 5 point star function C++

I'm trying to code a 5 point star function in C++, I am using the WinBGIm library. I am getting stuck on the trigonometry of the triangle. My function is given the centre x and y coordinates and the radius of the star all as integers.

This is what I have s ofar.

Code:
```// The main purpose of this program is to draw 7 stars
// Using the WinBGIm graphics library.

// Directives:
#include <graphics.h>
#include <cstdlib>
#include <cmath>
using namespace std;

//Constants

const int S = 700;

// First Star(test)
const int STARX1 = 0.2*S;
const int STARY1 = 0.5*S;

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Function Prototypes.
// This is a list of all the functions that I plan to write because the
// author of the graphics library did not have them!
void star (int cx, int cy, int radius);
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Main program

int main()
{
initwindow(S,S,"Dipper!");
delay(200000);

}

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// This function draws a star. The center of the star is at (cx, cy),

void star(int cx, int cy, int radius)
{

int farrightxcoord = cx + radius*cos(M_PI/10);
int farrightycoord = cy - radius*sin(M_PI/10);
int farleftxcoord    = cx + radius*cos(13*M_PI/10);
int farleftycoord    = cy - radius*sin(13*M_PI/10);
int topxcoord = cx + radius*cos(17*M_PI/10);
int topycoord = cy - radius*sin(17*M_PI/10);
line(farrightxcoord,farrightycoord, farleftxcoord, farleftycoord);
line(farrightxcoord,farrightycoord, bottomleftxcoord,bottomleftycoord);
line(bottomleftxcoord,bottomleftycoord,topxcoord,topycoord);
line(topxcoord,topycoord,bottomrightxcoord,bottomrightycoord);
line(bottomrightxcoord,bottomrightycoord, farleftxcoord, farleftycoord);```
As you can see the star function is where I am really confused, can someone help me with this?

2. this'll work -

line(x, y - starsize,
x + starsize*sin(M_PI/5), y + starsize*cos(M_PI/5));
line(x + starsize*sin(M_PI/5), y + starsize*cos(M_PI/5),
x - starsize*cos(M_PI/10), y - starsize*sin(M_PI/10));
line(x - starsize*cos(M_PI/10), y - starsize*sin(M_PI/10),
x + starsize*cos(M_PI/10), y - starsize*sin(M_PI/10));
line(x + starsize*cos(M_PI/10), y - starsize*sin(M_PI/10),
x - starsize*sin(M_PI/5), y + starsize*cos(M_PI/5));
line(x - starsize*sin(M_PI/5), y + starsize*cos(M_PI/5),
x, y - starsize);

peace