#!/usr/bin/python
# -*- coding: utf-8 -*-   ## Baustelle: MUSS 1. oder 2. Zeile sein
# name mb_seriell         # MRies, 09/2015

__author__ = 'ries'

import numpy as np 
import matplotlib.pyplot as plt

def mb_iteration(x, y):
	c = complex(x,y)      # x+yj
	z = 0+0j
	for iteration in range(255):
		z = z*z + c
		if abs( z ) >= 2:     # Divergenz
			return  iteration 
	return 255
	
def mb_matrix(x_min, x_max, y_min, y_max, bild):
	zeilen_zahl  = bild.shape[0]
	spalten_zahl = bild.shape[1]

	delta_x = (x_max - x_min) / spalten_zahl
	delta_y = (y_max - y_min) / zeilen_zahl
	for spalte_j in range(spalten_zahl):
		x_pix = x_min + spalte_j * delta_x
		for zeile_i in range(zeilen_zahl):
			y_pix = y_min + zeile_i * delta_y
			bild[(zeilen_zahl-1)-zeile_i, spalte_j] = \
				 mb_iteration(x_pix, y_pix)
	return bild

bild = np.zeros((400, 400), dtype=np.uint8)
mb_matrix(-0.088, -0.085, 0.855, 0.858, bild)

plt.imshow(bild)  
plt.gray()
plt.show()