Exemple #1
0
 def __init__(self):
     super().__init__(application_id="com.github.alexhuntley.Plots")
     self.scale = self._target_scale = self.INIT_SCALE
     self._translation = np.array([0, 0], 'f')
     self.vertex_template = jinja_env.get_template('vertex.glsl')
     self.fragment_template = jinja_env.get_template('fragment.glsl')
     self.rows = []
     self.slider_rows = []
     self.history = []
     self.history_position = 0  # index of the last undone command / next in line for redo
     self.overlay_source = None
Exemple #2
0
class Formula(RowData):
    priority = 20
    calculation_template = jinja_env.get_template("formula_calculation.glsl")

    def __init__(self, expr, body, rgba):
        m = re.match(r'^(?:y *=)?(.+)', expr)
        self.expr = m.group(1)
        self.body = body
        self.rgba = rgba

    def definition(self):
        return f"""float formula{self.id()}(float x) {{
    {self.body}
    return {self.expr};
}}"""

    def calculation(self):
        return self.calculation_template.render(formula=self)

    @staticmethod
    def accepts(expr):
        m = re.match(r'^(?:y *=)?(.+)', expr)
        return m and "=" not in m.group(1)