Created
March 21, 2023 19:57
-
-
Save ekm507/543cb4cdf54eaa054e4ebdfb7b137370 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# from matplotlib import pyplot as plt | |
import cv2 | |
width, height = 1000, 1000 | |
image = np.zeros((width, height)) | |
num_itterations = 10000 | |
n = 4 | |
# points = [] | |
def generate_initial_points(n, radius, center) -> list: | |
a = np.arange(0, n) | |
angles = 2 * np.pi / n * a | |
print(angles) | |
x = np.cos(angles) * radius + center[0] | |
y = np.sin(angles) * radius + center[1] | |
return list(zip(x, y)) | |
def add_point(points:list, n) -> list: | |
p1 = points[np.random.randint(0, n)] | |
# p2 = points[np.random.randint(0, len(points))] | |
p2 = points[-1] | |
if p2[0] - p1[0] == 0: | |
return points | |
m = (p2[1] - p1[1]) / (p2[0] - p1[0]) | |
d = (p2[0] - p1[0]) / 2 | |
newp = (p1[0] + d, | |
p1[1] + d * m) | |
points.append(newp) | |
return points | |
points = generate_initial_points(n, width // 2 - 1, (width // 2, height // 2)) | |
points = [ | |
(0, 0), | |
(0, 999), | |
(999, 500), | |
(999, 501), | |
] | |
for i in range(num_itterations): | |
points = add_point(points, n) | |
# init_points = generate_initial_points(4, 1, (110 // 2, 110 // 2)) | |
for point in points: | |
# print(list(map(int, list(point))), flush=True) | |
image[tuple(map(int, list(point)))] = 255 | |
# cv2.imshow('img', image) | |
cv2.imwrite('img.png', image) | |
cv2.waitKey(0) | |
# plt.imshow(image) | |
# plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment