MCPcopy Create free account
hub / github.com/csaez/mscreen / CurvePrim

Class CurvePrim

mscreen.py:264–336  ·  view source on GitHub ↗

Primitive representing poly-curves (arbitrary number of points).

Source from the content-addressed store, hash-verified

262
263# === Curve Primitive ===
264class CurvePrim(Primitive):
265 """
266 Primitive representing poly-curves (arbitrary number of points).
267 """
268 def __init__(self, points=None, degree=None, color=None, width=2):
269 super(CurvePrim, self).__init__()
270
271 # `width` of the curve, in pixels
272 self.width = width
273 # `color` of the curve (tuple of floats representing RGB components)
274 self.color = color or COLOR_BLACK
275 # `degree` represents the type of curve (i.e. linear or bezier)
276 self.degree = degree or CURVE_LINEAR
277
278 self._points = list() # control points
279 self._drawPoints = list() # drawable points
280 self._prePoints = list() # pre-transform points
281
282 if points:
283 self.points = points
284
285 # `points` are the control points of the curve.
286 @property
287 def points(self):
288 if self.isDirty:
289 self.update()
290 return self._points
291
292 @points.setter
293 def points(self, value):
294 self._prePoints = list(value)
295 self._drawPoints = list(value)
296 self.isDirty = True
297
298 def update(self):
299 super(CurvePrim, self).update()
300 self._points = []
301 matrix = self.transform.asMatrix()
302 for i in xrange(len(self._prePoints)):
303 point = om2.MPoint(self._prePoints[i])
304 point *= matrix
305 self._points.append(point)
306
307 if self.degree == CURVE_LINEAR:
308 self._drawPoints = [x for x in self._points]
309
310 elif self.degree == CURVE_BEZIER:
311 num_points = len(self._points)
312 segs = (num_points - 1) * 16
313 self._drawPoints = list()
314 for i in range(segs):
315 t = i/float(segs - 1)
316 p = bezierInterpolate(t, self._points)
317 self._drawPoints.append(p)
318
319 def draw(self, view, renderer):
320 super(CurvePrim, self).draw(view, renderer)
321

Callers 2

__init__Method · 0.85
drawCurveMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected