Vector addition of scattering amplitudes from diffraction gratings

This animation plots the scattering amplitude vectors from a homogeneously illuminated grating and plots the diffracted intensity simultaneously. The user is prompted to enter the number of illuminated grooves, the default value being 10. This animation is meant to be educational - the number of illuminated grooves in a real grating numbers several thousand; showing such a vector diagram and intensity plot would result in almost delta-like spikes and one could not follow the change in amplitude with phase. It is therefore advised not to enter much more than 100 for the number of grooves. 

The program uses the matlab function mArrow3.m to generate fancy 3D arrows, which I downloaded from MathWorks File Exchange, and for which I credit Georg Stillfried. I use this function in several of the matlab codes available here.