本文整理汇总了Python中lib.buffer_utils.BufferUtils.fixture_length方法的典型用法代码示例。如果您正苦于以下问题:Python BufferUtils.fixture_length方法的具体用法?Python BufferUtils.fixture_length怎么用?Python BufferUtils.fixture_length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.buffer_utils.BufferUtils
的用法示例。
在下文中一共展示了BufferUtils.fixture_length方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
# 需要导入模块: from lib.buffer_utils import BufferUtils [as 别名]
# 或者: from lib.buffer_utils.BufferUtils import fixture_length [as 别名]
def draw(self, dt):
self._current_time += dt
self._mass_destruction_countdown -= dt
# Ensure that empty displays start up with some seeds
p_birth = (1.0 - self._spontaneous_birth_probability) if self._population > 5 else 0.5
# Spontaneous birth: Rare after startup
if (self._population < self._population_limit) and random.random() + self.parameter('audio-onset-birth-boost').get() > p_birth:
strand = random.randint(0, BufferUtils.num_strands - 1)
fixture = random.randint(0, BufferUtils.strand_num_fixtures(strand) - 1)
pixel = random.randint(0, BufferUtils.fixture_length(strand, fixture) - 1)
address = BufferUtils.logical_to_index((strand, fixture, pixel))
if address not in (self._growing + self._alive + self._dying + self._fading_out):
self._growing.append(address)
self._time[address] = self._current_time
self._population += 1
self._spread_boost *= self.parameter('audio-onset-spread-boost-echo').get()
if self._mixer.is_onset():
self._spread_boost += self.parameter('audio-onset-spread-boost').get()
# Color growth
for address in self._growing:
neighbors = self.scene().get_pixel_neighbors(address)
p, color = self._get_next_color(address, self._growth_time, self._current_time)
if p >= 1.0:
self._growing.remove(address)
self._alive.append(address)
self._time[address] = self._current_time
self.setPixelHLS(address, color)
# Spread
spread_rate = self._spread_rate + self._spread_boost
if (self._population < self._population_limit) and (random.random() < spread_rate * dt):
for spread in neighbors:
if spread not in (self._growing + self._alive + self._dying + self._fading_out):
self._growing.append(spread)
self._time[spread] = self._current_time
self._population += 1
# Lifetime
for address in self._alive:
neighbors = self.scene().get_pixel_neighbors(address)
live_neighbors = [i for i in neighbors if i in self._alive]
lt = self._life_time
if len(neighbors) < 2:
lt = self._isolated_life_time
if len(live_neighbors) < 3 and ((self._current_time - self._time[address]) / lt) >= 1.0:
self._alive.remove(address)
self._dying.append(address)
self._time[address] = self._current_time
self._population -= 1
self.setPixelHLS(address, self._alive_color)
# Spread
if (self._population < self._population_limit) and random.random() < self._birth_rate * dt:
for spread in neighbors:
if spread not in (self._growing + self._alive + self._dying + self._fading_out):
self._growing.append(spread)
self._time[spread] = self._current_time
self._population += 1
# Color decay
for address in self._dying:
p, color = self._get_next_color(address, self._death_time, self._current_time + self.parameter('audio-onset-death-boost').get())
if p >= 1.0:
self._dying.remove(address)
self._fading_out.append(address)
self._time[address] = self._current_time
self.setPixelHLS(address, color)
# Fade out
for address in self._fading_out:
p, color = self._get_next_color(address, self._fade_out_time, self._current_time + self.parameter('audio-onset-death-boost').get())
if p >= 1.0:
self._fading_out.remove(address)
self.setPixelHLS(address, color)
# Mass destruction
if (self._population == self._population_limit) or \
(self._population > self._mass_destruction_threshold and self._mass_destruction_countdown <= 0):
for i in self._alive:
if random.random() > 0.95:
self._alive.remove(i)
self._dying.append(i)
self._population -= 1
for i in self._growing:
if random.random() > 0.85:
self._growing.remove(i)
self._dying.append(i)
self._population -= 1
self._mass_destruction_countdown = self.parameter('mass-destruction-time').get()