Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python Test Plotter For Hybrid Fractal
- # https://plus.google.com/101799841244447089430/posts/Grb2inEG79b
- import math;
- import random;
- import copy; # for non-mutable aspects of classes
- #import os;
- from PIL import Image;
- # 2d Axes
- class ct_axes_2d:
- def __init__(self, xmin, xmax, ymin, ymax):
- self.xmin = xmin;
- self.xmax = xmax;
- self.ymin = ymin;
- self.ymax = ymax;
- def __repr__(self):
- return "(%s, %s, %s, %s)" % (self.xmin, self.xmax, self.ymin, self.ymax)
- def __str__(self): return self.__repr__();
- def width(self): return self.xmax - self.xmin;
- def height(self): return self.ymax - self.ymin;
- # 2d Plane
- # no aspect ratio support for this crude test... ;^o
- class ct_plane_2d:
- def __init__(self, width, height, axes):
- self.axes = copy.copy(axes);
- self.width = width;
- self.height = height;
- self.xstep = self.axes.width() / width;
- self.ystep = self.axes.height() / height;
- self.aratio = height / width;
- def __repr__(self):
- return "(%s, %s, %s, %s, %s, %s)" % (self.axes,
- self.width, self.height,
- self.xstep, self.ystep,
- self.aratio);
- def __str__(self): return self.__repr__();
- def project_to(self, p):
- x = math.floor((p.real - self.axes.xmin) / self.xstep * self.aratio);
- y = math.floor((self.axes.ymax - p.imag) / self.ystep);
- return complex(x, y);
- def project_xy(self, x, y):
- x = self.axes.xmin + x * self.xstep;
- y = self.axes.ymax - y * self.ystep;
- return complex(x, y);
- # CT Hybrid Fractal Test Plotter
- class ct_hybrid:
- def __init__(self, plane):
- self.plane = copy.copy(plane);
- self.image = Image.new("RGB", (plane.width, plane.height));
- self.pixels = self.image.load();
- def __repr__(self):
- return "(%s)" % (self.plane);
- def __str__(self): return self.__repr__();
- def save(self, fname):
- self.image.save(fname, "BMP");
- def iterate_pixel(self, z, c, x, y, imax):
- for i in range(0, imax):
- #z = z**2 + c;
- if ((int(i + 1) % 4) == 0):
- z = z**2 + c;
- mul = z.real * z.imag;
- if (mul == 0.0): mul = .000000001;
- z = z**2 + (z.real + z.imag) / mul * .001;
- if (z.real**2 + z.imag**2 > 52):
- self.pixels[x, y] = (255, 255, 255);
- return;
- self.pixels[x, y] = (0, 0, 0);
- def iterate_plane(self, imax):
- for y in range(0, self.plane.height - 1):
- for x in range(0, self.plane.width - 1):
- z = self.plane.project_xy(x, y);
- self.iterate_pixel(z, z, x, y, imax);
- print("iterate_plane(%s of %s)\r" % (y, self.plane.height), end="");
- print("");
- # Secret Key
- class ct_rifc_skey:
- def __init__(self, z, c_0, c_1, p_0, p_1, n, hmkey):
- self.z = z;
- self.c_0 = c_0;
- self.c_1 = c_1;
- self.p_0 = p_0;
- self.p_1 = p_1;
- self.n = n;
- self.hmack = copy.copy(hmkey);
- def __repr__(self):
- return "(%s, %s, %s, %s, %s, %s, %s)" % (self.z, self.c_0, self.c_1, self.p_0, self.p_1, self.n, self.hmack);
- def __str__(self): return self.__repr__();
- # Main Program
- axes = ct_axes_2d(-2, 2, -2, 2);
- plane = ct_plane_2d(640, 640, axes);
- plot = ct_hybrid(plane);
- plot.iterate_plane(100);
- plot.save("output.bmp");
- #os.system("mspaint output.bmp");
Advertisement
Add Comment
Please, Sign In to add comment