from PIL import Image
import math
class Coordinate():
'''class Coordinate by Rafael'''
x = None
y = None
def __init__(self,content):
# try:
Coordinate.x=content[0]/1+150
Coordinate.y=content[1]/1+150
# except:
# print (r'class Coordinate except')
# raise myException
def main():
lut=[] # look up table
for i in range (256):
i0=math.sqrt(float(i))*16
i0=int(i0)
if i0>255:
i0=255
lut.append(i0)
print('len(lut) = ',len(lut))
coor0 = Coordinate((150,150))
im0 = Image.new("RGBA",(300,300))
fw=open(r'mandelbrot.txt','w')
cntAll = 0
for j in range (-150,150,1):
for i in range (-150,150,1):
coor0 = Coordinate((i,j))
cntAll = cntAll +1
cnt = 0
arg = 0.0+0.0j
arg = 0
c = complex(float(i)/100,float(j)/100)
while arg.real <10 and cnt <256:
arg = arg*arg+c
cnt = cnt + 1
im0.putpixel((coor0.x,coor0.y),(lut[cnt-1],lut[cnt-1],lut[cnt-1],255))
fw.write('\n')
print(cntAll)
im0.save(r'mandelbrot.png')
print(time.clock())
# print(dir())
os.chdir(str(os.path.split(os.path.realpath(__file__))[0]))
if __name__ == '__main__':
main()
#***************************************************************
在 2015年10月15日星期四 UTC+8上午11:30:23,atommann写道: