from itertools import groupby
from math import floor, cos, sin, radians
from numpy import arange, zeros
from matplotlib import pyplot, colors
r = 50
show_plot = True
step = 1 / r
sample_angle = 0
coordinates = []
while sample_angle < 45:
coordinates.append((floor(r * cos(radians(sample_angle))), floor(r * sin(radians(sample_angle)))))
sample_angle += step
tile_matrix = zeros(shape=[r + 1, r + 1], dtype=int)
for (x, y) in coordinates:
if x < r and y < r and (x >= y and tile_matrix[y][x + 1] == 0) or (x <= y and tile_matrix[y - 1][x] == 0):
tile_matrix[y][x] = 1
segment_lengths = [t for t in sum(tile_matrix) if t > 0]
segment_groups = groupby(segment_lengths)
segment_counts = [(int(label), sum(1 for _ in group)) for label, group in segment_groups]
segment_counts.reverse()
[print(x) for x in segment_counts]
tile_matrix = tile_matrix.transpose()
if show_plot:
pyplot.xlim([0, tile_matrix.shape[1]])
pyplot.xticks(arange(0.5, tile_matrix.shape[1], 1))
pyplot.ylim([0, tile_matrix.shape[0]])
pyplot.yticks(arange(0.5, tile_matrix.shape[0], 1))
pyplot.imshow(tile_matrix, cmap=colors.ListedColormap(['darkgreen', 'black']))
pyplot.grid(color='gray', linewidth="0.3")
pyplot.tick_params(labelbottom=False, labelleft=False)
pyplot.show()