diff --git a/hypertiling/plot.py b/hypertiling/plot.py index 36c995c3a6f2a4b60d89d4817a28a66e283f166c..a76dbf5bc4954fa813485050d42ff0a83a672615 100644 --- a/hypertiling/plot.py +++ b/hypertiling/plot.py @@ -1,10 +1,9 @@ import numpy as np import matplotlib.pyplot as plt -import matplotlib.pyplot as plt import matplotlib.cm as cmap from matplotlib.patches import Polygon from matplotlib.collections import PatchCollection, PolyCollection -from .geodesics import geodesic_arc +from geodesics import geodesic_arc # taken from http://exnumerus.blogspot.com/2011/02/how-to-quickly-plot-polygons-in.html @@ -80,10 +79,6 @@ def edges2matplotlib(T, **kwargs): types.append(-1) return edges, types - - - - # simple plot function for hyperbolic tiling with colors @@ -95,7 +90,7 @@ def plot_tiling(polygons, colors, symmetric_colors=False, plot_colorbar=False, x # draw patches ax.add_collection(pgons) - + # symmetric colorbar if symmetric_colors: cmin = np.min(colors) @@ -110,5 +105,7 @@ def plot_tiling(polygons, colors, symmetric_colors=False, plot_colorbar=False, x plt.ylim(ycrange) plt.axis("off") plt.gca().set_aspect('equal') + # plt.savefig('pgon73.png', dpi=400) + plt.show() return ax diff --git a/hypertiling/temp.py b/hypertiling/temp.py new file mode 100644 index 0000000000000000000000000000000000000000..841415eabd65c94029b36db02bf47204e7420c18 --- /dev/null +++ b/hypertiling/temp.py @@ -0,0 +1,53 @@ +import random + +import matplotlib.colors +import numpy as np + +from core import HyperbolicTiling +from plot import quick_plot, plot_tiling +from matplotlib import pyplot as plt +from PIL import Image +import binascii # to convert .png into hex + +def rgb_to_hex(rgb): + dim1 = len(rgb[:, 0, 0]) + dim2 = len(rgb[0, :, 0]) + hexcolors = np.empty(shape=(dim1, dim2), dtype='object') + for i, row in enumerate(rgb): + for j, clr in enumerate(row): + c = f"{format(clr[0], '02x')}" + f"{format(clr[1], '02x')}" + f"{format(clr[2], '02x')}" + hexcolors[i, j] = c + + return hexcolors + # return '%02x%02x%02x' % rgb + # return f"{format(rgb[0], '02x')}" + f"{format(rgb[1], '02x')}" + f"{format(rgb[2], '02x')}" + + +p, q, n = 7, 3, 1 +t = HyperbolicTiling(p, q, n, kernel="flo") +t.generate() +# plot_tiling(t, np.random.rand(len(t))) + +d = 10 +img = Image.open('Patrick Star Vorlage.png').resize((d, d)) +img = np.asarray(img) +img_hex = rgb_to_hex(img) +imgref = Image.open('pgon73.png').resize((d, d)) +imgref = np.asarray(imgref) +imgref_hex = rgb_to_hex(imgref) +# whites = [['000000' for _ in range(d)] for __ in range(d)] +# img_hex[(img_hex == '000000')] = 'x' +img_hex = np.where(imgref_hex != '000000', img_hex, '000000') +print(img_hex) +print(np.shape(img_hex)) +# img = np.delete() +fig, ax = plt.subplots() + +img = ax.imshow(img) +# patch = patches.Circle((250, 250), radius=1000, transform=ax.transData) +# patch2 = patches.Circle((0, 0), radius=1000, transform=ax.transData) +# img.set_clip_path(patch) +# img.set_clip_path(patch2) + +# ax.axis('off') +plt.show()