Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Color type #32

Open
joerick opened this issue Jun 25, 2016 · 0 comments
Open

Add Color type #32

joerick opened this issue Jun 25, 2016 · 0 comments

Comments

@joerick
Copy link
Member

joerick commented Jun 25, 2016

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.

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

No branches or pull requests

1 participant