sfml-tutorial/graphics.cpp
2012-03-07 13:25:06 -05:00

69 lines
1.6 KiB
C++

#include <iostream>
#include <list>
#include <math.h>
#include <SFML/Graphics.hpp>
sf::Shape build_ngon(int n, float radius)
{
sf::Shape s;
for (int i = 0; i < n; i++)
{
float angle = i * 2.0 * M_PI / n;
float x = radius * cos(angle);
float y = radius * sin(angle);
s.AddPoint(x, y, sf::Color(255, 128, 0), sf::Color(0, 0, 100));
}
s.SetColor(sf::Color(255, 255, 255, 255));
s.SetOutlineWidth(4);
return s;
}
int main()
{
sf::Clock Clock;
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
// App.UseVerticalSync(true);
// App.SetActive();
std::list<sf::Shape> shapes;
for (int n = 3, x = 0; x < 4; x++)
{
for (int y = 0; y < 3; y++, n++)
{
sf::Shape s = build_ngon(n, 75);
s.Move(200 * x + 100, 200 * y + 100);
shapes.push_back(s);
}
}
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
if ( (Event.Type == sf::Event::KeyPressed)
&& (Event.Key.Code == sf::Key::Escape) )
App.Close();
}
App.Clear(sf::Color(0, 0, 0));
for (std::list<sf::Shape>::iterator it = shapes.begin();
it != shapes.end();
it++)
{
it->Rotate(1000 * Clock.GetElapsedTime());
App.Draw(*it);
}
App.Display();
Clock.Reset();
}
return EXIT_SUCCESS;
}