Kernel: Python 2 (SageMath)
In [ ]:
#Code to take Julia set iteration data and produce sliced images
In [1]:
import numpy as np import cPickle as pickle from matplotlib import cm import matplotlib.pyplot as plt from PIL import Image from math import sqrt
In [2]:
DATA = '../data/iterations_data.bin' colormap = cm.viridis
In [ ]:
with open(DATA) as f: iteration_data = np.fromfile( f.read(), dtype=np.uint8 ) iteration_data = iteration_data.reshape( (1000, 1000) )
In [ ]:
In [ ]:
unique_values = np.unique(iteration_data) print(unique_values) n = len(unique_values)//5 slices = [ unique_values[i:i+n] for i in range(0, len(unique_values), n)]
In [ ]:
for slice_index, slice_values in enumerate( slices ): img = np.zeros( iteration_data.shape, dtype=np.int32) img.fill(0xFFFFFFFF) for index, slice_value in enumerate(slice_values): #raw_color = colormap(slice_value) #raw_color = RGB_tuples[ slice_index*n + index ] #color = sum( [int((0xFF*v))<<(8*i) for i,v in enumerate(raw_color)] ) shift = 8*(slice_value//(255//3)) color = (255//2 +slice_value%(255//3)) color = color<<shift color += 0xFF000000 img[ np.where( iterations_data == slice_value) ] = color pilImage = Image.frombuffer('RGBA', img.shape, img,'raw','RGBA',0,1) pilImage.save( "../Image_Slices/img_{0}.png".format(slice_index) )
In [ ]:
[ 8*(i//(255//3)) for i in range(1,256) ]
In [ ]:
In [ ]:
import numpy as np a = np.array([1,2,3,4,5,6,7,8,9])
In [ ]:
a.reshape(np.array('3,3'.split(',')).astype(int))
In [ ]:
b = a.reshape(np.array('3,3'.split(',')).astype(int)) b
In [ ]:
a
In [ ]: