-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f66efd
commit e61c1ae
Showing
3 changed files
with
177 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
__version__ = '0.1.31' | ||
__version__ = '0.1.32' | ||
|
||
_classifiers = [ | ||
'Development Status :: 4 - Beta', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
""" | ||
Day 31 - Fireworks (version A) | ||
My take on the fireworks theme. Colored blobs growing and sparkling. | ||
This version gives one explosion at a time at controlled intervalls. | ||
Suits best for smaller nonregular installations, eg a christmas tree. | ||
Also check the version in day31b. | ||
""" | ||
|
||
from xled_plus.samples.sample_setup import * | ||
|
||
|
||
class Fireball(Shape): | ||
def __init__(self, cent, minrad, maxrad, speed, huesat): | ||
super(Fireball, self).__init__(cent, 0.0) | ||
self.rad = minrad | ||
self.minrad = minrad | ||
self.maxrad = maxrad | ||
self.speed = speed | ||
self.huesat = huesat | ||
|
||
def is_inside(self, coord): | ||
return ( | ||
sum(map(lambda x1, x2: (x1 - x2) ** 2, self.cent, coord)) <= self.rad ** 2 | ||
) | ||
|
||
def get_color(self, coord, ind): | ||
dist2 = ( | ||
sum(map(lambda x1, x2: (x1 - x2) ** 2, self.cent, coord)) / self.rad ** 2 | ||
) | ||
if dist2 > 1.0: | ||
return False | ||
elif self.rad == self.minrad: | ||
return hsl_color(0.0, 0.0, 1.0) | ||
else: | ||
(hue, sat) = self.huesat | ||
p = (self.rad - self.minrad) / (self.maxrad - self.minrad) | ||
rnd = random() | ||
if rnd < 0.1 * (1.2 - p): | ||
light = 1.0 | ||
elif rnd < 0.2 * (1.2 - p): | ||
light = 0.0 | ||
else: | ||
light = 2.0 * (1.0 - p) ** 2 - 1.0 | ||
return hsl_color(hue, sat, light) | ||
|
||
def update(self, step): | ||
self.rad += self.speed * step | ||
|
||
|
||
class FireworksScene(MovingShapesScene): | ||
def __init__(self, ctr): | ||
super(FireworksScene, self).__init__(ctr) | ||
self.freq = 0.0 | ||
self.horizon = 100 | ||
self.preferred_frames = 700 | ||
self.preferred_fps = 20 | ||
self.proj2D3D = "halfsphere" | ||
|
||
def create(self): | ||
cent = (0.0, 0.0) | ||
shape = Fireball(cent, 0.10, 1.0, 0.01, (random(), 1.0 - random()**2)) | ||
shape.duetime = self.time + 0.9/0.01 | ||
return shape | ||
|
||
def update(self, step): | ||
for sh in reversed(self.shapes): | ||
if sh.duetime < self.time: | ||
self.shapes.remove(sh) | ||
if self.time >= self.crtime: | ||
if self.record: | ||
sh = self.create() | ||
self.add_shape(copy(sh)) | ||
sh.duetime += self.preferred_frames | ||
self.crtime = self.time + 100 | ||
self.pre_shapes.append((self.crtime + self.preferred_frames, sh)) | ||
elif self.replay: | ||
if self.pre_shapes: | ||
self.add_shape(self.pre_shapes[0][1]) | ||
self.crtime = self.pre_shapes[0][0] | ||
self.pre_shapes = self.pre_shapes[1:] | ||
else: | ||
self.add_shape(self.create()) | ||
self.crtime = self.time + 100 | ||
if self.pre_shapes and self.crtime >= self.pre_shapes[0][0]: | ||
self.replay = True | ||
for sh in self.shapes: | ||
sh.update(step) | ||
self.time += step | ||
|
||
if __name__ == '__main__': | ||
ctr = setup_control() | ||
ctr.adjust_layout_aspect(1.0) # How many times wider than high is the led installation? | ||
eff = FireworksScene(ctr) | ||
oldmode = ctr.get_mode()["mode"] | ||
eff.launch_rt() | ||
print("Started continuous effect - press Return to stop it") | ||
input() | ||
eff.stop_rt() | ||
ctr.set_mode(oldmode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
""" | ||
Day 31 - Fireworks (version B) | ||
My take on the fireworks theme. Colored blobs growing and sparkling. | ||
This version gives explosions at random times and positions. | ||
Suits best for rather large and dense 2D installations. | ||
Also check the version in day31a. | ||
""" | ||
|
||
from xled_plus.samples.sample_setup import * | ||
|
||
|
||
class Fireball(Shape): | ||
def __init__(self, cent, minrad, maxrad, speed, huesat): | ||
super(Fireball, self).__init__(cent, 0.0) | ||
self.rad = minrad | ||
self.minrad = minrad | ||
self.maxrad = maxrad | ||
self.speed = speed | ||
self.huesat = huesat | ||
|
||
def is_inside(self, coord): | ||
return ( | ||
sum(map(lambda x1, x2: (x1 - x2) ** 2, self.cent, coord)) <= self.rad ** 2 | ||
) | ||
|
||
def get_color(self, coord, ind): | ||
dist2 = ( | ||
sum(map(lambda x1, x2: (x1 - x2) ** 2, self.cent, coord)) / self.rad ** 2 | ||
) | ||
if dist2 > 1.0: | ||
return False | ||
elif self.rad == self.minrad: | ||
return hsl_color(0.0, 0.0, 1.0) | ||
else: | ||
(hue, sat) = self.huesat | ||
p = (self.rad - self.minrad) / (self.maxrad - self.minrad) | ||
rnd = random() | ||
if rnd < 0.1 * (1.2 - p): | ||
light = 1.0 | ||
elif rnd < 0.2 * (1.2 - p): | ||
light = 0.0 | ||
else: | ||
light = 2.0 * (1.0 - p) ** 2 - 1.0 | ||
return hsl_color(hue, sat, light) | ||
|
||
def update(self, step): | ||
self.rad += self.speed * step | ||
|
||
|
||
class FireworksScene(MovingShapesScene): | ||
def __init__(self, ctr): | ||
super(FireworksScene, self).__init__(ctr) | ||
self.freq = 0.8 | ||
self.horizon = 60 | ||
self.preferred_frames = 720 | ||
self.preferred_fps = 20 | ||
self.proj2D3D = "cylshell" | ||
|
||
def create(self): | ||
cent = (random()*1.6 - 0.8, random()*1.6 - 0.8) | ||
shape = Fireball(cent, 0.15, 0.63, 0.008, (random(), 1.0)) | ||
shape.duetime = self.time + 0.48/0.008 | ||
return shape | ||
|
||
|
||
if __name__ == '__main__': | ||
ctr = setup_control() | ||
ctr.adjust_layout_aspect(1.0) # How many times wider than high is the led installation? | ||
eff = FireworksScene(ctr) | ||
oldmode = ctr.get_mode()["mode"] | ||
eff.launch_rt() | ||
print("Started continuous effect - press Return to stop it") | ||
input() | ||
eff.stop_rt() | ||
ctr.set_mode(oldmode) |