本文整理汇总了Python中lib.buffer_utils.BufferUtils.index_to_logical方法的典型用法代码示例。如果您正苦于以下问题:Python BufferUtils.index_to_logical方法的具体用法?Python BufferUtils.index_to_logical怎么用?Python BufferUtils.index_to_logical使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.buffer_utils.BufferUtils
的用法示例。
在下文中一共展示了BufferUtils.index_to_logical方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_pixel_neighbors
# 需要导入模块: from lib.buffer_utils import BufferUtils [as 别名]
# 或者: from lib.buffer_utils.BufferUtils import index_to_logical [as 别名]
def get_pixel_neighbors(self, index):
"""
Returns a list of pixel addresses that are adjacent to the given address.
"""
neighbors = self._pixel_neighbors_cache.get(index, None)
if neighbors is None:
neighbors = []
strand, address, pixel = BufferUtils.index_to_logical(index)
f = self.fixture(strand, address)
neighbors = [BufferUtils.logical_to_index((strand, address, p)) for p in f.pixel_neighbors(pixel)]
if (pixel == 0) or (pixel == f.pixels - 1):
# If this pixel is on the end of a fixture, consider the neighboring fixtures
loc = 'end'
if pixel == 0:
loc = 'start'
logical_neighbors = self.get_colliding_fixtures(strand, address, loc)
neighbors += [BufferUtils.logical_to_index(n) for n in logical_neighbors]
self._pixel_neighbors_cache[index] = neighbors
return neighbors
示例2: get_pixel_location
# 需要导入模块: from lib.buffer_utils import BufferUtils [as 别名]
# 或者: from lib.buffer_utils.BufferUtils import index_to_logical [as 别名]
def get_pixel_location(self, index):
"""
Returns a given pixel's location in scene coordinates.
"""
loc = self._pixel_locations_cache.get(index, None)
if loc is None:
strand, address, pixel = BufferUtils.index_to_logical(index)
f = self.fixture(strand, address)
if pixel == 0:
loc = f.pos1
elif pixel == (f.pixels - 1):
loc = f.pos2
else:
x1, y1 = f.pos1
x2, y2 = f.pos2
scale = float(pixel) / f.pixels
relx, rely = ((x2 - x1) * scale, (y2 - y1) * scale)
loc = (x1 + relx, y1 + rely)
self._pixel_locations_cache[index] = loc
return loc
示例3: draw
# 需要导入模块: from lib.buffer_utils import BufferUtils [as 别名]
# 或者: from lib.buffer_utils.BufferUtils import index_to_logical [as 别名]
def draw(self, dt):
self._current_time += dt
# Spontaneous birth: Rare after startup
if (len(self._dragons) < self.parameter('pop-limit').get()) and random.random() < self.parameter('birth-rate').get():
strand = random.randint(0, BufferUtils.num_strands - 1)
fixture = random.randint(0, BufferUtils.strand_num_fixtures(strand) - 1)
address = BufferUtils.logical_to_index((strand, fixture, 0))
if address not in [d.loc for d in self._dragons]:
self._dragons.append(self.Dragon(address, 1, self._current_time))
growth_rate = self.parameter('growth-rate').get()
# Dragon life cycle
for dragon in self._dragons:
# Fade in
if dragon.growing:
p = (self._current_time - dragon.lifetime) / self.parameter('growth-time').get()
if (p > 1):
p = 1.0
color = self._growth_fader.get_color(p * self._fader_steps)
if p >= 1.0:
dragon.growing = False
dragon.alive = True
dragon.lifetime = self._current_time
self.setPixelHLS(dragon.loc, color)
# Alive - can move or die
if dragon.alive:
dragon.growth += dt * growth_rate
for times in range(int(dragon.growth)):
s, f, p = BufferUtils.index_to_logical(dragon.loc)
self.setPixelHLS(dragon.loc, (0, 0, 0))
if random.random() < dragon.growth:
dragon.growth -= 1
# At a vertex: optionally spawn new dragons
if dragon.moving and (p == 0 or p == (self.scene().fixture(s, f).pixels - 1)):
neighbors = self.scene().get_pixel_neighbors(dragon.loc)
neighbors = [BufferUtils.index_to_logical(n) for n in neighbors]
random.shuffle(neighbors)
# Kill dragons that reach the end of a fixture
dragon.moving = False
if dragon in self._dragons:
self._dragons.remove(dragon)
# Iterate over candidate pixels that aren't on the current fixture
num_children = 0
for candidate in [n for n in neighbors if n[1] != f]:
child_index = BufferUtils.logical_to_index(candidate)
if num_children == 0:
# Spawn at least one new dragon to replace the old one. This first one skips the growth.
dir = 1 if candidate[2] == 0 else -1
child = self.Dragon(child_index, dir, self._current_time)
child.growing = False
child.alive = True
child.moving = False
self._dragons.append(child)
num_children += 1
elif (len(self._dragons) < self.parameter('pop-limit').get()):
# Randomly spawn new dragons
if random.random() < self.parameter('birth-rate').get():
dir = 1 if candidate[2] == 0 else -1
child = self.Dragon(child_index, dir, self._current_time)
child.moving = False
self._dragons.append(child)
num_children += 1
break;
else:
# Move dragons along the fixture
self._tails.append((dragon.loc, self._current_time, self._tail_fader))
new_address = BufferUtils.logical_to_index((s, f, p + dragon.dir))
dragon.loc = new_address
dragon.moving = True
self.setPixelHLS(new_address, self._alive_color)
# Kill dragons that run into each other
if dragon in self._dragons:
colliding = [d for d in self._dragons if d != dragon and d.loc == dragon.loc]
if len(colliding) > 0:
#print "collision between", dragon, "and", colliding[0]
self._dragons.remove(dragon)
self._dragons.remove(colliding[0])
self._tails.append((dragon.loc, self._current_time, self._explode_fader))
neighbors = self.scene().get_pixel_neighbors(dragon.loc)
for neighbor in neighbors:
self._tails.append((neighbor, self._current_time, self._explode_fader))
break
# Draw tails
for loc, time, fader in self._tails:
if (self._current_time - time) > self.parameter('tail-persist').get():
if (loc, time, fader) in self._tails:
self._tails.remove((loc, time, fader))
#.........这里部分代码省略.........