From ea1461c1ae0f2bc71510ef50f50f16aa3733c35a Mon Sep 17 00:00:00 2001 From: incredibleLeitman Date: Fri, 27 Nov 2020 03:08:37 +0100 Subject: [PATCH] adding number generation modes for circle and rectangle --- main.cpp | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/main.cpp b/main.cpp index f5f416d..f6d3240 100644 --- a/main.cpp +++ b/main.cpp @@ -42,10 +42,32 @@ int main (int argc, char **argv) std::cout << "generating random numbers..." << std::endl; //srand(static_cast (time(0))); srand(static_cast (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 (rand()) / (static_cast (RAND_MAX / (WIDTH - OFFSET))); - float y = OFFSET + static_cast (rand()) / (static_cast (RAND_MAX / (HEIGHT - OFFSET))); + // 1) random generation + //x = OFFSET + static_cast (rand()) / (static_cast (RAND_MAX / (WIDTH - OFFSET))); + //y = OFFSET + static_cast (rand()) / (static_cast (RAND_MAX / (HEIGHT - OFFSET))); + x = OFFSET + static_cast (rand()) / (static_cast (RAND_MAX / (WIDTH - 2*OFFSET))); + y = OFFSET + static_cast (rand()) / (static_cast (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(); }