Testing Waters
Search
K

# Hexagonal Pattern From Image

Scaled triangles corresponding to pixel brightness within each hexagon that makes up a hexagonal grid stretching across the extents of an image
x count = 20, y count = 20
//Image Dimensions
w = Image.Dimensions(img)["width"];
h = Image.Dimensions(img)["height"];
//Surface corresponding to image proportions
pnt1 = Point.ByCoordinates(List.RestOfItems(0..w)<1>,List.RestOfItems(0..h)<2>);
srf = NurbsSurface.ByPoints(pnt1, 3, 3);
//Increase for more detail
xc = 10;
yc = 10;
//Hexagon Points Grid
s = 10;
a = s/(2*Math.Tan(30));
p1 = Point.ByCoordinates((0..#xc..s*3)<1>,(0..#yc..a*2)<2>);
p2 = List.Flatten(p1<1>.Translate([0,s*1.5]<2>,[0,a]<2>,0),1);
p4 = List.Flatten(p3,-1).Points;
//Triangles
//p7 = Polygon.ByPoints(p6);
c1 = Point.ByCoordinates(Math.Sum(p6.X)/3,Math.Sum(p6.Y)/3);
//Triangle UV
u1 = UV.ByCoordinates((p6.X-List.MinimumItem(List.Flatten(p6,-1).X))/List.MaximumItem(List.Flatten(p6,-1).X),
(p6.Y-List.MinimumItem(List.Flatten(p6,-1).Y))/List.MaximumItem(List.Flatten(p6,-1).Y));
//Triangle Centroid
u2 = UV.ByCoordinates((c1.X-List.MinimumItem(List.Flatten(c1,-1).X))/List.MaximumItem(List.Flatten(c1,-1).X),
(c1.Y-List.MinimumItem(List.Flatten(c1,-1).Y))/List.MaximumItem(List.Flatten(c1,-1).Y));
//Minimum and Maximum parameters
minX = List.MinimumItem(List.Flatten(p6.X,-1));
maxX = List.MaximumItem(List.Flatten(p6.X,-1));
minY = List.MinimumItem(List.Flatten(p6.Y,-1));
maxY = List.MaximumItem(List.Flatten(p6.Y,-1));
//b1 + (s-a1)*(b2-b1)/(a2-a1)
//Triangle UV
uv1 = UV.ByCoordinates((p6.X-minX)/(maxX-minX),(p6.Y-minY)/(maxY-minY));
//Triangle Centroid UV
uv2 = UV.ByCoordinates((c1.X-minX)/(maxX-minX),(c1.Y-minY)/(maxY-minY));
//Image Pixels
pxl1 = List.Flatten(List.Reverse(Image.Pixels(img, w, h)),-1);
prm1 = List.Flatten(UV.ByCoordinates((0..1..#h)<1>, (0..1..#w)<2>),-1);
clr1 = (ColorRange.ByColorsAndParameters(pxl1, prm1)).GetColorAtParameter(uv2);
//Triangles on Surface
cnt1 = srf.PointAtParameter(uv2.U,uv2.V);
thk1 = 0.25;
tri1 = Surface.ByPerimeterPoints(srf.PointAtParameter(uv1.U,uv1.V)).Thicken(thk1);
pln1 = Plane.ByOriginNormal(cnt1,srf.NormalAtPoint(cnt1));
tri2 = tri1.Scale(pln1,(1-Color.Brightness(clr1))+0.00001,(1-Color.Brightness(clr1))+0.00001,1);
x-count = 10, y count =10