Skip to content

Instantly share code, notes, and snippets.

@edwonedwon
Created June 12, 2015 04:28
Show Gist options
  • Save edwonedwon/1948630415ad8e2ff898 to your computer and use it in GitHub Desktop.
Save edwonedwon/1948630415ad8e2ff898 to your computer and use it in GitHub Desktop.
void DrawCircle(int x, int y, int r, Color color)
{
// how many segments you want in circle
int num_segments = 128;
float radius = r; // radius of circle
Vector2 center_pos = new Vector2(x,y);
// change angle for each pos in circle
float delta_angle = 2.0f * Mathf.PI / (float)num_segments;
// points in a circle
for( int i = 0; i < num_segments; ++i )
{
// current angle
float curr_angle = i * delta_angle;
// direction from center of circle, normalized
Vector2 dir = new Vector2( Mathf.Cos(curr_angle), Mathf.Sin(curr_angle) );
Vector2 pos = center_pos + dir * radius;
newTex.SetPixel((int)pos.x,(int)pos.y,color);
}
}
@edwonedwon
Copy link
Author

how do I fill in the circle

@edwonedwon
Copy link
Author

even better how to do I make it glow / fade out around the edges

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment