stretch_squeeze.py 766 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python3
  2. from PIL import Image
  3. from math import sin, pi
  4. def main():
  5. inter = Image.open('../figures/interferometer_schematic.png')
  6. size_x, size_y = inter.size
  7. n = 50
  8. def combine(t):
  9. A = 20
  10. w = 2*2*pi/n
  11. offset = int(A*sin(w*t))
  12. bg = Image.new('RGBA', (1000, 1000), color=(255, 255, 255, 0))
  13. inter2 = inter.resize((size_x-offset, size_y+offset))
  14. bg.paste(inter2, box=(50+offset//2, 50-offset//2))
  15. # bg.show()
  16. return bg
  17. frames = [combine(i) for i in range(n)]
  18. frames[0].save('stretch_squeeze.gif', save_all=True, append_images=frames[1:], duration=int(1000/30), loop=0)
  19. frames[0].save('stretch_squeeze_start.gif')
  20. if __name__ == '__main__':
  21. main()