If I believe right, blue flames are hotter than red ones and if I recall correctly it's because blue tend to ultraviolet. Then why is the sun, which's capable of warming whole planets, red instead of blue?
The surface of the sun is around 5,700 degrees. The sun radiates all colors of the visible spectrum. The sun radiates like a black body and its spectrum is shown below.
The sun does emit blue light but it also emits red and the other colors with almost the same intensity. A mixture of all the colors results in white light. As the temperature decreases, the peak moves to the right and the sun would start to appear red. Likewise, as you said, if the sun was hotter, the peak would move left and the sun would start to appear blue as the peak approached the ultraviolet part of the spectrum.
The comparison with flames is a bit misleading. Flames look yellow when they have have particles of unburnt carbon in them, and they look blue when there is no unburnt carbon present. The amount of unburnt carbon decreases as the flame gets hotter, so blue flames are indeed (usually) hotter than yellow flames. But this is not a fundamental property of the flame. It's due to the unburnt carbon.
The Sun is not a flame as nothing is burning in it. Instead it is a plasma i.e. it is a gas of ionised hydrogen and helium atoms, and the colour is described by Wien's displacement law. The temperature of the surface is around 5,700K and in fact it is more or less white. We tend to see it as yellowish because the atmosphere scatters blue light, but if you look at the Sun from outside the Earth's atmosphere it looks white.
You can get blue stars, but to have a significant blue colour the stars have to be very hot indeed. The surface temperature needs to be in the range 10,000 - 20,000 K or 2 to 4 times hotter than the Sun. The amount of energy emitted by a star of temperature $T$ is proportional to $T^4$ (see the Stefan Boltzmann law) so if you doubled the temperature of the Sun (and kept it the same size) it would emit 16 times as much heat and rapidly roast us all to a crisp!
The light of the sun contains a mixture of wavelengths - as given by the Planck law. The spectral distribution looks like this:
As you can see, the intensity is biased slightly towards the blue/violet part of the spectrum. However, as we evolved, we have learnt to interpret that mix of colors as "white". Strangely enough, when you are in a room illuminated by tungsten (incandescent) lights, when you see a piece of white paper you will have no trouble identifying it as "white" also. Yet the objective color is much more red/yellow (this is why cameras these days have AWB - automatic white balance - and why you used to have a "tungsten filter" that you would put on your film-based camera if you wanted to shoot slide film indoors: if you didn't, the images would come out looking horribly red).
protected by Qmechanic♦ Dec 18 '17 at 20:09
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?