Skip to content

Commit

Permalink
Fix ColorEffect decorator for standalone use
Browse files Browse the repository at this point in the history
  • Loading branch information
a5kin committed Jan 5, 2018
1 parent 4a302af commit 0f3f034
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions xentica/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ def declare_coords(cls):
def define_constant(cls, constant):
cls._constants[constant.name] = deepcopy(constant)

def is_constant(cls, constant):
return constant in cls._constants

@property
def coords_declared(cls):
return cls._coords_declared
Expand Down
5 changes: 3 additions & 2 deletions xentica/core/color_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __call__(self, *args):
def __init__(self, func):
"""Initialize base attributes."""
self.func = func
self.effect = ""

def __call__(self, self_var):
"""
Expand All @@ -67,14 +68,14 @@ def __call__(self, self_var):
``super`` result, like shown in the example above.
"""
r, g, b = self.func(self_var)
red, green, blue = self.func(self_var)
code = """
int new_r = %s;
int new_g = %s;
int new_b = %s;
%s
col[i] = make_int3(new_r, new_g, new_b);
""" % (r, g, b, self.effect)
""" % (red, green, blue, self.effect)
self_var.append_code(code)


Expand Down
11 changes: 7 additions & 4 deletions xentica/core/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ def render_code(self):
)
code += "}" * (self._bsca.topology.dimensions - 2)
# calculate average
by_smooth_factor = ""
if self._bsca.is_constant("SMOOTH_FACTOR"):
by_smooth_factor = "/ SMOOTH_FACTOR"
code += """
img[i * 3] = r / num_cells_projected / SMOOTH_FACTOR;
img[i * 3 + 1] = g / num_cells_projected / SMOOTH_FACTOR;
img[i * 3 + 2] = b / num_cells_projected / SMOOTH_FACTOR;
"""
img[i * 3] = r / num_cells_projected {by_smooth_factor};
img[i * 3 + 1] = g / num_cells_projected {by_smooth_factor};
img[i * 3 + 2] = b / num_cells_projected {by_smooth_factor};
""".format(by_smooth_factor=by_smooth_factor)
return code

0 comments on commit 0f3f034

Please sign in to comment.