Last active
June 11, 2019 21:41
-
-
Save inclement/85a4dba50edb4d0400a3b6a249543e8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.base import runTouchApp | |
from kivy.lang import Builder | |
from kivy.uix.widget import Widget | |
from kivy.properties import ListProperty | |
from kivy.core.window import Window | |
from colorsys import hls_to_rgb | |
class ColourApp(App): | |
def build(self): | |
root = Builder.load_string(''' | |
<ColourWidget>: | |
canvas: | |
Color: | |
rgb: root.colour | |
Rectangle: | |
pos: root.pos | |
size: root.size | |
''') | |
return ColourWidget() | |
class ColourWidget(Widget): | |
colour = ListProperty([0, 0, 0]) | |
def __init__(self, **kwargs): | |
super().__init__(**kwargs) | |
Window.bind(mouse_pos=self.update_colour) | |
def update_colour(self, instance, value): | |
x, y = value | |
x /= Window.size[0] | |
y /= Window.size[1] | |
self.colour = hls_to_rgb(x, y, 1) | |
ColourApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment