當前位置: 首頁>>代碼示例>>Python>>正文


Python Box.point_interval方法代碼示例

本文整理匯總了Python中box.Box.point_interval方法的典型用法代碼示例。如果您正苦於以下問題:Python Box.point_interval方法的具體用法?Python Box.point_interval怎麽用?Python Box.point_interval使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在box.Box的用法示例。


在下文中一共展示了Box.point_interval方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Colorpicker

# 需要導入模塊: from box import Box [as 別名]
# 或者: from box.Box import point_interval [as 別名]
class Colorpicker(Box):
    def __init__(self, argon):
        self.hue = 0.0
        self.saturation = 0.0
        self.value = 1.0
        self.gradient = argon.image('hue-saturation-360x256.png')
        Box.__init__(self, 0, 0,  480+20, 256+20)
        self.which = -1

    @property
    def rgba(self):
        return hsva(self.hue, self.saturation, self.value).rgba

    def update(self):
        self.major   = Box(self.left+10+0,   self.top+10, 360, 256)
        self.minor   = Box(self.left+10+360, self.top+10, 30,  256)
        self.preview = Box(self.left+10+390, self.top+10, 90,  256)

    def render(self, argon):
        self.update()
        v1 = hsva(self.hue, self.saturation, 1.0).rgba
        x0, y0 = self.major.interpolate((self.hue/360.0, self.saturation))
        x1, y1 = self.minor.interpolate((0, 1-self.value))
        argon.render([
            (self.rect, black, argon.plain),
            (self.major.rect, white.mix(black, self.value), self.gradient),
            (self.minor.rect, (v1, v1, black, black), argon.plain),
            (self.preview.rect, self.rgba, argon.plain),
            ((x0, y0, 1, 1), black, argon.plain),
            ((x1, y1, 30, 1), black, argon.plain),
        ])

    def setcolor(self, pos, which):
        if which == 0:
            i, j = self.major.point_interval(pos)
            self.hue        = i * 360.0
            self.saturation = j
        elif which == 1:
            i, j = self.minor.point_interval(pos)
            self.value = 1 - j

    def mousedown(self, button, pos):
        if button == 1:
            if self.major.point_inside(pos):
                self.setcolor(pos, 0)
                self.which = 0
            if self.minor.point_inside(pos):
                self.setcolor(pos, 1)
                self.which = 1

    def mouseup(self, button, pos):
        self.which = -1

    def mousemotion(self, pos, vel):
        self.setcolor(pos, self.which)
開發者ID:cheery,項目名稱:essence,代碼行數:57,代碼來源:colorpicker.py


注:本文中的box.Box.point_interval方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。