import matplotlib.pyplot as plt
import numpy as np
from itertools import combinations

def center(points):
	return sum(points)/len(points)

def draw_triangle(points):
	for ps in combinations(points, 2):
		xs = [ps[0][0], ps[1][0]]
		ys = [ps[0][1], ps[1][1]]        
		plt.plot(xs, ys, 'b-', alpha=0.1)

def mesh(points, depth):
	if depth > 0:
		c = center(points)
		for pair in combinations(points, 2):
			pts = [pair[0], pair[1], c]
			draw_triangle(pts)
			mesh(pts, depth-1)
			
points = [
	np.array([0, 1]),
	np.array([-0.866, -0.5]),
	np.array([ 0.866, -0.5]) ]

mesh(points, 3)
plt.axis("off")
plt.gca().set_aspect("equal")
plt.show()
