From 452d5c1f84a5894865591ebc6072d8369ae2dc9f Mon Sep 17 00:00:00 2001 From: knolax <1339802534.kk@gmail.com> Date: Wed, 27 Jun 2018 01:20:59 -0400 Subject: Initial commit, but don't be fooled, thi stuff is 4 years old --- mandelgen.py | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ mandelgen2.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100755 mandelgen.py create mode 100755 mandelgen2.py diff --git a/mandelgen.py b/mandelgen.py new file mode 100755 index 0000000..266b7b9 --- /dev/null +++ b/mandelgen.py @@ -0,0 +1,102 @@ +#!/bin/python +#written for py3.5.2 +from drawille import Canvas +import cmath +import math +import curses +from PIL import Image +import argparse +def init () : + global args + parser = argparse.ArgumentParser() + parser.add_argument("-xm", help="max x", + type=int) + parser.add_argument("-ym", help="max y", + type=int) + parser.add_argument("-xt", help="tran x", + type=float) + parser.add_argument("-yt", help="tran y", + type=float) + parser.add_argument("-s", help="scale", + type=float) + parser.add_argument("-b", help="braile", + action="store_true") + parser.add_argument("-t", help="threshhold of calcs", + type=int) + args = parser.parse_args() + global xt + xt = args.xt + global yt + yt = args.yt + global xs + xs = args.s + global ys + ys = args.s + global xm + xm = args.xm + global ym + ym = args.ym + global thr + thr = args.t + global vals + vals = [[]] + if (args.b) : + global screen + screen = curses.initscr() + curses.start_color() + curses.noecho() + curses.cbreak() + screen.keypad(1) + xm = screen.getmaxyx()[1] * 2 + ym = screen.getmaxyx()[0] * 3 + global canvas + canvas = Canvas() + else : + global img + global pix + img = Image.new('RGB', (xm, ym), (255, 255, 255)) + pix = img.load() + global recm + recm = [[]] + for xi in range(0, xm, 1) : + vals.append([]) + recm.append([]) + for yi in range(0, ym, 1) : + vals[xi].append(complex(0, 0)) + recm[xi].append(thr) + if (args.b) : + canvas.set(xi,yi) +def end () : + if (args.b) : + curses.echo() + curses.nocbreak() + screen.keypad(0) + curses.endwin() + else : + img.save("mandel","PNG") + return +init() +for i in range(0, thr, 1) : + for xi in range(0, xm, 1) : + for yi in range(0, ym, 1) : + tval = vals[xi][yi] + if (recm[xi][yi] == thr) : + if (math.sqrt(math.pow(tval.real, 2.0) + math.pow(tval.imag, 2.0)) >= 2 ) : + recm[xi][yi] = i + else : + c = complex(xt + (xs * xi), yt - (ys * yi)) + + vals[xi][yi] = vals[xi][yi] * vals[xi][yi] + c +for xi in range(0, xm, 1) : + for yi in range(0, ym, 1) : + if (args.b) : + if (recm[xi][yi] != thr) : + canvas.unset(xi, yi) + else : + color = 255 - int(255.0/float(thr) * float(recm[xi][yi])) + pix[xi, yi] = (color, color, color) +#screen.addstr(0, 0, canvas.frame()) +#screen.refresh() +end() +if (args.b) : + print(canvas.frame()) diff --git a/mandelgen2.py b/mandelgen2.py new file mode 100755 index 0000000..26a3baa --- /dev/null +++ b/mandelgen2.py @@ -0,0 +1,83 @@ +#!/bin/python +#written for py3.5.2 +from drawille import Canvas +import cmath +import math +import curses +from PIL import Image +import argparse +def init () : + global args + parser = argparse.ArgumentParser() + parser.add_argument("-xm", help="max x", + type=int) + parser.add_argument("-ym", help="max y", + type=int) + parser.add_argument("-xt", help="tran x", + type=float) + parser.add_argument("-yt", help="tran y", + type=float) + parser.add_argument("-s", help="scale", + type=float) + parser.add_argument("-b", help="braile", + action="store_true") + parser.add_argument("-t", help="threshhold of calcs", + type=int) + args = parser.parse_args() + global xt + xt = args.xt + global yt + yt = args.yt + global xs + xs = args.s + global ys + ys = args.s + global xm + xm = args.xm + global ym + ym = args.ym + global thr + thr = args.t + global vals + vals = [[]] + if (args.b) : + global canvas + canvas = Canvas() + else : + global img + global pix + img = Image.new('RGB', (xm, ym)) + pix = img.load() +def end () : + if (args.b) : + print(canvas.frame()) + else : + img.save("mandel","PNG") + return +print("initializing....") +init() +print("crunching....") +for xi in range(0, xm, 1) : + for yi in range(0, ym, 1) : + c = complex(xt + (xs * xi), yt - (ys * yi)) + n = complex(0, 0) + t = thr + for i in range(0, thr, 1) : + if (math.sqrt((n.real * n.real) + (n.imag * n.imag)) >= 2 ) : + t = i + break + else : + n = n * n + c + if (args.b) : + if (t != thr) : + canvas.unset(xi, yi) + else : + canvas.set(xi, yi) + else : + color = int(255 - (255 * t / thr)) + pix[xi, yi] = (color, color, color) + if (xi % 100 == 0) : + print(xi) + print(t) +print("saving....\b") +end() -- cgit v1.1