full Circle with cos sin and set(x,y,c)
in
Programming Questions
•
7 months ago
Hello all,
I want draw a circle with this method, but I've a lot of hole in my disc, if anybody have an idea to make a real full disc, I take it.
I want draw a circle with this method, but I've a lot of hole in my disc, if anybody have an idea to make a real full disc, I take it.
- color c = color(255) ;
//diameter of circle
int diam = 200 ;
void setup()
{
background(0) ;
size( 300,300 ) ;
colorMode(HSB, 360, 100, 100 ) ;
fill(255) ;
}
void draw()
{
background(0) ;
PVector pos = new PVector( mouseX, mouseY ) ;
//make cirlce
//circle(pos, diam) ;
//make a disc
disc(pos, diam) ;
//chromaticCircle(pos, diam) ;
//chromaticDisc(pos, diam) ;
}
//DISC
void disc( PVector pos, int diam )
{
for ( int i = 1 ; i < diam +1 ; i++) {
circle(pos, i) ;
}
}
//CIRCLE
//classic
void circle(PVector pos, int d)
{
int surface = d*d ; // surface is equale of square surface where is the circle.
int radius = ceil(radiusSurface(surface)) ;
int numPoints = ceil(perimeterCircle( radius)) ;
for(int i=0; i < numPoints; i++) {
float stepAngle = map(i, 0, numPoints, 0, 2*PI) ;
float angle = 2*PI - stepAngle;
set(int(pointOnCirlcle(pos, radius, angle).x + pos.x) , int(pointOnCirlcle(pos, radius, angle).y + pos.y), c);
}
}
//POINT
PVector pointOnCirlcle(PVector pos, int r, float angle)
{
PVector posPix = new PVector () ;
posPix.x = cos(angle) *r ;
posPix.y = sin(angle) *r ;
return posPix ;
}
//EQUATION
float perimeterCircle ( int r )
{
//calcul du perimetre
float p = 2*r*PI ;
return p ;
}
//EQUATION
float radiusSurface(int s)
{
// calcul du rayon par rapport au nombre de point
float r = sqrt(s/PI) ;
return r ;
}
1