-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset_generator.py
99 lines (89 loc) · 3.79 KB
/
dataset_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#Made by Yaroslav
import numpy as np
from random import random
import math
class Generator():
def __init__(self, n_components=2,
border_array=np.array([[0, 1], [0, 1]]),
function_array=np.array([(lambda x: x[0]), (lambda x: x[1]), (lambda x: math.cos(x[0]) + math.cos(x[1]))])):
self.n_components = n_components
self.border_array = border_array
self.function_array = function_array
def generate_net(self, n_points):
return np.array(sorted(list(
(
list(
self.border_array[j][0] + random() * (self.border_array[j][1] - self.border_array[j][0])
for j in range(self.n_components)
)
) for i in range(n_points)
)))
def process_net(self, net):
return np.array(list(
np.array(list(
function(net[i])
for function in self.function_array
))
for i in range(net.shape[0])
))
def generate_colors(self, n_points, color_data):
q = (color_data[1] - color_data[0]) / (max(n_points - 1, 1))
return np.array(
list(
color_data[0] + q * i
for i in range(n_points)
)
)
def generate_manifold(self, n_points, color_data=np.array([np.array([0,1,0]), np.array([0,0,1])])):
return self.process_net(self.generate_net(n_points)), self.generate_colors(n_points, color_data)
class Mobius(Generator):
def __init__(self, width=2, radius=1):
super().__init__(
n_components=2,
border_array=np.array([[0, 2 * math.pi], [-width / 2, width / 2]]),
function_array=np.array(
[
(lambda x: (radius + x[1] / 2 * math.cos(x[0] / 2)) * math.cos(x[0])),
(lambda x: (radius + x[1] / 2 * math.cos(x[0] / 2)) * math.sin(x[0])),
(lambda x: x[1] / 2 * math.sin(x[0] / 2))
]))
class Ring(Generator):
def __init__(self, width=2, radius=1):
super().__init__(n_components=2,
border_array=np.array([[0, 2 * math.pi], [-width / 2, width / 2]]),
function_array=np.array(
[
(lambda x: radius * math.cos(x[0])),
(lambda x: radius * math.sin(x[0])),
(lambda x: x[1])
]))
class Helix(Generator):
def __init__(self, step=1, twists=1, width=1, offset=0):
super().__init__(n_components=2,
border_array=np.array([[0, twists * 2 * math.pi], [offset - width / 2, offset + width / 2]]),
function_array=np.array(
[
(lambda x: x[1] * math.cos(x[0])),
(lambda x: x[1] * math.sin(x[0])),
(lambda x: step * x[0] / 2 / math.pi)
]))
class S_curve(Generator):
def __init__(self):
super().__init__(n_components=2,
border_array=np.array([[-1/3 * math.pi, 4/3 * math.pi], [0, 1]]),
function_array=np.array(
[
(lambda x: x[1]),
(lambda x: math.sin(2 * x[0])),
(lambda x: math.cos(x[0])),
]))
class Spiral(Generator):
def __init__(self):
super().__init__(n_components=2,
border_array=np.array([[0, 10],[0, 10]]),
function_array=np.array(
[
(lambda x: x[1]),
(lambda x: x[0] * math.sin(x[0])),
(lambda x: x[0] * math.cos(x[0])),
]))