1
\$\begingroup\$

Im trying to make a SFML code that takes my code i already have to make a star with a convex shape and put it into a circle of stars surrounding the point the user chooses. The User is also able to choose the amount of stars in the circle.

Here is my code for making a star

#include <iostream>
#include <SFML/Graphics.hpp>

#include <stdlib.h>

#include <time.h>
#include <math.h>
using namespace std;
using namespace sf;
int main()
{
double x;
double y;
double width;
double p = 3.14*4;
double r = width;

cout<<"Enter x"<<endl;
cin>>x;

cout<<"Enter y"<<endl;
cin>>y;

cout<<"Enter a width"<<endl;
cin >>width;

RenderWindow window(VideoMode(800,800),"My Window");
window.setFramerateLimit(60);



ConvexShape convex;
convex.setPointCount(5);


convex.setPoint(0,Vector2f(width*cos(p/5)+x,width*sin(p/5)+y));
convex.setPoint(1,Vector2f(width*cos(p/5*2)+x, width*sin(p/5*2)+y));
convex.setPoint(2,Vector2f(width*cos(p/5*3)+x, width*sin(p/5*3)+y));
convex.setPoint(3,Vector2f(width*cos(p/5*4)+x, width*sin(p/5*4)+y));
convex.setPoint(4,Vector2f(width*cos(p/5*5)+x, width*sin(p/5*5)+y));
convex.setFillColor(Color(0,0,255));

while (window.isOpen())
{
    Event event;
    while (window.pollEvent(event))
    {
        if (event.type == Event::Closed)
            window.close();
    }
    window.clear();

window.draw(convex);


    window.display();

}
return 0 ;
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.