Hydrogels embedded with periodic arrays of nanoparticles display a striking photonic crystal coloration that may be useful for applications such as camouflage, anticounterfeiting, and chemical sensing. Dynamically generating color patterns requires control of nanoparticle organization within a polymer network on-demand, which is challenging. We solve this problem by creating a DNA hydrogel system that shows a 50 000-fold decrease in modulus upon heating by ~10 deg C. Magnetic nanoparticles entrapped within these DNA gels generate a structural color only when the gel is heated and a magnetic field is applied. A spatially controlled photonic crystal coloration was achieved by photopatterning with a near-infrared illumination. Color was "erased" by illuminating or heating the gel in the absence of an external magnetic field. The on-demand assembly technology demonstrated here may be beneficial for the development of a new generation of smart materials with potential applications in erasable lithography, encryption, and sensing.