def AddGraph(self): polygon = Polygon(parent=self) color = (1.0, 1.0, 1.0, 0.3) polygon.color = color ro = polygon.GetRenderObject() thisWidth, thisHeight = self.GetAbsoluteSize() count = len(self.data) for i in xrange(count): vert1 = trinity.Tr2Sprite2dVertex() vert1.position = (GetGraphX(i, count, thisWidth), thisHeight) vert1.color = color ro.vertices.append(vert1) vert2 = trinity.Tr2Sprite2dVertex() vert2.position = (GetGraphX(i, count, thisWidth), GetGraphY(self.data[i], self.minimum, self.maximum, thisHeight)) vert2.color = color ro.vertices.append(vert2) for i in xrange(count - 1): triangle1 = trinity.Tr2Sprite2dTriangle() triangle1.index0 = 2 * i triangle1.index1 = 2 * i + 1 triangle1.index2 = 2 * i + 2 ro.triangles.append(triangle1) triangle2 = trinity.Tr2Sprite2dTriangle() triangle2.index0 = 2 * i + 1 triangle2.index1 = 2 * i + 3 triangle2.index2 = 2 * i + 2 ro.triangles.append(triangle2)
def RenderGradient(self): self.polygon.Flush() directionAngle = math.pi / 2 fromDeg = directionAngle - self.angle / 2 toDeg = directionAngle + self.angle / 2 numSegments = 40 segmentStep = (toDeg - fromDeg) / float(numSegments) c = self.color innerColor = c outerColor = (c[0], c[1], c[2], 0.0) radius = 50 ro = self.polygon.GetRenderObject() for i in xrange(numSegments + 1): a = fromDeg + i * segmentStep x = math.cos(a) y = -math.sin(a) innerVertex = trinity.Tr2Sprite2dVertex() innerVertex.position = (self.width / 2 * uicore.desktop.dpiScaling, self.height / 2 * uicore.desktop.dpiScaling) innerVertex.color = innerColor ro.vertices.append(innerVertex) outerVertex = trinity.Tr2Sprite2dVertex() outerVertex.position = ((self.width / 2 + radius * x) * uicore.desktop.dpiScaling, (self.height / 2 + radius * y) * uicore.desktop.dpiScaling) outerVertex.color = outerColor ro.vertices.append(outerVertex) for i in xrange(numSegments * 2): triangle = trinity.Tr2Sprite2dTriangle() triangle.index0 = i triangle.index1 = i + 1 triangle.index2 = i + 2 ro.triangles.append(triangle)
def MakeCircle(self, radius = 64.0, segments = 12, centerColor = default_color, edgeColor = default_color): ro = self.GetRenderObject() del ro.triangles[:] del ro.vertices[:] centerVertex = trinity.Tr2Sprite2dVertex() centerVertex.position = (radius, radius) centerVertex.color = centerColor centerVertex.texCoord0 = (0.5, 0.5) centerVertex.texCoord1 = (0.5, 0.5) ro.vertices.append(centerVertex) for i in xrange(segments): a = math.pi * 2.0 / float(segments) * float(i) x = math.cos(a) y = math.sin(a) edgeVertex = trinity.Tr2Sprite2dVertex() edgeVertex.position = (x * radius + radius, y * radius + radius) edgeVertex.color = edgeColor edgeVertex.texCoord0 = (x * 0.5 + 0.5, y * 0.5 + 0.5) edgeVertex.texCoord1 = edgeVertex.texCoord0 ro.vertices.append(edgeVertex) for i in xrange(segments - 1): triangle = trinity.Tr2Sprite2dTriangle() triangle.index0 = 0 triangle.index1 = i + 1 triangle.index2 = i + 2 ro.triangles.append(triangle) triangle = trinity.Tr2Sprite2dTriangle() triangle.index0 = 0 triangle.index1 = segments triangle.index2 = 1 ro.triangles.append(triangle)
def MakeGradient(self, width=256, height=256, colorPoints=[(0, (0, 0, 0, 1)), (1, (1, 1, 1, 1))], rotation=0): ro = self.GetRenderObject() del ro.triangles[:] del ro.vertices[:] startPoint = colorPoints[0] startValue = startPoint[0] startColor = startPoint[1] topLeft = (startValue, 0) bottomLeft = (startValue, height) vertex = trinity.Tr2Sprite2dVertex() vertex.position = topLeft vertex.color = startColor vertex.texCoord0 = (0, 0) vertex.texCoord1 = (0, 0) ro.vertices.append(vertex) vertex = trinity.Tr2Sprite2dVertex() vertex.position = bottomLeft vertex.color = startColor vertex.texCoord0 = (0, 1) vertex.texCoord1 = (0, 1) ro.vertices.append(vertex) baseIx = 0 for i in xrange(len(colorPoints) - 1): endPoint = colorPoints[i + 1] endValue = endPoint[0] endColor = endPoint[1] topLeft = (endValue * width, 0) bottomLeft = (endValue * width, height) vertex = trinity.Tr2Sprite2dVertex() vertex.position = topLeft vertex.color = endColor vertex.texCoord0 = (endValue, 0) vertex.texCoord1 = (endValue, 0) ro.vertices.append(vertex) vertex = trinity.Tr2Sprite2dVertex() vertex.position = bottomLeft vertex.color = endColor vertex.texCoord0 = (endValue, 1) vertex.texCoord1 = (endValue, 1) ro.vertices.append(vertex) triangle = trinity.Tr2Sprite2dTriangle() triangle.index0 = baseIx + 0 triangle.index1 = baseIx + 1 triangle.index2 = baseIx + 2 ro.triangles.append(triangle) triangle = trinity.Tr2Sprite2dTriangle() triangle.index0 = baseIx + 1 triangle.index1 = baseIx + 2 triangle.index2 = baseIx + 3 ro.triangles.append(triangle) baseIx += 2 startValue = endValue startColor = endColor
def MakeSegmentedRectangle(self, segments, tex): ro = self.GetRenderObject() del ro.triangles[:] del ro.vertices[:] self.texture = tex width = tex.atlasTexture.width height = tex.atlasTexture.height step = float(width) / float(segments) ustep = 1.0 / float(segments) x = 0.0 u = 0.0 yTop = 0.0 yBottom = float(height) vTop = 0.0 vBottom = 1.0 color = (1, 1, 1, 1) vertex = trinity.Tr2Sprite2dVertex() vertex.position = (x, yTop) vertex.color = color vertex.texCoord0 = (u, vTop) vertex.texCoord1 = (u, vTop) ro.vertices.append(vertex) vertex = trinity.Tr2Sprite2dVertex() vertex.position = (x, yBottom) vertex.color = color vertex.texCoord0 = (u, vBottom) vertex.texCoord1 = (u, vBottom) ro.vertices.append(vertex) baseIx = 0 for i in xrange(segments): x += step u += ustep vertex = trinity.Tr2Sprite2dVertex() vertex.position = (x, yTop) vertex.color = color vertex.texCoord0 = (u, vTop) vertex.texCoord1 = (u, vTop) ro.vertices.append(vertex) vertex = trinity.Tr2Sprite2dVertex() vertex.position = (x, yBottom) vertex.color = color vertex.texCoord0 = (u, vBottom) vertex.texCoord1 = (u, vBottom) ro.vertices.append(vertex) triangle = trinity.Tr2Sprite2dTriangle() triangle.index0 = baseIx + 0 triangle.index1 = baseIx + 1 triangle.index2 = baseIx + 2 ro.triangles.append(triangle) triangle = trinity.Tr2Sprite2dTriangle() triangle.index0 = baseIx + 1 triangle.index1 = baseIx + 2 triangle.index2 = baseIx + 3 ro.triangles.append(triangle) baseIx += 2
def MakeArc(self, radius = 32.0, outerRadius = 66.0, segments = 12, fromDeg = 0.0, toDeg = 90.0, innerColor = default_color, outerColor = default_color, feather = 3.0): self.Flush() ro = self.GetRenderObject() segmentStep = (toDeg - fromDeg) / float(segments) TRANSPCOLOR = (0, 0, 0, 0) for i in xrange(segments + 1): a = mathUtil.DegToRad(fromDeg + i * segmentStep) x = math.cos(a) y = math.sin(a) innerVertex = trinity.Tr2Sprite2dVertex() innerVertex.position = (x * radius, y * radius) innerVertex.color = innerColor ro.vertices.append(innerVertex) outerVertex = trinity.Tr2Sprite2dVertex() outerVertex.position = (x * outerRadius, y * outerRadius) outerVertex.color = outerColor ro.vertices.append(outerVertex) for i in xrange(segments * 2): triangle = trinity.Tr2Sprite2dTriangle() triangle.index0 = i triangle.index1 = i + 1 triangle.index2 = i + 2 ro.triangles.append(triangle) if feather: shift = len(ro.vertices) for i in xrange(segments + 1): a = mathUtil.DegToRad(fromDeg + i * segmentStep) x = math.cos(a) y = math.sin(a) innerFeatherVertex = trinity.Tr2Sprite2dVertex() innerFeatherVertex.position = (x * (radius - feather), y * (radius - feather)) innerFeatherVertex.color = TRANSPCOLOR ro.vertices.append(innerFeatherVertex) outerFeatherVertex = trinity.Tr2Sprite2dVertex() outerFeatherVertex.position = (x * (outerRadius + feather), y * (outerRadius + feather)) outerFeatherVertex.color = TRANSPCOLOR ro.vertices.append(outerFeatherVertex) for i in xrange(segments * 2): triangle = trinity.Tr2Sprite2dTriangle() triangle.index0 = i triangle.index1 = shift + i triangle.index2 = shift + i + 2 ro.triangles.append(triangle) triangle = trinity.Tr2Sprite2dTriangle() triangle.index0 = shift + i + 2 triangle.index1 = i + 2 triangle.index2 = i ro.triangles.append(triangle)
def MakeRectangle(self, topLeft=(0, 0), topLeftColor=(1, 1, 1, 1), topRight=(64, 0), topRightColor=(1, 1, 1, 1), bottomRight=(64, 64), bottomRightColor=(1, 1, 1, 1), bottomLeft=(0, 64), bottomLeftColor=(1, 1, 1, 1)): ro = self.GetRenderObject() del ro.triangles[:] del ro.vertices[:] vertex = trinity.Tr2Sprite2dVertex() vertex.position = topLeft vertex.color = topLeftColor vertex.texCoord0 = (0, 0) vertex.texCoord1 = (0, 0) ro.vertices.append(vertex) vertex = trinity.Tr2Sprite2dVertex() vertex.position = topRight vertex.color = topRightColor vertex.texCoord0 = (1, 0) vertex.texCoord1 = (1, 0) ro.vertices.append(vertex) vertex = trinity.Tr2Sprite2dVertex() vertex.position = bottomRight vertex.color = bottomRightColor vertex.texCoord0 = (1, 1) vertex.texCoord1 = (1, 1) ro.vertices.append(vertex) vertex = trinity.Tr2Sprite2dVertex() vertex.position = bottomLeft vertex.color = bottomLeftColor vertex.texCoord0 = (0, 1) vertex.texCoord1 = (0, 1) ro.vertices.append(vertex) triangle = trinity.Tr2Sprite2dTriangle() triangle.index0 = 0 triangle.index1 = 1 triangle.index2 = 2 ro.triangles.append(triangle) triangle = trinity.Tr2Sprite2dTriangle() triangle.index0 = 0 triangle.index1 = 2 triangle.index2 = 3 ro.triangles.append(triangle)
def Build(self): donchianLowData, donchianHighData = self.data maxValue = self.maxValue if maxValue == 0: maxValue = max(donchianHighData) width, height = self.GetAbsoluteSize() verticalScale = height / maxValue n = len(donchianHighData) step = float(width) / (n - 1) renderObject = self.GetRenderObject() x0 = 0 n = len(donchianLowData) for i in xrange(n - 1): highLeft = donchianHighData[i] lowLeft = donchianLowData[i] highRight = donchianHighData[i + 1] lowRight = donchianLowData[i + 1] x1 = x0 + step topLeft = trinity.Tr2Sprite2dVertex() topLeft.position = (x0, height - highLeft * verticalScale) renderObject.vertices.append(topLeft) topRight = trinity.Tr2Sprite2dVertex() topRight.position = (x1, height - highRight * verticalScale) renderObject.vertices.append(topRight) bottomRight = trinity.Tr2Sprite2dVertex() bottomRight.position = (x1, height - lowRight * verticalScale) renderObject.vertices.append(bottomRight) bottomLeft = trinity.Tr2Sprite2dVertex() bottomLeft.position = (x0, height - lowLeft * verticalScale) renderObject.vertices.append(bottomLeft) x0 = x1 for i in xrange(n - 1): t1 = trinity.Tr2Sprite2dTriangle() t1.index0 = i * 4 t1.index1 = i * 4 + 1 t1.index2 = i * 4 + 2 t2 = trinity.Tr2Sprite2dTriangle() t2.index0 = i * 4 t2.index1 = i * 4 + 2 t2.index2 = i * 4 + 3 renderObject.triangles.append(t1) renderObject.triangles.append(t2)
def Build(self): low = MovingLow(self.data[0], 5) hi = MovingHigh(self.data[1], 5) maximum = max(max(self.data[0]), max(self.data[1])) minimum = min(min(self.data[0]), min(self.data[1])) color = (self.color.r, self.color.g, self.color.b, self.color.a) ro = self.GetRenderObject() width, height = self.graphContainer.GetAbsoluteSize() count = len(self.data[0]) for i in xrange(count): if self.axis is None: hiY = GetGraphY(hi[i], minimum, maximum, height) lowY = GetGraphY(low[i], minimum, maximum, height) else: hiY = self.axis.GetAxisValue(hi[i]) lowY = self.axis.GetAxisValue(low[i]) x = GetGraphX(i, width, self.zoom) vert1 = trinity.Tr2Sprite2dVertex() vert1.position = (x, hiY) vert1.color = color ro.vertices.append(vert1) vert2 = trinity.Tr2Sprite2dVertex() vert2.position = (x, lowY) vert2.color = color ro.vertices.append(vert2) for i in xrange(count - 1): triangle1 = trinity.Tr2Sprite2dTriangle() triangle1.index0 = 2 * i triangle1.index1 = 2 * i + 1 triangle1.index2 = 2 * i + 2 ro.triangles.append(triangle1) triangle2 = trinity.Tr2Sprite2dTriangle() triangle2.index0 = 2 * i + 1 triangle2.index1 = 2 * i + 3 triangle2.index2 = 2 * i + 2 ro.triangles.append(triangle2) self.AddAnimation()