<commit_before>import argparse
import subprocess
import os
import os.path
import inspect
from GLSLJinja import GLSLJinjaLoader

parser = argparse.ArgumentParser(description="Generate multiple images using batchRIshader with particle_DF_with_motion.vert")
parser.add_argument("exe", help="path to the executable file 'batchRIshader'")
args = parser.parse_args()

outputDir   = os.path.abspath(os.getcwd());
outputName  = os.path.splitext(os.path.basename(__file__))[0]
srcDir      = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print("srcDir: " + srcDir, flush=True)
batchRIshader = os.path.abspath(args.exe)
shaderDir = os.path.join(srcDir, "shaders")
os.chdir(shaderDir)

loader = GLSLJinjaLoader(os.path.join(srcDir, "anim_script"))
particleTmpl = loader.get_template("particle_DF_with_motion.vert.tmpl")

def render_frame(source, i):
    p = subprocess.Popen(
        [
            batchRIshader,
            "--num_particles",          str(65536 << (13-5)),
            "--num_div_particles",      str(64),
            "--super_sampling_level",   str(0),
            "--num_tile_x",             str(1),
            "--num_tile_y",             str(1),
            "--output",                 os.path.join(outputDir, outputName + "_frm%05d.png" % i),
            "--output_w",               str(1920),
            "--output_h",               str(1080),
            "--hide_gl_info",
            "main_shader.frag",
            "-",
            "particle_DF.frag"
        ],
        universal_newlines = True,
        stdin = subprocess.PIPE
        )
    p.communicate(input = source)
    if p.returncode > 0:
    #    print(source[1000:])
        raise Exception()

def get_line_directive():
    return '#line %d "%s"\n' % (inspect.stack()[1][2], inspect.stack()[1][1].replace("\\", "\\\\"))

def render_template(include, timeinfo, cross_roundness = 16.0):
    tmpl = loader.get_includable_template_from_string(include)

    d = dict(
        t01                 = timeinfo.get_t01(),
        gbl_time            = timeinfo.get_global_time(),
        tmpl                = tmpl,
        cross_roundness     = cross_roundness,
        duration_scaling    = timeinfo.duration_scaling)
    return particleTmpl.render(d)

class TimeInfo:
    def __init__(self, FPS, local_frame, global_frame, duration, duration_scaling):
        self.FPS            = FPS
        self.local_frame    = local_frame
        self.global_frame   = global_frame
        self.duration       = duration
        self.duration_scaling   = duration_scaling

    def get_t01(self):
        return self.local_frame/(self.FPS*self.duration)

    def get_global_time(self):
        return self.global_frame/self.FPS

def get_scene_still(cross_roundness = None):
    def scene_still(timeinfo):
        code = (
            get_line_directive() +
            """\
            """
        )
        return render_template(code, timeinfo, cross_roundness) if cross_roundness != None else render_template(code, timeinfo)
    return scene_still

def scene_x_slide(timeinfo):
    code = (
        get_line_directive() +
        """\
        float nrmz = (star_pos.z - DFmin.z) / DFsize.z;
        float t = max(0.08 + nrmz*1.85 - `t01`*2.0, 0.0);
        float x0 = (star_pos.x+0.25);
        star_pos.x += pow(t*8., x0*8.0+0.25)*3.0 + t*x0*8.0;
        """
    )
    return render_template(code, timeinfo, 2.0)

def scene_suck(timeinfo):
    code = (
        get_line_directive() +
        """\
        vec3 center = vec3(0.0);
        float nrmdist = length(star_pos - center) / length(DFmin - center);
        float t = clamp(1.0 + nrmdist - `t01`*2.0, 0.0, 1.0);
        star_pos = (star_pos - center)*pow(t, 4.0) + center;
        color_scaling = max(pow((t - 0.2)/(1.0-0.2), 8.0), 0.0);
        """
    )
    return render_template(code, timeinfo, 2.0)

