Fractal Art with Python: The Mandelbrot Set
Discover the hidden wonders of the Mandelbrot Set. This tutorial will show you how to use Python to create an infinite and colorful fractal image. No strong mathematical background is required, just curiosity and a passion for learning.
the code is below:
import pygame
import os
os.environ['SDL_VIDEO_CENTERED'] = '1'
width, height = 1550,1080
win = (width, height)
screen = pygame.display.set_mode(win)
xaxis = width/1.80 + 150
yaxis = height/2
scale = 450
iterations = 60
def main():
for iy in range(int(height/2+1)):
for ix in range(width):
z = 0+0j
c = complex(float(ix-xaxis)/scale, float(iy-yaxis)/scale)
x=c.real
y=c.imag
y2=y*y
q=(x-0.25)**2+y2
if not(q*(q+(x-0.25)) 2:
v = 765*i/iterations
if v > 510:
color = (255, 255, v%255)
elif v > 255:
color = (100,v%255 , 255)
else:
color = (0, 0, v%255)
break
else:
color = (0, 0, 0)
screen.set_at((ix, iy), color)
screen.set_at((ix, height-iy), color)
pygame.display.update()
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.key.get_pressed()
pygame.quit()
if __name__ == "__main__":
main()
Join the conversation