Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #IT's very important to choose a correct file location:
- location=r"C:\Users\Vartotojas\Desktop\EnolaProject\Matematikos idejos\Visual Tools\2 budai paaiskinti skritulio plotui\integral division\frames\intos"
- #a .gif file will be saved as plotas.gif"
- #It takes about 2 minutes to render 100 frames because part of picture is taken from thre result of .tex compilation
- from PIL import Image, ImageDraw
- from pytex import snap_tex
- import webbrowser
- from images2gif import writeGif
- ims=[]
- radius=126
- text=500
- for it in range(1,101):
- #it=2**it
- im = Image.new('RGB', (2*radius+text,2*radius), 'white')
- draw = ImageDraw.Draw(im)
- #draw.ellipse([(0,0),(2*radius,2*radius)], fill='orange', outline='blue')
- lightblue_cells, blue_cells, darkblue_cells=[],[],[]
- for w in range(it):
- for h in range(it):
- S=radius*it
- a,b,c,d=2.*radius*w, 2.*radius*h, 2.*radius*(1+w), 2.*radius*(1+h)
- 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))
- current_rectangle=[(2.*radius*w/it, 2.*radius*h/it), (2.*radius*(1+w)/it, 2.*radius*(1+h)/it)]
- if all([n>S**2 for n in distances_from_centrum]):
- lightblue_cells.append(current_rectangle)
- else:
- if all([n<=S**2 for n in distances_from_centrum]):
- darkblue_cells.append(current_rectangle)
- else:
- blue_cells.append(current_rectangle)
- for n in lightblue_cells: draw.rectangle(n, fill='yellow', outline='lightblue')
- for n in darkblue_cells: draw.rectangle(n, fill='darkblue', outline='darkblue')
- for n in blue_cells: draw.rectangle(n, fill='blue', outline='lightblue')
- draw.ellipse([(0,0),(2*radius,2*radius)], outline='magenta')
- del draw
- comment=open('plotas_comment.tex','r').read()
- if it>1: im.paste(snap_tex(eval(comment)), (2*radius+1, 0))
- im.save(location+str(it)+".png")
- ims.append(im)
- writeGif('plotas.gif', ims, duration=2.0)
- webbrowser.open('plotas.gif')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement