Skip to content

Commit 4f7bf11

Browse files
committed
Update readme and comments
1 parent b998a4a commit 4f7bf11

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Complex
2-
Complex number plotter using domain coloring
2+
Complex function plotter using domain coloring
33

44
## Usage
55
1. `git clone https://github.com/Ducolnd/complex`
@@ -12,6 +12,6 @@ Complex number plotter using domain coloring
1212
8. Run by typing `python complex.py` and close by pressing ECS
1313

1414
## Sources
15-
[algorithm-archive.org](https://www.algorithm-archive.org/contents/domain_coloring/domain_coloring.html)
16-
[dynamicmath.xyz](https://www.dynamicmath.xyz/domain-coloring/#basic)
17-
[wikipedia.org](https://en.wikipedia.org/wiki/Domain_coloring)
15+
[algorithm-archive.org](https://www.algorithm-archive.org/contents/domain_coloring/domain_coloring.html) <br>
16+
[dynamicmath.xyz](https://www.dynamicmath.xyz/domain-coloring/#basic)<br>
17+
[wikipedia.org](https://en.wikipedia.org/wiki/Domain_coloring)<br>

complex.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@
33
import numpy as np
44
import math
55

6-
size = 400
6+
# Setup
7+
size = 800
8+
x_range = 3
9+
y_range = x_range
10+
threshold = 0.01 # Black line visibility
711

8-
res = np.linspace(-2, 2, size * 2 + 1)
9-
ims = np.linspace(-2, 2, size * 2 + 1)
12+
res = np.linspace(-(x_range / 2), x_range / 2, size * 2 + 1)
13+
ims = np.linspace(-(y_range / 2), y_range / 2, size * 2 + 1)
1014

1115
nums = np.zeros((len(res) - 1, len(ims) - 1), dtype=np.complex_)
1216

1317
for i in range(-size, size):
1418
for j in range(-size , size):
15-
nums[i+size, j+size] = complex(res[i+size], ims[j+size])
19+
nums[i+size, j+size] = complex(ims[i+size], res[j+size])
1620

21+
def g(z):
22+
return (z - 1) / (z ** 13 + z + 1)
1723

18-
# Edit this
19-
def function(complex_num):
20-
return complex_num ** 2
21-
24+
def function(z):
25+
return z ** (1 + 10j) * np.cos(g(z))
2226

2327

2428
nums = function(nums)
@@ -29,12 +33,14 @@ def function(complex_num):
2933

3034
H = np.interp(phase, (-180, 180), (0, 360))
3135
S = 0.7 + (1 / 3) * (np.log(magnitude) / np.log(1.6) - np.floor(np.log(magnitude) / np.log(1.6))) # alternatively S = 0.5 + 0.5 * (magnitude - np.floor(magnitude))
32-
V = ((np.abs(np.sin(math.pi * nums.real)) ** 0.1) * (np.abs(np.sin(math.pi * nums.imag)) ** 0.1)) * 255 # alternatively V = np.full(phase.shape, 255, dtype="float32")
36+
V = ((np.abs(np.sin(math.pi * nums.real)) ** threshold) * (np.abs(np.sin(math.pi * nums.imag)) ** threshold)) * 255 # alternatively V = np.full(phase.shape, 255, dtype="float32")
3337

3438

3539
HSV = np.dstack((H, S, V)).astype("float32", copy=False)
3640

37-
image = cv2.cvtColor(HSV, cv2.COLOR_HSV2BGR) / 255
41+
image = np.rot90(cv2.cvtColor(HSV, cv2.COLOR_HSV2BGR) / 255, 3)
42+
43+
# cv2.imwrite("complex.png", image * 255)
3844

3945
cv2.imshow("Complex", image)
4046
cv2.waitKey(0)

0 commit comments

Comments
 (0)