fork download
  1. import Image, ImageDraw, random
  2.  
  3. #from http://c...content-available-to-author-only...e.com/recipes/577111-mandelbrot-fractal-using-pil/
  4. # Mandelbrot fractal
  5. # FB - 201003254
  6. # drawing area
  7. xa = -2.0
  8. xb = 1.0
  9. ya = -1.5
  10. yb = 1.5
  11. maxIt = 255 # max iterations allowed
  12. # image size
  13. imgx = 512
  14. imgy = 512
  15. image = Image.new("RGB", (imgx, imgy))
  16.  
  17. x = .3
  18. y = -.1
  19.  
  20. for i in xrange(100000):
  21. c = random.randint(0,2)
  22. if c is 0:
  23. x = x/2.0
  24. y = y/2.0
  25. if c is 1:
  26. x = (x+1)/2.0
  27. y = (y)/2.0
  28. if c is 2:
  29. x = x/2.0
  30. y = (y+1)/2.0
  31. cx = x * imgx
  32. cy = y * imgy
  33. if x >= 0 and y >= 0 and x < imgx and y < imgy and i > 20:
  34. image.putpixel((int(cx), int(cy)), (255,255,255))
  35.  
  36.  
  37.  
  38.  
  39. # ideone output
  40. import StringIO
  41. output = StringIO.StringIO()
  42. image.save(output, 'PNG')
  43. contents = output.getvalue()
  44. output.close()
  45. print contents
Success #stdin #stdout 0.91s 12016KB
stdin
Standard input is empty
stdout