Advertisement
miklis

Plotas su Python

Jun 24th, 2019
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #IT's very important to choose a correct file location:
  2. location=r"C:\Users\Vartotojas\Desktop\EnolaProject\Matematikos idejos\Visual Tools\2 budai paaiskinti skritulio plotui\integral division\frames\intos"
  3.  
  4. #a .gif file will be saved as plotas.gif"
  5. #It takes about 2 minutes to render 100 frames because part of picture is taken from thre result of .tex compilation
  6.  
  7. from PIL import Image, ImageDraw
  8. from pytex import snap_tex
  9. import webbrowser
  10. from images2gif import writeGif
  11. ims=[]
  12. radius=126
  13. text=500
  14. for it in range(1,101):
  15. #it=2**it
  16. im = Image.new('RGB', (2*radius+text,2*radius), 'white')
  17. draw = ImageDraw.Draw(im)
  18. #draw.ellipse([(0,0),(2*radius,2*radius)], fill='orange', outline='blue')
  19. lightblue_cells, blue_cells, darkblue_cells=[],[],[]
  20. for w in range(it):
  21. for h in range(it):
  22. S=radius*it
  23. a,b,c,d=2.*radius*w, 2.*radius*h, 2.*radius*(1+w), 2.*radius*(1+h)
  24. distances_from_centrum=((a-S)*(a-S)+(b-S)*(b-S), (a-S)*(a-S)+(d-S)*(d-S), (c-S)*(c-S)+(d-S)*(d-S), (c-S)*(c-S)+(b-S)*(b-S))
  25. current_rectangle=[(2.*radius*w/it, 2.*radius*h/it), (2.*radius*(1+w)/it, 2.*radius*(1+h)/it)]
  26. if all([n>S**2 for n in distances_from_centrum]):
  27. lightblue_cells.append(current_rectangle)
  28. else:
  29. if all([n<=S**2 for n in distances_from_centrum]):
  30. darkblue_cells.append(current_rectangle)
  31. else:
  32. blue_cells.append(current_rectangle)
  33.  
  34. for n in lightblue_cells: draw.rectangle(n, fill='yellow', outline='lightblue')
  35. for n in darkblue_cells: draw.rectangle(n, fill='darkblue', outline='darkblue')
  36. for n in blue_cells: draw.rectangle(n, fill='blue', outline='lightblue')
  37.  
  38. draw.ellipse([(0,0),(2*radius,2*radius)], outline='magenta')
  39. del draw
  40. comment=open('plotas_comment.tex','r').read()
  41. if it>1: im.paste(snap_tex(eval(comment)), (2*radius+1, 0))
  42. im.save(location+str(it)+".png")
  43. ims.append(im)
  44.  
  45. writeGif('plotas.gif', ims, duration=2.0)
  46. webbrowser.open('plotas.gif')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement