67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
#include "Point.h"
|
|
|
|
#include <list>
|
|
#include <cstdlib> // for srand, rand
|
|
|
|
class NumberGenerator
|
|
{
|
|
public:
|
|
static std::list<Point> get_random_numbers(int valCount)
|
|
{
|
|
std::list<Point> points;
|
|
|
|
//srand(static_cast <unsigned> (time(0)));
|
|
srand(static_cast <unsigned> (0)); // fixed seed for testing
|
|
|
|
float x = 0;
|
|
float y = 0;
|
|
for (int i = 0; i < valCount; ++i)
|
|
{
|
|
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)));
|
|
|
|
points.push_back(Point(x, y));
|
|
}
|
|
|
|
return points;
|
|
}
|
|
|
|
static std::list<Point> get_rectangle_numbers(int valCount)
|
|
{
|
|
std::list<Point> points;
|
|
|
|
float diff = (2.f * HEIGHT/valCount);
|
|
|
|
float x = 0;
|
|
float y = 0;
|
|
for (int i = 0; i < valCount; ++i)
|
|
{
|
|
x = (i%2 == 0) ? OFFSET : WIDTH - OFFSET;
|
|
y = diff/2 + (i/2) * diff;
|
|
|
|
points.push_back(Point(x, y));
|
|
}
|
|
|
|
return points;
|
|
}
|
|
|
|
static std::list<Point> get_circle_numbers(int valCount)
|
|
{
|
|
std::list<Point> points;
|
|
|
|
float rad = HEIGHT/2;
|
|
float deg = (float)(2 * 3.14159 / valCount);
|
|
|
|
float x = 0;
|
|
float y = 0;
|
|
for (int i = 0; i < valCount; ++i)
|
|
{
|
|
x = WIDTH/2 + rad * cosf(i * deg);
|
|
y = HEIGHT/2 + rad * sinf(i * deg);
|
|
|
|
points.push_back(Point(x, y));
|
|
}
|
|
|
|
return points;
|
|
}
|
|
}; |