-
-
Save eddietree/74a0b519e207ddfd8da1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void DrawCircle(int texture_size_x, int texture_size_y, int center_x, int center_y, int r, Color color) | |
{ | |
// basically, find out the box around the circle | |
// iterate inside the box only for optimziation | |
int box_x_min = max(0, center_x - r); | |
int box_y_min = max(0, center_y - r); | |
int box_x_max = min(texture_size_x, center_x + r); | |
int box_y_max = min(texture_size_y, center_y + r); | |
// go thru each position within the box that surrounds the circle | |
for ( int x = box_x_min; x <= box_x_max; ++x ) | |
{ | |
for ( int y = box_y_min; y <= box_y_max; ++y ) | |
{ | |
// calculate distance from current point to the center of the circle | |
// if the distance is less than the radius, that means you are *inside* the circle, so color that shit BLACK | |
float x_diff = x - center_x; | |
float y_diff = y - center_y; | |
float length = Math.sqrt( x_diff*x_diff + y_diff*y_diff ); | |
// test if inside circle | |
if ( length < r ) | |
{ | |
newTex.SetPixel(x,y,color); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment