Skip to content

Instantly share code, notes, and snippets.

@madelinecr
Created October 9, 2011 00:22
Show Gist options
  • Save madelinecr/1273101 to your computer and use it in GitHub Desktop.
Save madelinecr/1273101 to your computer and use it in GitHub Desktop.
def man(V,B,c): #Z, C, iter
if abs(V)>=6: #Escape bound. 6 instead of 4 to give smoother fade
return (2+c-4*abs(V)**-0.4)/255 #(0..1]
elif c:
return man(V*V+B,B, c-1) #Reiterate Z=Z*Z+C
else:
return 0 #In set
v=1500 #width
x=1000 #height
from struct import pack
write=open('M.bmp','wb').write
write('BM'+pack('<QIIHHHH',v*x*3+26,26,12,v,x,1,24)) #standard BMP header
for X in range(v*x): #Instead of using a nested loop
T=sum(man(0,(A%3/3.+X%v+(X/v+A/3/3.-x/2)/1j)*2.5/x-2.7,255)**2 for A in (0,1,2,3,4,5,6,7,8))/9 #Convert resolution coord to coord in mandelbrot. Also average 9 points for linear filtering
write(pack('BBB', #This is an RGB triplet. Random numbers for fancy color
T*80+T**9*255-950*T**99,
T*70-880*T**18+701*T**9,
T*255**(1-T**45*2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment