本文整理汇总了Python中kivy.core.image.Image.read_pixel方法的典型用法代码示例。如果您正苦于以下问题:Python Image.read_pixel方法的具体用法?Python Image.read_pixel怎么用?Python Image.read_pixel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.core.image.Image
的用法示例。
在下文中一共展示了Image.read_pixel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Sheep
# 需要导入模块: from kivy.core.image import Image [as 别名]
# 或者: from kivy.core.image.Image import read_pixel [as 别名]
class Sheep(Scatter):
image = ObjectProperty(None)
canMove = BooleanProperty(False)
idx_frame = NumericProperty(0.0)
previous_position = ObjectProperty(None)
def __init__(self, **kwargs):
super(Sheep, self).__init__(**kwargs)
self.image = CoreImage('images/maze.png', keep_data=True)
self.previous_position = self.pos
def on_touch_down(self, touch):
if not self.canMove:
return
ret = super(Sheep, self).on_touch_down(touch)
if not ret:
return
return True
def on_touch_move(self, touch):
if not self.canMove:
return
x, y = touch.pos
if not self or not self.parent or not self.parent.maze:
return
mazeimg = self.parent.maze
x -= mazeimg.x
y -= mazeimg.y
x = int(x)
y = int(y)
y = self.parent.maze.height - y
try:
color = self.image.read_pixel(x, y)
except IndexError:
return
if color[-1] == 0:
return
if self.idx_frame == 10 :
if touch.x != self.previous_position[0]:
angle = math.degrees(math.atan((self.previous_position[1]-touch.y)/(self.previous_position[0]-touch.x)))
if self.previous_position[0] > touch.x :
angle += 180
else:
angle = 90 * math.copysign(1, self.rotation)
self.rotation = angle
self.previous_position = touch.pos
self.idx_frame=0
else :
self.idx_frame+=1
#print angle
# ret = super(Sheep, self).on_touch_move(touch)
# return ret
if abs(touch.x - self.center_x) < 50 and abs(touch.y - self.center_y) < 50:
ret = super(Sheep, self).on_touch_move(touch)
return ret
return True
def on_touch_up(self, touch):
if not self.canMove:
return
if not touch.grab_current == self:
return False
ret = super(Sheep, self).on_touch_up(touch)
return ret