Skip to content

Instantly share code, notes, and snippets.

@WitherOrNot
Created January 4, 2020 06:08
Show Gist options
  • Save WitherOrNot/69a3e9f096f8ba24983186eb9682ea0e to your computer and use it in GitHub Desktop.
Save WitherOrNot/69a3e9f096f8ba24983186eb9682ea0e to your computer and use it in GitHub Desktop.
how original
from __future__ import division
import pygame
import sys
import os
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
if key[pygame.K_DOWN] == 1:
psy += 0.01
if key[pygame.K_LEFT] == 1:
psx -= 0.01
if key[pygame.K_RIGHT] == 1:
psx += 0.01
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 = 1
if scl == -9:
scl = -10
if scl == 11:
scl = 20
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 = zx * zy
zx = zx * zx - zy * zy + cx
zy = 2 * xt + cy
i = i + 1
scr.set_at((x, y), (i, i, i))
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