Hi guys,
I appreciate your help in the past, it was valuable this time I need a little help in order to understand this mandelbrot fractal set.
To begin with what is a fractal? Since English is not my native language, I have a hard time translating this.
This is my code, I want to know how to generate the image and how to calculate this fractal. I got to how many iterations are needed for (Z on) 2) + Z + C, iterations of what?
Code:
#Description:
#A mandelbrot set uses a decart coordinate system in order to represent an image and its color based on the
#iterations needed in order to
#Libraries
#From pillow(PIL) include the classes Image and ImageDraw
from PIL import Image, ImageDraw
#Import libraries os, json, yaml, math
import os, json, yaml, math
#Import library pandas named pd for short
import pandas as pd
#Import library numbpy named np for short
import numpy as np
#Import library matplotlib . pylot named plt for short
import matplotlib .pyplot as plt
#Variables block
image_width = 100
image_height = 100
cxmin = 100
cxmax = 100
cymin = 100
cymax = 100
iterations = 100
color = 'Green'
output_image_path = 'target/04_mandelbrot.png'
#Function declarations block
#mandelbrot set function
def render_mandelbrot(image_width, image_height, cxmin, cxmax, cymin, cymax, iterations, color, output_image_path):
#create an image of type RGBA, size in width and height, color
img = Image.new('RGBA', (image_width, image_height), color)
#new_pixel_map = img.load()
#Mandelbrot calculations(scaling)
for i in range (image_height):
y = 2*i/image_height - 1.0
for j in range (image_width):
x = 2*j/image_width - 1.0
#compute the mandelbrot set iteself
g = compute_mandelbrot_value(x, y, iterations=200)
#color = (g, g, g)
#new_pixel_map[j, i] = color
#return the image at the end of the funtion
return img
def compute_mandelbrot_value(x, y, iterations=200):
g = int(255 * ((x + y)+ 2)/4)
return g
img = Image.new('RGB', (image_width, image_height), color)
img.save(output_image_path)#The function does not save the file
#Function calling block
render_mandelbrot(image_width, image_height, cxmin, cxmax, cymin, cymax, iterations, color, output_image_path)