(
var substitute, mapDepth, dir, tileMap, depth, transform, img;

substitute = {arg parent, transform; var s, t, u, v, sub;
	s = 4.collect({arg i; parent[0] + ((parent[i] - parent[0]) / 2)});
	t = [parent[2] + ((parent[3] - parent[2]) / 2), parent[2], s[3], s[2]];
	u = [t[0], s[1], t[0] + ((parent[1] - s[1]) / 2), s[1] + ((parent[1] - s[1]) / 2)];
	v = [parent[1], parent[3], u[3], u[2]];
	sub = [s, t, u, v].collect({arg child, i; if(transform[i] == nil, {nil},
		{4.collect({arg j; child[((j.asDigits(2, 2) + transform[i].asDigits(2, 2)) % 2).convertDigits(2)]})})});
	sub.removeEvery([nil])};

mapDepth = {arg depth, transform; var tiles = [[[0, 0], [2, 0], [0, 1], [2, 1]]];
	depth.do({arg i; tiles = tiles.collect({arg tile; substitute.value(tile, transform)}).flatten});
	[tiles]};

dir = thisProcess.nowExecutingPath.dirname;

256.do({arg index;
	transform = index.asDigits(4, 4);
	tileMap = mapDepth.value(6, transform);

	img = Image.new(700, 350);
	img.draw({var rectWidth, rectHeight, xOffset, yOffset;
		rectWidth =  img.bounds.width - 20; rectHeight = rectWidth / 2;
		xOffset = 10; yOffset = (img.bounds.height - rectHeight) / 2;
		Pen.width = (rectHeight + rectWidth) / 8000;
		tileMap[0].do({arg tile, i; var p1, p2, rect;
			p1 = Point.new(tile[0][0] / 2 * rectWidth, tile[0][1] * rectHeight);
			p2 = Point.new(tile[3][0] / 2 * rectWidth, tile[3][1] * rectHeight);
			rect = Rect.fromPoints(p1, p2).moveBy(xOffset, yOffset);
			if(abs(p1.x - p2.x) > abs(p1.y - p2.y),
				{Pen.color = Color.white; Pen.fillRect(rect); Pen.color = Color.black; Pen.strokeRect(rect)},
				{Pen.color = Color.black; Pen.fillRect(rect); Pen.color = Color.white; Pen.strokeRect(rect)});
		});
		Pen.color = Color.black; Pen.strokeRect(Rect.new(xOffset, yOffset, rectWidth, rectHeight))});
	if(File.exists(dir +/+ ".." +/+ "images").not, {File.mkdir(dir +/+ ".." +/+ "images")});
	img.write(dir +/+ ".." +/+ "images" +/+ transform.join ++ ".png".standardizePath);
});
)