Browse Source

added option to specify approximate animation time

master
Fr3deric 7 years ago
parent
commit
1dd2d0a943
  1. 28
      generators/fireworks.py

28
generators/fireworks.py

@ -71,9 +71,20 @@ class Rocket:
def getRandomColor(maxval): def getRandomColor(maxval):
return list(map(lambda x: int(round(x*maxval)), colorsys.hsv_to_rgb(random.random(), 1, 1))) return list(map(lambda x: int(round(x*maxval)), colorsys.hsv_to_rgb(random.random(), 1, 1)))
def gen_rockets(num, now=0):
for i in range(num):
yield Rocket(
np.array([random.randint(0, dim.width-1), dim.height-1]),
np.array([random.randint(-8, 8), -20 + random.randint(-2, 2)]),
4 + random.randint(-2, 2),
now + random.randint(0, 40) / 10,
np.array([dim.depth-1] * 3)
)
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate plasma animations') parser = argparse.ArgumentParser(description='Generate plasma animations')
parser.add_argument('-d', '--delay', type=int, default=50) parser.add_argument('-d', '--delay', type=int, default=50)
parser.add_argument('-t', '--time', type=int, default=0)
parser.add_argument('-n', '--num-rockets', type=int, default=3) parser.add_argument('-n', '--num-rockets', type=int, default=3)
parser.add_argument('output_file') parser.add_argument('output_file')
args = parser.parse_args() args = parser.parse_args()
@ -82,17 +93,7 @@ if __name__ == '__main__':
anim = blup.animation.Animation(dim) anim = blup.animation.Animation(dim)
anim.tags['description'] = ' '.join(sys.argv) anim.tags['description'] = ' '.join(sys.argv)
rockets = [] rockets = list(gen_rockets(args.num_rockets))
for i in range(args.num_rockets):
rockets.append(
Rocket(
np.array([random.randint(0, dim.width-1), dim.height-1]),
np.array([random.randint(-8, 8), -20 + random.randint(-2, 2)]),
4 + random.randint(-2, 2),
random.randint(0, 40) / 10,
np.array([dim.depth-1] * 3)
)
)
fbs = [] fbs = []
t = 0 t = 0
@ -126,6 +127,11 @@ if __name__ == '__main__':
anim.addFrame(frame) anim.addFrame(frame)
if len(rockets) == 0 and len(fbs) == 0: if len(rockets) == 0 and len(fbs) == 0:
if t < args.time:
frame = blup.animation.AnimationFrame(dim, 700)
anim.addFrame(frame)
rockets = list(gen_rockets(args.num_rockets, t))
else:
break break
t += args.delay / 1000 t += args.delay / 1000

Loading…
Cancel
Save