Created
December 20, 2013 03:32
-
-
Save RavensKrag/8050038 to your computer and use it in GitHub Desktop.
Code to draw a circle.
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
$window.gl z do | |
glPushMatrix() | |
glTranslatef(self.body.p.x, self.body.p.y, 0) | |
glBegin(GL_TRIANGLE_FAN) | |
glColor4ub(color.red, color.green, color.blue, color.alpha) | |
iterations = 60 # maybe high iterations cause crashes? | |
rotation_angle = 2*Math::PI / iterations # radians | |
rotation_vector = CP::Vec2.for_angle rotation_angle | |
vec = CP::Vec2.new(self.radius, 0) | |
# center | |
glVertex2f(0, 0) | |
# verts on the edge of the circle | |
(iterations+1).times do # extra iteration to loop back to start | |
glVertex2f(vec.x, vec.y) | |
vec = vec.rotate rotation_vector | |
end | |
glEnd() | |
glPopMatrix() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment