I have 2 questions.
1) How can I create circles more quickly without having to retype all of the code for each spawning circle?
2) Why are my spiraling circles not smooth? Is it because they are moving too quickly?
DO NOT COMPILE MY PROGRAM IF YOU SUFFER FROM ANY FORM OF SEIZURES!!! I am not responsible for what happens.
Here's the code:
Code
#include <Windows.h>
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <math.h>
using namespace std;
sf::CircleShape Circle1(50);
sf::CircleShape Circle2(50);
sf::CircleShape Circle3(50);
sf::ContextSettings settings;
void circthree();
bool bcircthree = false;
void circtwo();
bool bcirctwo = false;
bool bwinopen = true;
int I, P, SizeTwo, angleTwo, runTwo, SizeThree, angleThree, runThree, J, K;
int main()
{
FreeConsole();
settings.antialiasingLevel = 8;
sf::RenderWindow window(sf::VideoMode(900, 900), "Screensaver 1", sf::Style::Default, settings);
Circle1.setFillColor(sf::Color::Blue);
Circle1.setOrigin(50, 50);
Circle2.setFillColor(sf::Color::Red);
Circle2.setOrigin(50, 50);
Circle3.setFillColor(sf::Color::Blue);
Circle3.setOrigin(50, 50);
int originX, originY, angle, Size, run, X, Y;
originX = 50;
originY = 50;
angle = 45;
Size = 50;
run = 1;
SizeTwo = 50;
angleTwo = 45;
SizeThree = 50;
angleThree = 45;
sf::Thread CTwo(&circtwo);
CTwo.launch();
sf::Thread CThree(&circthree);
CThree.launch();
while (window.isOpen())
{
X = Circle1.getPosition().x + sin(angle)*Size;
Y = Circle1.getPosition().y + cos(angle)*Size;
sf::Event event;
while (window.pollEvent(event))
if (event.type == sf::Event::Closed){
bwinopen = false;
window.close();
}
if (run % 2 == 0)
{
window.clear(sf::Color::Red);
}
else
{
window.clear(sf::Color::Blue);
}
window.draw(Circle1);
if (bcirctwo == true)
{
window.draw(Circle2);
}
if (bcircthree == true)
{
window.draw(Circle3);
}
if (run == 1)
{
Circle1.setPosition(450, 450);
}
else
{
Circle1.setPosition(X, Y);
Sleep(100);
}
window.display();
angle++;
Size = Size + 1;
run++;
}
return 0;
}
void circtwo()
{
Sleep(3000);
bcirctwo = true;
while (bwinopen == true)
{
if (runTwo == 1)
{
Circle2.setPosition(450, 450);
}
else
{
Circle2.setPosition(I, P);
Sleep(100);
}
I = Circle2.getPosition().x + sin(angleTwo)*SizeTwo;
P = Circle2.getPosition().y + cos(angleTwo)*SizeTwo;
angleTwo++;
SizeTwo = SizeTwo + 1;
runTwo++;
}
}
void circthree()
{
Sleep(6000);
bcircthree = true;
while (bwinopen == true)
{
if (runThree == 1)
{
Circle3.setPosition(450, 450);
}
else
{
Circle3.setPosition(J, K);
Sleep(100);
}
J = Circle3.getPosition().x + sin(angleThree)*SizeThree;
K = Circle3.getPosition().y + cos(angleThree)*SizeThree;
angleThree++;
SizeThree = SizeThree + 1;
runThree++;
}
}