1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include "Simple_window.h" // get access to our window library
#include "Graph.h" // get access to our graphics library facilities
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
//------------------------------------------------------------------------------
using namespace std;
using namespace Graph_lib; // our graphics facilities are in Graph_lib
int PI = 3.14159265359;
//int x_cor(){
// int x;
// int xc, t;
// t = 360 - rand()%360;
// xc = rand()%250;
// x = xc + cos(t);
// return x;
//}
//
//int y_cor(){
// int y;
// int yc, t;
// t = 360 - rand()%360;
// yc = rand()%250;
// y = yc + sin(t);
// return y;
//}
//int radius(int radius, int n){
// int r;
// r = 250*sin(PI/n)/(1 + sin(PI/n));
// return r;
//}
int main(){
srand(time(0));
Point tl(0,0); // to become top left corner of window
Simple_window win(tl,500,500,"Canvas"); // make a simple window
const int max_radius{ 200 };
Circle outer( {500 / 2, 500 / 2 }, max_radius );
outer.set_color(rand() % 243 + 23);
outer.set_style( Line_style{ Line_style::solid, 3 } );
win.attach( outer );
while(true){
int n;
cout << "Enter Number of Cycles: ";
cin >> n;
if (n <= 0) break;
for (int i = 0; i < n; i++){
int genrand = rand ();
const int rand_radius{ genrand * ( 1, max_radius ) };
// x_bounds[]{ { outer.center( ).x - outer.radius( ) + rand_radius },
// { outer.center( ).x + outer.radius( ) - rand_radius } },
// y_bounds[]{ { outer.center( ).y - outer.radius( ) + rand_radius },
// { outer.center( ).y + outer.radius( ) - rand_radius } };
Circle boundary (Point(250, 250) , max_radius - rand_radius );
boundary.set_color(rand() % 243 + 23);
boundary.set_style( { Line_style::solid, 2 } );
win.attach( boundary );
Vector_ref<Circle> rand_circles;
const int num_circles{ 20 };
for( int i{}; i < num_circles; i++ ) {
const int rand_radius{ genrand*( 1, max_radius ) },
rand_angle = genrand*( 1, 360 ) / 180.0 * M_PI,
x0 = (max_radius - rand_radius) * cos( rand_angle ) + outer.center( ).x,
y0 = (max_radius - rand_radius) * sin( rand_angle ) + outer.center( ).y;
Circle* rand_circle{ new Circle{ { x0, y0 }, rand_radius } };
rand_circle->set_color(rand() % 243 + 23);
rand_circles.push_back( rand_circle );
}
for( int i{}; i < rand_circles.size( ); i++ )
win.attach( rand_circles[i] );
}
win.wait_for_button(); // give control to the display engine
}
return 0;
}
//------------------------------------------------------------------------------
| |