def scene_box_stack(timeinfo):
    code = (<commit_msg>Improved scene_x_slide in particle_DF_with_motion.py<commit_after>import argparse
import subprocess
import os
import os.path
import inspect
from GLSLJinja import GLSLJinjaLoader

parser = argparse.ArgumentParser(description="Generate multiple images using batchRIshader with particle_DF_with_motion.vert")
parser.add_argument("exe", help="path to the executable file 'batchRIshader'")
args = parser.parse_args()

outputDir   = os.path.abspath(os.getcwd());
outputName  = os.path.splitext(os.path.basename(__file__))[0]
srcDir      = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print("srcDir: " + srcDir, flush=True)
batchRIshader = os.path.abspath(args.exe)
shaderDir = os.path.join(srcDir, "shaders")
os.chdir(shaderDir)

loader = GLSLJinjaLoader(os.path.join(srcDir, "anim_script"))
particleTmpl = loader.get_template("particle_DF_with_motion.vert.tmpl")

def render_frame(source, i):
    p = subprocess.Popen(
        [
            batchRIshader,
            "--num_particles",          str(65536 << (13-5)),
            "--num_div_particles",      str(64),
            "--super_sampling_level",   str(0),
            "--num_tile_x",             str(1),
            "--num_tile_y",             str(1),
            "--output",                 os.path.join(outputDir, outputName + "_frm%05d.png" % i),
            "--output_w",               str(1920),
            "--output_h",               str(1080),
            "--hide_gl_info",
            "main_shader.frag",
            "-",
            "particle_DF.frag"
        ],
        universal_newlines = True,
        stdin = subprocess.PIPE
        )
    p.communicate(input = source)
    if p.returncode > 0:
    #    print(source[1000:])
        raise Exception()

def get_line_directive():
    return '#line %d "%s"\n' % (inspect.stack()[1][2], inspect.stack()[1][1].replace("\\", "\\\\"))

def render_template(include, timeinfo, cross_roundness = 16.0):
    tmpl = loader.get_includable_template_from_string(include)

    d = dict(
        t01                 = timeinfo.get_t01(),
        gbl_time            = timeinfo.get_global_time(),
        tmpl                = tmpl,
        cross_roundness     = cross_roundness,
        duration_scaling    = timeinfo.duration_scaling)
    return particleTmpl.render(d)

class TimeInfo:
    def __init__(self, FPS, local_frame, global_frame, duration, duration_scaling):
        self.FPS            = FPS
        self.local_frame    = local_frame
        self.global_frame   = global_frame
        self.duration       = duration
        self.duration_scaling   = duration_scaling

    def get_t01(self):
        return self.local_frame/(self.FPS*self.duration)

    def get_global_time(self):
        return self.global_frame/self.FPS

def get_scene_still(cross_roundness = None):
    def scene_still(timeinfo):
        code = (
            get_line_directive() +
            """\
            """
        )
        return render_template(code, timeinfo, cross_roundness) if cross_roundness != None else render_template(code, timeinfo)
    return scene_still

def scene_x_slide(timeinfo):
    code = (
        get_line_directive() +
        """\
        float nrmz = (star_pos.z - DFmin.z) / DFsize.z;
        float t = 0.08 + nrmz*1.85 - `t01`*2.0;
        color_scaling = t > 0.0 ? 1.0 : 1.0/max(-t*32.0, 0.01) + 1.0;
        t = max(t, 0.0);
        float x0 = (star_pos.x+0.25);
        star_pos.x += pow(t*8., x0*8.0+0.25)*3.0 + t*x0*8.0;
        """
    )
    return render_template(code, timeinfo, 2.0)

def scene_suck(timeinfo):
    code = (
        get_line_directive() +
        """\
        vec3 center = vec3(0.0);
        float nrmdist = length(star_pos - center) / length(DFmin - center);
        float t = clamp(1.0 + nrmdist - `t01`*2.0, 0.0, 1.0);
        star_pos = (star_pos - center)*pow(t, 4.0) + center;
        color_scaling = max(pow((t - 0.2)/(1.0-0.2), 8.0), 0.0);
        """
    )
    return render_template(code, timeinfo, 2.0)

def scene_box_stack(timeinfo):
    code = (
{'fraction_non_alphanumeric': 0.13543247344461304, 'fraction_numerical': 0.027061203844208397, 'mean_word_length': 2.284468438538206, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1351784', 'n_tokens_mistral': 2791, 'n_tokens_neox': 2656, 'n_words': 472}