From dd8bd07d1ef5e65d97579f196a48eb35857f10c9 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 31 Mar 2011 22:30:58 -0400 Subject: [PATCH] optimize drawing routines slightly --- SketchWidget.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/SketchWidget.py b/SketchWidget.py index 3ecdbb3..656eed3 100644 --- a/SketchWidget.py +++ b/SketchWidget.py @@ -94,17 +94,24 @@ class SketchWidget: shape.vars[2], shape.vars[3], size) def drawCircle(self, shape, size): - steps = 24 + steps = 16 + step = 2 * math.pi / steps for i in range(steps + 1): - angle = i * 2 * math.pi / steps - next_angle = (i + 1) * 2 * math.pi / steps - self.drawFilledLine(shape.vars[0] + shape.vars[2] * math.cos(angle), - shape.vars[1] + shape.vars[2] * math.sin(angle), - shape.vars[0] + shape.vars[2] * math.cos(next_angle), - shape.vars[1] + shape.vars[2] * math.sin(next_angle), - size) + angle = i * step + next_angle = (i + 1) * step + x0 = shape.vars[0] + shape.vars[2] * math.cos(angle) + y0 = shape.vars[1] + shape.vars[2] * math.sin(angle) + x1 = shape.vars[0] + shape.vars[2] * math.cos(next_angle) + y1 = shape.vars[1] + shape.vars[2] * math.sin(next_angle) + self.drawFilledLineUncapped(x0, y0, x1, y1, size) + self.drawFilledCircle(x0, y0, size, 8) def drawFilledLine(self, x0, y0, x1, y1, size): + self.drawFilledLineUncapped(x0, y0, x1, y1, size) + self.drawFilledCircle(x0, y0, size, 16) + self.drawFilledCircle(x1, y1, size, 16) + + def drawFilledLineUncapped(self, x0, y0, x1, y1, size): glBegin(GL_QUADS) angle = math.atan2(y1 - y0, x1 - x0) ninety = math.pi / 2 @@ -117,8 +124,6 @@ class SketchWidget: glVertex(x1 + x_right, y1 + y_right) glVertex(x1 + x_left, y1 + y_left) glEnd() - self.drawFilledCircle(x0, y0, size, 16) - self.drawFilledCircle(x1, y1, size, 16) def drawFilledCircle(self, x, y, radius, steps): glBegin(GL_TRIANGLE_FAN)