Skip to content

Commit 56a57cd

Browse files
committed
Sync materials with tutorials
1 parent b89c740 commit 56a57cd

16 files changed

+55
-114
lines changed

mandelbrot-set-python/02_bw_plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_members(c, num_iterations):
2222

2323

2424
if __name__ == "__main__":
25-
c = complex_matrix(-2, 0.5, -1.5, 1.5, pixel_density=1280)
25+
c = complex_matrix(-2, 0.5, -1.5, 1.5, pixel_density=512)
2626

2727
plt.imshow(is_stable(c, num_iterations=20).T, cmap="binary")
2828
plt.gca().set_aspect("equal")

mandelbrot-set-python/04_grayscale.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
for x in range(width):
1616
re = scale * (x - width / 2)
1717
im = scale * (height / 2 - y)
18-
probability = 1 - mandelbrot_set.probability(complex(re, im))
19-
image.putpixel((x, y), int(probability * 255))
18+
stability = 1 - mandelbrot_set.stability(complex(re, im))
19+
image.putpixel((x, y), int(stability * 255))
2020

2121
image.show()

mandelbrot-set-python/05_grayscale_smooth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
re = scale * (x - width / 2)
1717
im = scale * (height / 2 - y)
1818
c = complex(re, im)
19-
probability = 1 - mandelbrot_set.probability(c, smooth=True)
20-
image.putpixel((x, y), max(0, min(int(probability * 255), 255)))
19+
stability = 1 - mandelbrot_set.stability(c, smooth=True)
20+
image.putpixel((x, y), int(stability * 255))
2121

2222
image.show()

mandelbrot-set-python/06_viewport_aspect.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

mandelbrot-set-python/07_viewport_center.py renamed to mandelbrot-set-python/06_viewport_pixel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from PIL import ImageEnhance
33

44
from mandelbrot_03 import MandelbrotSet
5-
from viewport_02 import Viewport
5+
from viewport import Viewport
66

77
if __name__ == "__main__":
88
print("This might take a while...")
@@ -12,8 +12,8 @@
1212
image = Image.new(mode="L", size=(512, 512))
1313
for pixel in Viewport(image, center=-0.7435 + 0.1314j, width=0.002):
1414
c = complex(pixel)
15-
probability = 1 - mandelbrot_set.probability(c, smooth=True)
16-
pixel.color = max(0, min(int(probability * 255), 255))
15+
stability = 1 - mandelbrot_set.stability(c, smooth=True)
16+
pixel.color = int(stability * 255)
1717

1818
enhancer = ImageEnhance.Brightness(image)
1919
enhancer.enhance(1.25).show()

mandelbrot-set-python/08_color_palette_matplotlib.py renamed to mandelbrot-set-python/07_color_palette_matplotlib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
from PIL import Image
33

44
from mandelbrot_03 import MandelbrotSet
5-
from viewport_02 import Viewport
5+
from viewport import Viewport
66

77

88
def paint(mandelbrot_set, viewport, palette, smooth):
99
for pixel in viewport:
10-
probability = mandelbrot_set.probability(complex(pixel), smooth)
11-
index = int(min(probability * len(palette), len(palette) - 1))
10+
stability = mandelbrot_set.stability(complex(pixel), smooth)
11+
index = int(min(stability * len(palette), len(palette) - 1))
1212
pixel.color = palette[index % len(palette)]
1313

1414

mandelbrot-set-python/09_color_palette_custom.py renamed to mandelbrot-set-python/08_color_palette_custom.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from PIL import Image
22

33
from mandelbrot_03 import MandelbrotSet
4-
from viewport_02 import Viewport
4+
from viewport import Viewport
55

66

77
def paint(mandelbrot_set, viewport, palette, smooth):
88
for pixel in viewport:
9-
probability = mandelbrot_set.probability(complex(pixel), smooth)
10-
index = int(min(probability * len(palette), len(palette) - 1))
9+
stability = mandelbrot_set.stability(complex(pixel), smooth)
10+
index = int(min(stability * len(palette), len(palette) - 1))
1111
pixel.color = palette[index % len(palette)]
1212

1313

mandelbrot-set-python/10_color_gradient.py renamed to mandelbrot-set-python/09_color_gradient.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
from scipy.interpolate import interp1d
44

55
from mandelbrot_03 import MandelbrotSet
6-
from viewport_02 import Viewport
6+
from viewport import Viewport
77

88

99
def paint(mandelbrot_set, viewport, palette, smooth):
1010
for pixel in viewport:
11-
probability = mandelbrot_set.probability(complex(pixel), smooth)
12-
index = int(min(probability * len(palette), len(palette) - 1))
11+
stability = mandelbrot_set.stability(complex(pixel), smooth)
12+
index = int(min(stability * len(palette), len(palette) - 1))
1313
pixel.color = palette[index % len(palette)]
1414

1515

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from PIL.ImageColor import getrgb
33

44
from mandelbrot_03 import MandelbrotSet
5-
from viewport_02 import Viewport
5+
from viewport import Viewport
66

77

88
def hsb(hue_degrees: int, saturation: float, brightness: float):
@@ -19,14 +19,13 @@ def hsb(hue_degrees: int, saturation: float, brightness: float):
1919
mandelbrot_set = MandelbrotSet(max_iterations=25)
2020
image = Image.new(mode="RGB", size=(512, 512))
2121
for pixel in Viewport(image, center=-0.75, width=3.5):
22-
p = mandelbrot_set.probability(complex(pixel), smooth=True)
23-
probability = max(0, min(p, 1))
22+
stability = mandelbrot_set.stability(complex(pixel), smooth=True)
2423
pixel.color = (
2524
(0, 0, 0)
26-
if probability == 1
25+
if stability == 1
2726
else hsb(
28-
hue_degrees=int(probability * 360),
29-
saturation=probability,
27+
hue_degrees=int(stability * 360),
28+
saturation=stability,
3029
brightness=1,
3130
)
3231
)

mandelbrot-set-python/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This code requires the following libraries:
1414
To install them, activate your [virtual environment](https://realpython.com/python-virtual-environments-a-primer/), and type the following command:
1515

1616
```
17-
$ python -m pip install -r requirements.txt
17+
$ python3 -m pip install -r requirements.txt
1818
```
1919

2020
## Usage

0 commit comments

Comments
 (0)