Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@RavensKrag
Created December 20, 2013 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RavensKrag/8050038 to your computer and use it in GitHub Desktop.
Save RavensKrag/8050038 to your computer and use it in GitHub Desktop.
Code to draw a circle.
$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