Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate mandelbrot image from csv pixel data
import math
from PIL import Image
import pandas as pd
import time
RESOLUTION = 10**3
def get_color(escape_val):
return escape_val
def import_data():
print("Importing Data")
return pd.read_csv("../data/mandelbrot_e-3.txt")
def gen_img(mandl):
last_time = time.time()
avg_time_per_percent = 0
size = (int(math.sqrt(mandl.shape[0])), int(math.sqrt(mandl.shape[0])))
img = Image.new('L', size)
px = img.load()
for idx, row in mandl.iterrows():
if idx % int(mandl.shape[0] / 100) == 0:
current_time = time.time()
percentage = math.ceil(idx/mandl.shape[0]*100)
if percentage != 0:
avg_time_per_percent = avg_time_per_percent + (((current_time - last_time) - avg_time_per_percent)/ percentage)
print(f"{percentage}% done... about {int(avg_time_per_percent*(100-percentage))} seconds left.")
last_time = current_time
#print(f"raw_x: {row['x']}\t raw_y: {row['y']}")
x = int(round((row['x'] + 2.0) * RESOLUTION))
y = int(round((row['y'] + 2.0) * RESOLUTION))
color = get_color(int(row['escape']))
#print(f"X: {x}\t\tY: {y} --> Color: {color}")
px[x, y] = color
return img
if __name__ == '__main__':
df = import_data()
img = gen_img(df)
img.save("mandelbrot.jpg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.