I have created a loop using processing that draws circles, the overall shape should be a circle. However they are mainly drawn close to X and Y axis. I have randomized the angle for the calculus of its location, I cannot see where the problem is.
Code as follows:
for (int omega = 0; omega<1080; omega++){ //loop for circle creation
radius = (int)random(80); //random radius for each circle
int color1= (int)random(100); //little variation of color for each circle
int color2= (int)random(100);
int locationY = (int)(sin(radians(omega))*random(width/2+1)); //location calcualtion
int locationX = (int)(cos(radians(omega))*random(width/2+1));
fill(0,color1+200,color2+200,50);
ellipse(locationX,locationY,radius,radius); //draw circles
}
Good point @Durandal (+1)
However I have one more thought with random circles.
When you generate random distance with such code:
double distance = random( width/2 );
you random from uniform distribution. I mean all values from 0
to width/2
have the same probability. But circle with 3*r
radius have 9
times bigger area then circle with r
radius. So, the smaller distance from center, the greater density we can see.
This way generated cloud do not have uniform density as you can see on first image.
But if you change the probability density function in such way that bigger values are less probable that smaller ones you can get uniformly generated cloud.
Such simple modification:
double distance = Math.sqrt( random( width/2 * width/2 ) );
produces more uniformly distributed circles, as you can see on second image.
I hope this can be helpful..
Its an artefact of the way you calculate location, you're pulling two different random values for the X and Y component:
int locationY = (int)(sin(radians(omega))*random(width/2+1)); //location calcualtion
int locationX = (int)(cos(radians(omega))*random(width/2+1));
You should use one random value "distance" from the center for both X and Y, that will remove the clustering towards the axes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With