#!/usr/bin/env python

import stlwrite as stl

def example():
    def get_cube():
        # cube corner points
        s = 3.
        p1 = (0, 0, 0)
        p2 = (0, 0, s)
        p3 = (0, s, 0)
        p4 = (0, s, s)
        p5 = (s, 0, 0)
        p6 = (s, 0, s)
        p7 = (s, s, 0)
        p8 = (s, s, s)

        # define the 6 cube faces with points in clockwise order
        return [
            [p1, p5, p7, p3],
            [p1, p2, p6, p5],
            [p5, p6, p8, p7],
            [p7, p8, p4, p3],
            [p1, p3, p4, p2],
            [p2, p4, p8, p6],
        ]

    filename = 'cube.stl'
    with open(filename, 'wb') as fp:
        writer = stl.ASCII_STL_Writer(fp)
        writer.add_faces(get_cube())
        writer.close()
    print 'Wrote ' + filename

if __name__ == '__main__':
    example()
