Do gases become more opaque as they are cooled or compressed? So recently I was thinking gases (at least colourless ones) are more transparent in their gaseous state than liquid state.
And as we talk of continuity in liquid and gaseous state (fluids) is it possible that gases become more and more opaque as their number density (number of gas molecules per unit volume) increases (by cooling, compression, etc) increases.
Consider a ideally cubical transparent container with a gas in it and compress it continuously. Assume a monochromatic light source behind the container giving out light with constant intensity with all light rays parallel to each other. Would intensity of transmitted light decrease as number density increases?
It would seem true intuitively to me I guess but I cannot figure out why?
So my question:
Is it possible to relate the intensity of transmitted light with number density of gas (Mathematically)?
Please provide validation too for your formula or reasoning.
 A: Relation between transmission and density
You ask for a mathematical relation between the intensity $I$ of the transmitted light and the number density $n$ of gas molecules. It is
$$
I = I_0 \, e^{-n\sigma r},
$$
where $I_0$ is the emitted intensity (i.e. before the beam enters the gas), $\sigma$ is the (wavelength-dependent) cross section of individual particles, and $r$ is the distance traveled through the gas.
Optical depth
The quantity $\tau \equiv nr\sigma$ is called the optical depth of the gas. We sometimes speak of the two different regimes $\tau \ll 1$ and $\tau \gg 1$ as optically thin and optically thick, respectively. In the optically thin regime, "most" light is transmitted. In the optically thick regime, "most" light is absorbed.
Derivation
Consider a light beam of cross-sectional area $A$, traveling a small distance $dr$ (so small that the particles don't "cover" each other). The volume covered is $V=A\,dr$, and the total area of all particles in this volume is $\Sigma = nV\sigma$.
The transmitted fraction $I/I_0$ is equal to the fractional area covered by particles:
$$
\frac{dI}{I} = -\frac{\Sigma}{A} = -n\sigma \,dr.
$$
If there are multiple species of particles, you use $(n_1\sigma_1 + n_2\sigma_2 + \cdots)dr$.
Integrating on both sides (i.e. along the path of the beam),
$$
\begin{array}{rcl}
\int_{_{I_0}}^{^{I}}\frac{dI'}{I} & = & -\int_0^r n\sigma\,dr'\\
\ln I - \ln I_0 & = & n\sigma r\\
\frac{I}{I_0} & = & e^{-n \sigma r}.
\end{array}
$$
A: Clear air is colorless in the visible spectrum. Yet consider what happens when the Sun changes its altitude from high in the sky to just over horizon: intensity of solar radiation decreases for an earthly observer. That's due to scattering (Rayleigh scattering, in particular, is relevant here) from a larger amount of atmospheric gases.
Also, when you go higher above the ground (e.g. in an airplane), you get more solar radiation from the Sun at the same zenith angle. That's due to lower atmospheric density at high altitudes, which results in less scattering along the path between the Sun and the airborne observer.
So yes, due to scattering, gases do become less transparent with increase of molecule number density.

Is it possible to relate the intensity of transmitted light with number density of gas (Mathematically)?

Yes, you want to learn the Beer–Lambert law.
