Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <SFML/Graphics.hpp>
- #include <iostream>
- #include <vector>
- #include <cmath>
- using namespace sf;
- using namespace std;
- int main()
- {
- constexpr int pointCount = 200;
- const Vector2f ellipseRadius = { 200.f, 80.f };
- ContextSettings settings;
- settings.antialiasingLevel = 8;
- RenderWindow window(VideoMode({ 800,600 }), "Ellipse", Style::Default, settings);
- ConvexShape ellipse;
- ellipse.setPosition({ 400,320 });
- ellipse.setFillColor(Color::Blue);
- ellipse.setPointCount(pointCount);
- for (int pointNo = 0; pointNo < pointCount; pointNo++) {
- float angle = float(2 * M_PI * pointNo) / float(pointCount);
- Vector2f point = {
- ellipseRadius.x * sin(angle),
- ellipseRadius.y * cos(angle)
- };
- ellipse.setPoint(pointNo, point);
- }
- vector< vector< vector<Vertex> > > lines;
- int lineCount = 5;
- int segmentCount = 200;
- int _x = 400;
- int _y = 320;
- for( int i = 0; i < lineCount; i++ ){
- vector< vector<Vertex> > line;
- for( int j = 0; j < segmentCount - 1; j++ ){
- float a1 = float(2 * M_PI * j ) / float( segmentCount );
- float a2 = float(2 * M_PI * (j + 1) ) / float( segmentCount );
- float x = ellipseRadius.x * ( float(i) / lineCount );
- float y = ellipseRadius.y;
- vector<Vertex> lineSegment{
- sf::Vertex(sf::Vector2f( _x + x * sin(a1), _y + y * cos(a1))),
- sf::Vertex(sf::Vector2f( _x + x * sin(a2), _y + y * cos(a2))),
- };
- line.push_back( lineSegment );
- }
- lines.push_back( line );
- }
- /*
- double circleRadius = sqrt(pow(ellipseRadius.x, 2) + pow(ellipseRadius.y, 2));
- double angle = atan(ellipseRadius.y / ellipseRadius.x);
- double step = -angle * 2 / 10;
- VertexArray arrays[10];
- VertexArray base = VertexArray(TrianglesStrip, 22);
- for (int i = 0; i < 10; i++) {
- arrays[i] = VertexArray(TrianglesStrip, 22);
- }
- double t = 3;
- for (int i = 0; i <= 10; i++) {
- double currentAngle = angle + step * i;
- base[2 * i] = Vector2f( circleRadius * cos(currentAngle) - 200, circleRadius * sin(currentAngle) + 320);
- base[2 * i].color = Color::Red;
- base[2 * i + 1] = Vector2f( (circleRadius + t) * cos(currentAngle) - 200, (circleRadius + t) * sin(currentAngle) + 320);
- base[2 * i + 1].color = Color::Red;
- }
- double f = 3;
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 22; j++) {
- arrays[i][j] = Vector2f( ( ( base[j].position.x ) * ( ( i - 5 + 1 ) * f ) ) + 400 , ( base[j].position.y));
- if (j % 2 == 0)
- {
- arrays[0][j].position.x *= (1 - (2 * i + 1) / 100);
- }
- }
- }
- */
- while (window.isOpen())
- {
- Event event;
- while (window.pollEvent(event))
- {
- if (event.type == Event::Closed)
- {
- window.close();
- }
- }
- window.clear();
- window.draw(ellipse);
- for( int i = 0; i < lineCount; i ++ ){
- for( int j = 0; j < segmentCount - 1; j++ ){
- Vertex line[2] = {
- lines[i][j][0],
- lines[i][j][1]
- };
- //std::cout << line[0] << line[1] << std::endl;
- window.draw( line, 3, sf::Lines );
- }
- }
- /*
- for (int i = 0; i < 10; i++) {
- window.draw(arrays[i]);
- }
- window.draw( base );
- */
- window.display();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement