optimize drawing routines slightly
This commit is contained in:
parent
03f3245721
commit
dd8bd07d1e
@ -94,17 +94,24 @@ class SketchWidget:
|
|||||||
shape.vars[2], shape.vars[3], size)
|
shape.vars[2], shape.vars[3], size)
|
||||||
|
|
||||||
def drawCircle(self, shape, size):
|
def drawCircle(self, shape, size):
|
||||||
steps = 24
|
steps = 16
|
||||||
|
step = 2 * math.pi / steps
|
||||||
for i in range(steps + 1):
|
for i in range(steps + 1):
|
||||||
angle = i * 2 * math.pi / steps
|
angle = i * step
|
||||||
next_angle = (i + 1) * 2 * math.pi / steps
|
next_angle = (i + 1) * step
|
||||||
self.drawFilledLine(shape.vars[0] + shape.vars[2] * math.cos(angle),
|
x0 = shape.vars[0] + shape.vars[2] * math.cos(angle)
|
||||||
shape.vars[1] + shape.vars[2] * math.sin(angle),
|
y0 = shape.vars[1] + shape.vars[2] * math.sin(angle)
|
||||||
shape.vars[0] + shape.vars[2] * math.cos(next_angle),
|
x1 = shape.vars[0] + shape.vars[2] * math.cos(next_angle)
|
||||||
shape.vars[1] + shape.vars[2] * math.sin(next_angle),
|
y1 = shape.vars[1] + shape.vars[2] * math.sin(next_angle)
|
||||||
size)
|
self.drawFilledLineUncapped(x0, y0, x1, y1, size)
|
||||||
|
self.drawFilledCircle(x0, y0, size, 8)
|
||||||
|
|
||||||
def drawFilledLine(self, x0, y0, x1, y1, size):
|
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)
|
glBegin(GL_QUADS)
|
||||||
angle = math.atan2(y1 - y0, x1 - x0)
|
angle = math.atan2(y1 - y0, x1 - x0)
|
||||||
ninety = math.pi / 2
|
ninety = math.pi / 2
|
||||||
@ -117,8 +124,6 @@ class SketchWidget:
|
|||||||
glVertex(x1 + x_right, y1 + y_right)
|
glVertex(x1 + x_right, y1 + y_right)
|
||||||
glVertex(x1 + x_left, y1 + y_left)
|
glVertex(x1 + x_left, y1 + y_left)
|
||||||
glEnd()
|
glEnd()
|
||||||
self.drawFilledCircle(x0, y0, size, 16)
|
|
||||||
self.drawFilledCircle(x1, y1, size, 16)
|
|
||||||
|
|
||||||
def drawFilledCircle(self, x, y, radius, steps):
|
def drawFilledCircle(self, x, y, radius, steps):
|
||||||
glBegin(GL_TRIANGLE_FAN)
|
glBegin(GL_TRIANGLE_FAN)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user