Skip to content
Snippets Groups Projects
Commit 72f3478d authored by Stefano Bagnasco's avatar Stefano Bagnasco
Browse files

Initial upload

parent 790e59a9
No related branches found
No related tags found
No related merge requests found
FROM centos:7
MAINTAINER stefano.bagnasco@to.infn.it
RUN yum install -y numpy python-matplotlib &&\
yum clean all
COPY mandelbrot.py /usr/lib/mandelbrot.py
ENTRYPOINT ["/usr/bin/python","/usr/lib/mandelbrot.py"]
CMD ["50", "50.", "601", "401"]
\ No newline at end of file
#!/usr/bin/python
"""
Compute the Mandelbrot fractal
Code adapted from http://www.scipy-lectures.org/intro/numpy/exercises.html
"""
import sys
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
from numpy import newaxis
import warnings
warnings.filterwarnings('ignore',category=RuntimeWarning)
def compute_mandelbrot(N_max, some_threshold, nx, ny):
print "Computing..."
# A grid of c-values
x = np.linspace(-2, 1, nx)
y = np.linspace(-1.5, 1.5, ny)
c = x[:,newaxis] + 1j*y[newaxis,:]
# Mandelbrot iteration
z = c
for j in xrange(N_max):
z = z**2 + c
mandelbrot_set = (abs(z) < some_threshold)
return mandelbrot_set
# good values are (50, 50., 601, 401)
mandelbrot_set = compute_mandelbrot(int(sys.argv[1]),float(sys.argv[2]),int(sys.argv[3]),int(sys.argv[4]))
print "Drawing..."
plt.imshow(mandelbrot_set.T, extent=[-2, 1, -1.5, 1.5])
plt.gray()
plt.savefig('mandelbrot.png')
print "Done."
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment