Last active
January 4, 2020 06:11
-
-
Save WitherOrNot/d8fdb3d73f96b5aaa4a9bea96b882b4f to your computer and use it in GitHub Desktop.
+4 chars = totally new fractal apparently
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
import pygame | |
import sys | |
import os | |
import math | |
pygame.init() | |
scr = pygame.display.set_mode((200,200)) | |
psx = -2 | |
psy = -2 | |
scl = 50 | |
if not os.path.isdir("mandel"): | |
os.mkdir("mandel") | |
def mandelrender(x, y, s): | |
psx = x | |
psy = y | |
scl = s | |
while True: | |
key = pygame.key.get_pressed() | |
if key[pygame.K_x] == 1: | |
scl += 10 | |
if key[pygame.K_z] == 1: | |
scl -= 10 | |
if key[pygame.K_UP] == 1: | |
psy -= 0.01/((scl//1000)+1) | |
if key[pygame.K_DOWN] == 1: | |
psy += 0.01/((scl//1000)+1) | |
if key[pygame.K_LEFT] == 1: | |
psx -= 0.01/((scl//1000)+1) | |
if key[pygame.K_RIGHT] == 1: | |
psx += 0.01/((scl//1000)+1) | |
if key[pygame.K_RETURN] == 1: | |
pygame.image.save(scr, "mandel/mandel_"+str(psx)+"_"+str(psy)+"_"+str(scl)+".png") | |
if key[pygame.K_ESCAPE] == 1: | |
pygame.quit() | |
sys.exit() | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
pygame.quit() | |
sys.exit() | |
pygame.event.pump() | |
for y in range(200): | |
for x in range(200): | |
if scl <= 0: | |
scl = 10 | |
i = 0 | |
cx = psx + x / scl | |
cy = psy + y / scl | |
zx = 0 | |
zy = 0 | |
""" | |
Good values: | |
psx: -0.45, -0.68 | |
psy: -0.66, -0.74 | |
scl: 2400, 1200 | |
""" | |
while i < 255 and (zx * zx + zy * zy) < 4: | |
#""" | |
xt = abs(zx) * abs(zy) | |
zx = abs(zx) * abs(zx) - abs(zy) * abs(zy) + cx | |
zy = 2 * xt + cy | |
i = i + 1 | |
#""" | |
c = 3 * math.log(i) / math.log(255) | |
if c < 1: | |
scr.set_at((x, y), (int(255 * c), 0, 0)) | |
elif c < 2: | |
scr.set_at((x, y), (255, int(255*(c-1)), 0)) | |
else: | |
scr.set_at((x, y), (255, 255, int(255*(c-2)))) | |
if i == 255: | |
scr.set_at((x, y), (0,0,0)) | |
pygame.display.flip() | |
sys.stdout.write("x: "+str(psx)+" y: "+str(psy)+" zoom: "+str(scl)+" \r") | |
#""" | |
pygame.display.set_caption("Mandelbrot") | |
mandelrender(psx, psy, scl) | |
#""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment