File:Mandelbrot numpy set 5.png
Summary
| Description |
Deutsch: Die Mandelbrot-Menge wird mit NumPy unter Verwendung komplexer Matrizen berechnet. Es wird eine von Adam Saka popularisierte und von Adam Majewski beschriebene Hillshading-Methode verwendet. Diese Technik erzeugt die Illusion dreidimensionaler Stufen. English: The Mandelbrot set is calculated with NumPy using complex matrices. A hillshading method popularized by Adam Saka and described by Adam Majewski is used. This technique creates the illusion of three-dimensional steps. |
| Date | |
| Source | Own work |
| Author | Majow |
| Other versions |
|
| PNG development | |
| Source code | Python codeimport numpy as np
import matplotlib.pyplot as plt
d, h = 500, 600 # pixel density (= image width) and image height
n, r = 200, 500 # number of iterations and escape radius (r > 2)
direction, height = 45.0, 1.5 # direction and height of the light
x = np.linspace(0, 2, num=d+1)
y = np.linspace(0, 2 * h / d, num=h+1)
A, B = np.meshgrid(x - 1, y - h / d)
C = (2.0 + 1.0j) * (A + B * 1j) - 0.5
def iteration(C):
Z, dZ = np.zeros_like(C), np.zeros_like(C)
def iterate(C, Z, dZ):
Z, dZ = Z * Z + C, 2 * Z * dZ + 1
return Z, dZ
for i in range(n):
M = abs(Z) < r
Z[M], dZ[M] = iterate(C[M], Z[M], dZ[M])
return Z, dZ
Z, dZ = iteration(C)
D, S = np.zeros(C.shape), np.zeros(C.shape)
fig = plt.figure(figsize=(12.8, 9.6))
fig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95)
N = abs(Z) >= r # blended normal map effect and linear steps (potential function)
U, V = Z[N] / dZ[N], np.log2(np.log(np.abs(Z[N])) / np.log(r))
U, v = U / abs(U), np.exp(direction / 180 * np.pi * 1j) # unit normal vectors and light vector
D[N], S[N] = np.maximum((U.real * v.real + U.imag * v.imag + height) / (1 + height), 0), V
ax1 = fig.add_subplot(2, 3, 1)
ax1.imshow(D ** 1.0, cmap=plt.cm.gray, origin="lower")
ax2 = fig.add_subplot(2, 3, 2)
ax2.imshow(S ** 1.0, cmap=plt.cm.gray, origin="lower")
ax3 = fig.add_subplot(2, 3, 3)
ax3.imshow((D + S) ** 1.0, cmap=plt.cm.gray, origin="lower")
N = abs(Z) >= r # blended normal map effect and linear steps (potential function)
U, V = Z[N] / dZ[N], np.maximum(1 - np.log2(np.log(np.abs(Z[N])) / np.log(r)), 0)
U, v = U / abs(U), np.exp(direction / 180 * np.pi * 1j) # unit normal vectors and light vector
D[N], S[N] = np.maximum((U.real * v.real + U.imag * v.imag + height) / (1 + height), 0), V
ax4 = fig.add_subplot(2, 3, 4)
ax4.imshow(D ** 1.0, cmap=plt.cm.gray, origin="lower")
ax5 = fig.add_subplot(2, 3, 5)
ax5.imshow(S ** 1.0, cmap=plt.cm.gray, origin="lower")
ax6 = fig.add_subplot(2, 3, 6)
ax6.imshow((D + S) ** 1.0, cmap=plt.cm.gray, origin="lower")
fig.savefig("Mandelbrot_numpy_set_5.png", dpi=200)
|
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
| This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication. | |
| The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
|