#!/usr/bin/env python

#ellipse_example.py

import math
from math import pi
import stlwrite
import csg

def frange(x, maximum, step):
    while x < maximum:
        yield x
        x += step

def get_ellipsoid(A,B,C,x0,y0,z0):
    " You fill in this code "
    return triangles

def get_duck_features():
    """Return a list of body parts. Each body part is a list of triangles
        generated by get_ellipsoid().  So the result is a list of lists
        of triangles.    """
    # You fill in this part
    return body_parts

def write_simple_duck():
    parts = get_duck_features()
    # Put all the triangles together in one big list.
    triangles = []
    for parts in get_duck_features():
        triangles.extend(parts)
    # Write the list as an STL file
    filename = "simple_duck.stl"
    with open(filename, 'wb') as fp:
        writer = stlwrite.ASCII_STL_Writer(fp)
        writer.add_faces(triangles)
        writer.close()
    print("Wrote " + filename)
    
def write_good_duck():
    filename = "duck_union.stl"
    # Do a mesh union of all the body parts
    body_parts = get_duck_features()
    good_mesh = csg.union_all(body_parts)
    good_mesh.saveSTL(filename, binary=False)
