Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Created January 13, 2020 21:21
Show Gist options
  • Save tshirtman/b2b6532dc8f30671488803da6febb16e to your computer and use it in GitHub Desktop.
Save tshirtman/b2b6532dc8f30671488803da6febb16e to your computer and use it in GitHub Desktop.
from kivy.app import App
from kivy.lang import Builder
from kivy.factory import Factory
from kivy.properties import ListProperty, NumericProperty
KV = '''
<Tile@Label>:
bg_hue: 0
font_size: sp(25)
canvas.before:
Color:
hsv: self.bg_hue, app.saturation, app.value
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
orientation: 'vertical'
RecycleView:
id: rv
data: app.tiles
viewclass: 'Tile'
RecycleGridLayout:
cols: int(len(rv.data) ** .5) + 1
padding: sp(10)
spacing: sp(10)
BoxLayout:
size_hint_y: None
height: sp(48)
Hues:
Saturation:
Value:
<Hues@BoxLayout>:
orientation: 'vertical'
Label:
text: 'tiles'
Slider:
step: 1
value: app.hues
min: 1
max: 100
on_value: app.hues = self.value
<Saturation@BoxLayout>:
orientation: 'vertical'
Label:
text: 'saturation'
Slider:
value: app.saturation
min: 0
max: 1
on_value: app.saturation = self.value
<Value@BoxLayout>:
orientation: 'vertical'
Label:
text: 'value'
Slider:
value: app.value
min: 0
max: 1
on_value: app.value = self.value
'''
class Application(App):
tiles = ListProperty()
hues = NumericProperty(10)
saturation = NumericProperty(.5)
value = NumericProperty(.5)
def build(self):
return Builder.load_string(KV)
def on_hues(self, inst, value):
inc_hue = 1 / value
self.tiles = [
{
'text': f'{x}: {inc_hue * x:.2f}',
'bg_hue': inc_hue * x
}
for x in range(value)
]
if __name__ == "__main__":
Application().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment