20110102

Bůh je matematik...

...a já jsem bůh

Aneb takhle nějak by to mohlo vypadat, ještě než se vrhnu na optimalizaci...

from Blender import Redraw,Save
import bpy
from random import randrange
me=bpy.data.meshes['Mandel']
#me=bpy.data.meshes.new('Mandel')
#scn = bpy.data.scenes.active
#ob = scn.objects.new(me, 'Mandel')
batches=[]
vertcount=1
curbatch=0
def batch(x,y):
 global batches
 global vertcount
 global curbatch
 batches.append([x,y,0])
 if(vertcount%10000==0):
  me.verts.extend(batches)
  batches=[]
  name="C:\Users\programagor\mandel{0}.blend".format(curbatch%2)
#  name="C:\Users\programagor\mandel.blend"
  Save(name,1)
  Redraw()
  curbatch+=1
  print "--prubeh ulozen (",name,")--"
 vertcount+=1

def check(r,i,it,bail):
 zr=r
 zi=i
 a=1
 while a<=it:
  zr,zi=zr*zr-zi*zi+r,2*zr*zi+i
  if (zr**2+zi**2)>=bail:
   return False
  a+=1
 return True

def plot(r,i,it,bail):
 zr=r
 zi=i
 a=1
 while a<=it:
  zr,zi=zr*zr-zi*zi+r,2*zr*zi+i
  if ((zr>-3)&(zr<2)&(zi>-2.5)&(zi<2.5)):
   batch(zr,zi)
  if (zr**2+zi**2)>=bail:
   return False
  a+=1
 return True

try:
 a=1
 while 0==0:

  r=randrange(-50000000000000,50000000000000)/10000000000000.0
  i=randrange(-50000000000000,50000000000000)/10000000000000.0
  if (a%1000)==0:
   print a,"iterovanych bodu Z,",vertcount,"bodu naneseno"
  if check(r,i,100000,50)==False:
   plot(r,i,100000,50)
  a+=1

finally:
 me.verts.extend(batches)
 print "--prubeh ulozen--"
 print "Celkem iterovano",a,"bodu Z,",vertcount,"bodu naneseno"

A výsledek kódu

Žádné komentáře:

Okomentovat