adding number generation modes for circle and rectangle
This commit is contained in:
parent
e78cf39d6d
commit
ea1461c1ae
35
main.cpp
35
main.cpp
@ -42,10 +42,32 @@ int main (int argc, char **argv)
|
||||
std::cout << "generating random numbers..." << std::endl;
|
||||
//srand(static_cast <unsigned> (time(0)));
|
||||
srand(static_cast <unsigned> (0)); // fixed seed for testing
|
||||
|
||||
// 2) rectangle
|
||||
//float diff = (2.f * HEIGHT / valCount);
|
||||
|
||||
// 3) circle
|
||||
//float rad = HEIGHT / 2; //8.0f;
|
||||
//float deg = (float)(2 * 3.14159 / valCount);
|
||||
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
for (int i = 0; i < valCount; ++i)
|
||||
{
|
||||
float x = OFFSET + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (WIDTH - OFFSET)));
|
||||
float y = OFFSET + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (HEIGHT - OFFSET)));
|
||||
// 1) random generation
|
||||
//x = OFFSET + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (WIDTH - OFFSET)));
|
||||
//y = OFFSET + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (HEIGHT - OFFSET)));
|
||||
x = OFFSET + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (WIDTH - 2*OFFSET)));
|
||||
y = OFFSET + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (HEIGHT - 2*OFFSET)));
|
||||
|
||||
// 2) rectangle
|
||||
//x = (i%2 == 0) ? OFFSET : WIDTH - OFFSET;
|
||||
//y = diff/2 + (i/2) * diff;
|
||||
|
||||
// 3) position in circle around center, x/y plane
|
||||
//x = WIDTH/2 + rad * cosf(i * deg);
|
||||
//y = HEIGHT/2 + rad * sinf(i * deg);
|
||||
|
||||
points.push_back(Point(x, y));
|
||||
}
|
||||
}
|
||||
@ -78,7 +100,7 @@ int main (int argc, char **argv)
|
||||
}
|
||||
|
||||
// TODO: sort here, once and for all? xD
|
||||
sortPoints(points);
|
||||
//sortPoints(points);
|
||||
for (Point& pt : points)
|
||||
{
|
||||
std::cout << "pt: " << pt.x() << ", " << pt.y() << std::endl;
|
||||
@ -86,13 +108,10 @@ int main (int argc, char **argv)
|
||||
|
||||
if (vis)
|
||||
{
|
||||
// TODO: use data as ctor argument? pointer?
|
||||
|
||||
// TEST to check SFML coordinate system
|
||||
points.push_back(Point(0, 0));
|
||||
//points.push_back(Point(0, 0));
|
||||
|
||||
Display display;
|
||||
display.setData(points);
|
||||
Display display(points);
|
||||
display.show();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user