2018-11-22 17:56:35 +00:00
|
|
|
import pyglet
|
|
|
|
from svgpathtools import Line, CubicBezier, QuadraticBezier, Path
|
|
|
|
|
|
|
|
class GenericRenderer:
|
|
|
|
globalRenderer = None
|
|
|
|
|
2018-12-14 21:28:28 +00:00
|
|
|
def __init__(self, debug):
|
|
|
|
self.debug = debug
|
|
|
|
if debug:
|
|
|
|
# Make a new window to render into
|
|
|
|
self.window = pyglet.window.Window()
|
|
|
|
self.window.set_size(1000, 1000)
|
|
|
|
self.window.set_location(300, 0)
|
|
|
|
pyglet.gl.glClearColor(0.4, 0.4, 0.4, 1)
|
2018-11-22 17:56:35 +00:00
|
|
|
|
|
|
|
self.lineBatch = pyglet.graphics.Batch()
|
|
|
|
self.pointBatch = pyglet.graphics.Batch()
|
|
|
|
|
2018-12-01 20:47:13 +00:00
|
|
|
pyglet.gl.glLineWidth(2)#2
|
2018-11-23 18:14:26 +00:00
|
|
|
pyglet.gl.glPointSize(4)
|
2018-11-22 17:56:35 +00:00
|
|
|
|
2018-12-14 21:28:28 +00:00
|
|
|
#self.addLine(Line(start=(0+0j), end=(1000+1000j)), 255, 0, 0)
|
2018-11-22 17:56:35 +00:00
|
|
|
|
|
|
|
GenericRenderer.globalRenderer = self
|
|
|
|
|
|
|
|
def addLine(self, line, r, g, b):
|
|
|
|
self.lineBatch.add(2, pyglet.gl.GL_LINES, None,
|
2018-11-23 18:14:26 +00:00
|
|
|
('v2f', (line.start.real, 1000 - line.start.imag, line.end.real, 1000 - line.end.imag)),
|
2018-11-22 17:56:35 +00:00
|
|
|
('c3B', (r,g,b, r,g,b))
|
|
|
|
)
|
|
|
|
def addPath(self, path, r, g, b):
|
|
|
|
for shape in path:
|
|
|
|
for x in range(0, 99):
|
|
|
|
x1 = x / 100.0
|
|
|
|
x2 = x1 + 0.01
|
|
|
|
self.addLine(Line(start=shape.point(x1), end=shape.point(x2)), r, g, b)
|
|
|
|
|
|
|
|
def addPoint(self, point, r, g, b):
|
|
|
|
self.pointBatch.add(1, pyglet.gl.GL_POINTS, None,
|
2018-11-23 18:14:26 +00:00
|
|
|
('v2f', (point.real, 1000 - point.imag)),
|
2018-11-22 17:56:35 +00:00
|
|
|
('c3B', (r, g, b))
|
|
|
|
)
|
|
|
|
|
2018-11-30 13:20:26 +00:00
|
|
|
def clearAll(self):
|
|
|
|
self.lineBatch = pyglet.graphics.Batch()
|
|
|
|
self.pointBatch = pyglet.graphics.Batch()
|
|
|
|
|
2018-11-22 17:56:35 +00:00
|
|
|
def updateDisplay(self, s):
|
|
|
|
self.window.clear()
|
|
|
|
self.lineBatch.draw()
|
|
|
|
self.pointBatch.draw()
|
|
|
|
|
|
|
|
def runLoop(self):
|
2018-12-14 21:28:28 +00:00
|
|
|
if self.debug:
|
|
|
|
pyglet.clock.schedule_interval(self.updateDisplay, 1 / 30.0)
|
|
|
|
pyglet.app.run()
|
2018-11-22 17:56:35 +00:00
|
|
|
|