Drawing Triangles OOP - ZackWilde27/Z3dPy GitHub Wiki

Once you've got your rastered triangles:

for tri in z3dpyOOP.RasterThings([myThing, myOtherThing], myCamera):

My module has shortcuts for drawing triangles to a pygame or tkinter screen.

# Uses the float for each channel, producing greyscale
z3dpyOOP.PgDrawTriangleF(tri, float, surface, pygame)

# Multiplies the float by the colour of the triangle to shade it
z3dpyOOP.PgDrawTriangleS(tri, float, surface, pygame)

# Draws the triangle with the specified colour as a vector
z3dpyOOP.PgDrawTriangleRGB(tri, vColour, surface, pygame)

# Same as RGB, but converts 0-1 to 0-255
z3dpyOOP.PgDrawTriangleRGBF(tri, VColour, surface, pygame)

# Same as RGBF, but draws an outline
z3dpyOOP.PgDrawTriangleOutl(tri, VColour, surface, pygame)

But, you may need to draw them manually, in which case:

PyGame

white = (255, 255, 255)

pygame.draw.polygon(screen, white, [(tri.p1.x, tri.p1.y), (tri.p2.x, tri.p2.y), (tri.p3.x, tri.p3.y)])

Tkinter

canvas.create_polygon([tri.p1.x, tri.p1.y, tri.p2.x, tri.p2.y, tri.p3.x, tri.p3.y], fill='white')

Graphics.py

points = [Point(tri.p1.x, tri.p1.y), Point(tri.p2.x, tri.p2.y), Point(tri.p3.x, tri.p3.y)]

triangle = Polygon(points)
triangle.setFill('white')
triangle.draw(win)