Skip to content

Add Color type #32

Description

@joerick

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions