**```python
import pygame,sys
from pygame.locals import *
WINDOWWIDTH=500
WINDOWHEIGHT=500
BLACK=(0,0,0)
BLUE=(0,0,168)
GREEN=(0,168,0)
CYAN=(0,168,168)
RED=(168,0,0)
MAGENTA=(168,0,168)
BROWN=(168,84,0)
LIGHTGRAY=(168,168,168)
DARKGRAY=(84,84,84)
LIGHTBLUE=(84,84,255)
LIGHTGREEN=(84,255,84)
LIGHTCYAN=(84,255,255)
LIGHTRED=(255,84,84)
LIGHTMAGENTA=(255,84,255)
YELLOW=(255,255,84)
WHITE=(255,255,255)
COLOR=[BLACK,BLUE,GREEN,CYAN,RED,MAGENTA,BROWN,LIGHTGRAY,DARKGRAY,LIGHTBLUE,LIGHTGREEN,LIGHTCYAN,LIGHTRED,LIGHTMAGENTA,YELLOW,WHITE]
def drawMandelbrotSet(reCmax,imCmax,reCmin,imCmin):
pygame.init()
windowSurface=pygame.display.set_mode((WINDOWWIDTH,WINDOWHEIGHT),0,32)
pygame.display.set_caption('MandelbrotSet')
deltReC=(reCmax-reCmin)/500
deltImC=(imCmax-imCmin)/500
for xCord in range(0,500):
for yCord in range(0,500):
reC=reCmin+deltReC*xCord
imC=imCmin+deltImC*yCord
reZ=0
imZ=0
for nTimes in range(0,160):
tmpReZ=reZ*reZ-imZ*imZ+reC
imZ=2*reZ*imZ+imC
reZ=tmpReZ
absZ=reZ*reZ+imZ*imZ
if absZ>=4:
nColor=int(nTimes/10)
break
nColor=0
#pygame.draw.rect(windowSurface,WHITE, [xCord, yCord, 1, 1], width=1)
#windowSurface.set_at([xCord,yCord],COLOR[nColor])
pixArray=pygame.PixelArray(windowSurface)
pixArray[xCord][yCord]=COLOR[nColor]
del pixArray
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
drawMandelbrotSet(1.75,1.5,-2.25,-1.8)
```**
python下的一个显示Mandelbrot集的小程序
最新推荐文章于 2024-07-25 18:55:58 发布