Programmable optical device