-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
Description
Currently colors are represented in tingbot using tuples or strings. While this is convenient, it holds us back from adding functionality around colors e.g. blending, darker/lighter methods, HSL constructors.
I propose a Color type to solve this. Common usage will be using a rgb() or rgba() constructor functions:
import tingbot
from tingbot import *
def loop():
screen.fill(color=rgb(20,20,20))
screen.text('Hello, world!', color=rgba(255,128,128,0.5))
tingbot.run(loop)The syntax deliberately matches the CSS syntax for rgb and rgba. We'll also provide hsl and hsla functions for color-wheel color picking.
More advanced usage using the object directly-
import tingbot
from tingbot import *
def loop():
bg_color = Color.from_name('green')
screen.fill(color=bg_color)
screen.text('Hello, world!', color=bg_color.darker())
tingbot.run(loop)All the graphics routines that take a color parameter will continue to accept tuples/strings, and convert to color objects internally.