1
Graphics / Re: Get an image from a shape
« on: December 27, 2012, 04:18:01 am »
Yes, I guess so, but I'm wondering how are this fans generated. Anyway, the results of the test:
The condition is that given the radius and the pointCount, for every i greater than zero, CircleShape(radius, pointCount) equals bit-to-bit to CircleShape(radius, pointCount + i)
Ok, I didn't test it for every i greater than zero, but at least 20 values from the last change
radius -> pointCount
1 -> 5
2 -> 5
3 -> 14
4 -> 10
5 -> 22
6 -> 10
7 -> 32
8 -> 20
9 -> 18
10 -> 26
11 -> 51
12 -> 21
13 -> 64
14 -> 37
15 -> 71
It's kind of surprising for me, especially the change from 7 to 9 (it decreases).
Here's the code, if you want to repeat the test. Just use the arrows to increase or decrease both values:
#include <iostream>
#include <SFML/Graphics.hpp>
#define SCREEN_WIDTH 200
#define SCREEN_HEIGHT 200
#define BIT_DEPTH 32
int main() {
sf::RenderWindow renderWindow(
sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, BIT_DEPTH),
"CircleShape test");
float radius = 10;
int pointCount = 4;
sf::CircleShape circle;
while (renderWindow.isOpen()) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
pointCount--;
std::cout << "radius=" << radius << "; pointCount=" << pointCount << std::endl;
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
pointCount++;
std::cout << "radius=" << radius << "; pointCount=" << pointCount << std::endl;
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
radius = (float) (((int) radius)-1);
std::cout << "radius=" << radius << "; pointCount=" << pointCount << std::endl;
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
radius = (float) (((int) radius)+1);
std::cout << "radius=" << radius << "; pointCount=" << pointCount << std::endl;
}
circle.setRadius(radius);
circle.setPointCount(pointCount);
sf::Event event;
while (renderWindow.pollEvent(event)) {
if (event.type == sf::Event::Closed
|| (event.type == sf::Event::KeyPressed
&& event.key.code == sf::Keyboard::Escape)) {
renderWindow.close();
}
}
renderWindow.clear();
renderWindow.draw(circle);
renderWindow.display();
sf::sleep(sf::seconds(0.1f));
}
return 0;
}
The condition is that given the radius and the pointCount, for every i greater than zero, CircleShape(radius, pointCount) equals bit-to-bit to CircleShape(radius, pointCount + i)
Ok, I didn't test it for every i greater than zero, but at least 20 values from the last change
radius -> pointCount
1 -> 5
2 -> 5
3 -> 14
4 -> 10
5 -> 22
6 -> 10
7 -> 32
8 -> 20
9 -> 18
10 -> 26
11 -> 51
12 -> 21
13 -> 64
14 -> 37
15 -> 71
It's kind of surprising for me, especially the change from 7 to 9 (it decreases).
Here's the code, if you want to repeat the test. Just use the arrows to increase or decrease both values:
#include <iostream>
#include <SFML/Graphics.hpp>
#define SCREEN_WIDTH 200
#define SCREEN_HEIGHT 200
#define BIT_DEPTH 32
int main() {
sf::RenderWindow renderWindow(
sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, BIT_DEPTH),
"CircleShape test");
float radius = 10;
int pointCount = 4;
sf::CircleShape circle;
while (renderWindow.isOpen()) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
pointCount--;
std::cout << "radius=" << radius << "; pointCount=" << pointCount << std::endl;
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
pointCount++;
std::cout << "radius=" << radius << "; pointCount=" << pointCount << std::endl;
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
radius = (float) (((int) radius)-1);
std::cout << "radius=" << radius << "; pointCount=" << pointCount << std::endl;
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
radius = (float) (((int) radius)+1);
std::cout << "radius=" << radius << "; pointCount=" << pointCount << std::endl;
}
circle.setRadius(radius);
circle.setPointCount(pointCount);
sf::Event event;
while (renderWindow.pollEvent(event)) {
if (event.type == sf::Event::Closed
|| (event.type == sf::Event::KeyPressed
&& event.key.code == sf::Keyboard::Escape)) {
renderWindow.close();
}
}
renderWindow.clear();
renderWindow.draw(circle);
renderWindow.display();
sf::sleep(sf::seconds(0.1f));
}
return 0;
}