itsapi / pycraft

A Minecraft-inspired game for the terminal
GNU General Public License v2.0
197 stars 21 forks source link

Lights - ref #81 #84

Closed geraintwhite closed 8 years ago

geraintwhite commented 8 years ago

Regarding #81, this is a smoother transition between night and day with four colours. It can be improved to go through more shades.

olls commented 8 years ago

This is a relevant discussion about pallet dithering: http://www.pouet.net/topic.php?which=10003&page=1

olls commented 8 years ago

This is the current result from the dithering: image

There are probably some mistakes in the maths.

olls commented 8 years ago

This is an alternative method which just goes through some blue colours:

def sky(x, y, time, sun, lights):
    """ Returns the sky colour. """

    if sun[0] in [x, x+1] and sun[1] == y:
        # Sun pixel
        return YELLOW if cos(time) > 0 else WHITE
    else:
        # Sky pixel
        day, night = (0, 0, 1), (0, 0, 0.2)
        shade = (cos(time) + 1) / 2

        if any(map(lambda l: lit(x, y, l), lights)):
            return rgb(*day)
        else:
            return rgb(0, (5-((15*shade//2)%6))/5, (5-((15*shade)%2))/5)
            # return rgb(*(lerp(day[i], shade, night[i]) for i in range(3)))
geraintwhite commented 8 years ago

The sun should also have a glow around it

geraintwhite commented 8 years ago

The day/night transition still has some shades in the wrong order.

geraintwhite commented 8 years ago

Also, we need to consider the performance - these changes make the game significantly more laggy.

olls commented 8 years ago

The colour_lerp still needs working on...

Yes, we may want to simplify the visuals of this a lot, I'm not even sure if I like the look, it makes it very noisy.

olls commented 8 years ago

Although I haven't noticed the performance difference, I suppose it is because there are more colour changes/bigger diff, and crosh doesn't handle that as well as xfce-terminal

olls commented 8 years ago

There is also a problem with picking the lightest colour to render, ATM we pick the value closest to it's source without considering the actual brightness of the colours. It seems like we might want to use HSL for both finding the brightness, and doing the actual lerp: http://www.alanzucconi.com/2016/01/06/secrets-colour-interpolation

Although that could get expensive...

olls commented 8 years ago

So with HSV colour conversion, we get a nice transition, but there is obvious banding. We should use spacial dithering (not pallet dithering) to hide this.