The Origin of the Diversity of Type Ia Supernovae and the Environmental Effects