python [Kivy] HSVA拾色器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python [Kivy] HSVA拾色器相关的知识,希望对你有一定的参考价值。
from kivy.app import App
from kivy.graphics import Color, Rectangle
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
Builder.load_string('''
<MyLayout>:
orientation: "vertical"
padding: 50, 50, 50, 50
Label:
id: label
font_name: "RobotoMono-Regular"
font_size: 25
outline_color: 0.5,0.5,0.5
outline_width: 1
halign: "right"
Slider:
id: h_slider
Slider:
id: s_slider
Slider:
id: v_slider
Slider:
id: a_slider
''')
class MyLayout(BoxLayout):
initial_hsva = (0, 0.5, 0.5, 1)
background_color = None
sliders = None
def __init__(self, **kwargs):
super(MyLayout, self).__init__(**kwargs)
h,s,v,a = self.initial_hsva
with self.canvas.before:
self.background_color = Color(h,s,v,a, mode="hsv")
self.rect = Rectangle(pos=self.pos, size=self.size)
def on_parent(self, widget, parent):
self.bind(pos=self.update_rect, size=self.update_rect)
self.sliders = (self.ids.h_slider, self.ids.s_slider, self.ids.v_slider, self.ids.a_slider)
initial_slider_values = (x * 100 for x in self.initial_hsva)
for slider, value in zip(self.sliders, initial_slider_values):
slider.bind(
on_touch_down = self.update_color,
on_touch_move = self.update_color,
)
slider.value = value
self.update_color(None, None)
def update_rect(self, instance, size):
self.rect.pos = self.pos
self.rect.size = self.size
def update_color(self, instance, touch):
h,s,v,a = (x.value / 100 for x in self.sliders)
self.background_color.rgba = Color(h,s,v,a, mode="hsv").rgba
h_string = str(round(h * 360)).rjust(3)
s_string, v_string, a_string = (str(round(x * 100)).rjust(3) for x in (s,v,a))
self.ids.label.text = "H: {0}\nS: {1}\nV: {2}\nA: {3}".format(h_string, s_string, v_string, a_string)
class DemoApp(App):
def build(self):
return( MyLayout() )
if __name__ == "__main__":
DemoApp().run()
以上是关于python [Kivy] HSVA拾色器的主要内容,如果未能解决你的问题,请参考以下文章
Android 拾色器透明问题
拾色器
Shader+UGUI仿制Unity拾色器
Android Studio中如何设置颜色拾色器工具
优动漫PAINT基础系列之拾色器教学
php 拾色器代码 - OceanWP