A code for generating fake spectra from a cosmological simulation