Skip to content

Commit 14feb4f

Browse files
committed
Implement 6 transformations as static methods
1 parent 80ce27d commit 14feb4f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

variations.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,33 @@ def transform(self):
1616
def linear(x, y):
1717
return x, y
1818

19+
@staticmethod
20+
def handkerchief(x, y):
21+
r = np.sqrt(x**2 + y**2)
22+
theta = np.arctan2(x, y)
23+
return r * np.sin(theta + r), r * np.cos(theta - r)
24+
25+
@staticmethod
26+
def swirl(x, y):
27+
r = np.sqrt(x ** 2 + y ** 2)
28+
return x * np.sin(r**2) - y * np.cos(r**2), x * np.cos(r**2) + y * np.sin(r**2)
29+
30+
@staticmethod
31+
def disc(x, y):
32+
r = np.sqrt(x ** 2 + y ** 2)
33+
theta = np.arctan2(x, y)
34+
c = theta / np.pi
35+
return c * np.sin(np.pi * r), c * np.cos(np.pi * r)
36+
37+
@staticmethod
38+
def eyefish(x, y):
39+
r = np.sqrt(x ** 2 + y ** 2)
40+
c = 2 / (r + 1)
41+
return c * x, c * y
42+
43+
@staticmethod
44+
def horseshoe(x, y):
45+
r = np.sqrt(x ** 2 + y ** 2)
46+
c = 1 / r
47+
return c * ((x-y) * (x+y)), c * 2 * x*y
48+

0 commit comments

Comments
 (0)