Skip to content

Instantly share code, notes, and snippets.

@dreness
Last active April 17, 2023 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreness/7df398708c0407ce8c98729d18f28a85 to your computer and use it in GitHub Desktop.
Save dreness/7df398708c0407ce8c98729d18f28a85 to your computer and use it in GitHub Desktop.
A bunch of Algodoo script snippets, extracted from public files

... is pretty great. If you somehow arrived here without knowing what Algodoo is, I implore you to go try it right now.

I had a hard time finding good examples of Thyme code on ye interwebs, and this document tries to remedy that. I downloaded a bunch of public compositions by the talented matto and then made a Jupyter notebook to extract interesting Thyme snippets from the project files (which are just zip archives after all). For this purpose, I define "interesting" as:

  • Not too long
  • Not too similar to a previously seen snippet

The notebook is attached at the end of this gist if you want to run the same process on your own bag of Algodoo compositions.

Also note that matto made videos about many of these compositions, so definitely check those out.

Other userful resources:

  • Thyme Language Guide
  • Thyme Property reference
  • desmos.com is a nice web-based graphing calculator. This is useful for tweaking parameteric equations, for example the linked graph was used to figure out an equation for adjusting an Algodoo object's attraction property over time, and is installed in the onUpdate callback as shown below. We substitute x for sim.time, and replace the divisor constant with a variable to more quickly visualize the equation using different values.

onUpdateParametric

image

thyme.cfg

First, here are the contents of thyme.cfg from inside the app bundle, which is probably the closest thing to official documentation for this scripting language.

Thyme is the homebrew scrpting language in Algodoo/Phun.
There are four atom types in thyme: Int, Float, Bool and String.
These types can then be used to construct aggregate types, such as Lists, and Functions.
Identifiers are declared using operator:= and changed using operator=. An identifier is typeless.

foo := 3; // Declares a new identifier "foo" with an initial integer vale
foo = [foo, "hello", true];  // Assigns a list to the previously declared variable 'foo'. The list is heterogenous.
print foo(1); // prints "hello"
print foo([0,2]); // prints [3, true]
isEven := (n)=>{ n%2==0 }; // Declares a function "isEven" that takes one argument and returns true if it's even
*/

/* for - A simple looping structure in Thyme.
Used like this: for(n, (i)=>{ ... });
... where n is the number of times to call the function.
    i will be given the values 0, 1, ..., n-2, n-1
Example:
	for(4, (n)=>{print ((n+1) + " bottles of beer on the wall.")})
Output:
	1 bottles of beer on the wall.
	2 bottles of beer on the wall.
	3 bottles of beer on the wall.
	4 bottles of beer on the wall.
*/

for = (n, what)=>{
    n <= 0 ? false : {
        for(n - 1, what);
        what(n-1)
    }
};

/* if - A simple if structure in Thyme.
Used like this: if(c, { ... }); where c is the condition that needs to be true for the function in {} to be executed
Example:
    if(true, {print "This will be written."});
    if(false, {print "This will be ignored."});
Output:
    This will be written.

if = (c, s)=>{
    c ? {s} : undefined
};

inclusive_range = (min, max)=>{min > max ? [] : {[min] ++ inclusive_range(min + 1, max)}};
infix 5 left: _ .. _ => inclusive_range; // Usage:  1..5 == [1,2,3,4,5]

math.max = (a,b)=>{ a > b ? a : b };
math.min = (a,b)=>{ a < b ? a : b };

// The sum of the components of a real vector
math.sum = (v)=>{
	ret = 0;
	for(string.length(v), (i)=>{
		ret = ret + v(i)
	});
	ret  // Return this
};

// Bench the time it takes to take a few simulation steps.
Bench_Steps = (n)=>{t := System.time; Sim.Step_N(n); Console.print(n + " steps took " + (System.time-t) + " seconds.") };

// Vector library (assumes 2-component vectors)
math.vec = alloc;
math.vec.lenSq  = (v)=>{ (v(0))^2 + (v(1))^2 };
math.vec.len    = (v)=>{ ( (v(0))^2 + (v(1))^2 )^.5 };
math.vec.distSq = (a,b)=>{ math.vec.lenSq(a-b) };
math.vec.dist   = (a,b)=>{ math.vec.len(a-b) };

// Example functionss
spawnBoxRow = (offset, n)=>{for(n, (x)=>{Scene.addBox({pos = offset + [x, 0]})})};
spawnRing = {Scene.addPolygon({surfaces = [makeRing(1, 48), makeRing(0.5, 48)]})};
makeRing = (r, n)=>{
    list = [];
    for(n, (i)=>{
        a = (2 * math.pi * i) / n;
        list = list ++ [r * [cos(a), sin(a)]]
    });
    list  // Return this
};

Poached from matto's compositions

The examples are grouped by the function they are defining: postStep, update, onCollide, onKey.

postStep

/Convective_motion_fluid_particle_simulator/scene.phn

postStep := (e)=>{
        _count = _count + 1.0000000e-07;
        density = density + _count;
        density > 0.010500000 ? {
            density = 0.010500000;
            _count = 0
        } : {};
        c = density * 100;
        f = (density * 100) * (-1) + 1;
        k = (vel(0) ^ 2 + vel(1) ^ 2) ^ 0.50000000;
        P = 1 / k;
        color = [0, f + k, 1, 1]
    };

/Compact_laser_with_automatic_aim/scene.phn

postStep := (e)=>{
        scene.my.ang1 = angle
    };

/Compact_laser_with_automatic_aim/scene.phn

postStep := (e)=>{
        my.scene.Xpallona = pos(0);
        my.scene.Ypallona = pos(1);
        my.scene.angPallona = angle
    };

/Compact_laser_with_automatic_aim/scene.phn

postStep := (e)=>{
        scene.my.a3 = angle
    };

/Compact_laser_with_automatic_aim/scene.phn

postStep := (e)=>{
        Xpallona = my.scene.Xpallona;
        Xpallina = my.scene.Xpallina;
        Xpallina = pos(0);
        Ypallina = pos(1);
        XX = Xpallina - Xpallona;
        YY = Ypallina - Ypallona;
        angolo = math.atan(YY / XX);
        my.scene.angolo = angolo;
        my.scene.Xpallina = pos(0);
        my.scene.Ypallina = pos(1)
    };

/Compact_laser_with_automatic_aim/scene.phn

postStep := (e)=>{
        a1 = scene.my.ang1;
        a2 = scene.my.ang2;
        aa = a1 - a2;
        aa > (-2) ? {
            fadeDist = 0
        } : {
            fadeDist = 300
        }
    };

/Radar_laser/scene.phn

postStep := (e)=>{
                scene.my.p = pos
            };
            opaqueBorders := true;
            geomID := 11223;
            body := 0;
            edgeBlur := 0.0099999998;
            angle := -0.85762119;
            zDepth := 7.0000000;
            layer := 0
        })
    };

/Mechanism_of_the_two_mouth_of_Alien/scene.phn

postStep := (e)=>{
        q = (math.sin(sim.time * 5)) * 16;
        colorHSVA = [230.00000 + q, 1.0000000, 1.0000000, 1.0000000]
    };

/Realistic_insect_laser_sensor_automatically_avoid_obstacle/scene.phn

postStep := (e)=>{
        scene.my.k = 2;
        scene.my.min = 1.4000000
    };

/Realistic_insect_laser_sensor_automatically_avoid_obstacle/scene.phn

postStep := (e)=>{
        q = math.sin(sim.Time * 2);
        motorSpeed = q
    };

/Realistic_insect_laser_sensor_automatically_avoid_obstacle/scene.phn

postStep := (e)=>{
        q = scene.my.S3;
        k = scene.my.k;
        m = scene.my.min;
        q < m ? {
            force = (m - q) * k
        } : {
            force = 0
        }
    };

/Robot_with_radar_avoids_moving_obstacles/scene.phn

postStep := (e)=>{
        q = scene.my.S3;
        k = scene.my.k;
        m = scene.my.min;
        q < m ? {
            force = (m - q) * k
        } : {
            force = 0
        }
    };

/Self_pilot_two_engine_stabilized_drone/scene.phn

postStep := (e)=>{
        my.scene.AngLed < 0 ? {
            color = [1.0000000, 1.0000000, 0.0000000, 1.0000000]
        } : {
            color = [0, 0, 0, 0]
        }
    };

/Self_pilot_two_engine_stabilized_drone/scene.phn

postStep := (e)=>{
        my.scene.UpDown = ((pos(1) - 70.699997) * (-1)) * 10;
        my.scene.DxSx = ((pos(0) - 64.300003) * (-1)) * 10
    };

/Self_pilot_two_engine_stabilized_drone/scene.phn

postStep := (e)=>{
        my.scene.magnet < 0 ? {
            attraction = 200;
            color = [1.0000000, 0.0000000, 0.0000000, 1.0000000]
        } : {
            attraction = 0;
            color = [0.0000000, 0.0000000, 1.0000000, 1.0000000]
        };
        my.scene.attract = attraction
    };

/Self_pilot_two_engine_stabilized_drone/scene.phn

postStep := (e)=>{
        my.scene.magnet = angle
    };

/Self_pilot_two_engine_stabilized_drone/scene.phn

postStep := (e)=>{
        fadeDist = 2 + my.scene.DX + (my.scene.p1 * (-1));
        fadeDist < 0 ? {
            fadeDist = (fadeDist * (-1) / 6)
        } : {}
    };

/Stabilized_remote_controller_four_engine_drone_sript/scene.phn

postStep := (e)=>{
        fadeDist = 2 + my.scene.DX + (my.scene.p1 * (-1));
        fadeDist < 0 ? {
            fadeDist = (fadeDist * (-1) / 6)
        } : {}
    };

/Self_pilot_two_engine_stabilized_drone/scene.phn

postStep := (e)=>{
        force = 20 + my.scene.SX + (my.scene.p1 * (-1)) + (((my.scene.p0 * (-1)) * 0.10000000));
        my.scene.forceSx = force
    };

/self_equilibrium/scene.phn

postStep := (e)=>{
        scene.my.tpNo0 = pos + [0, 0]
    };

/Catching_puppets_crane/scene.phn

postStep := (e)=>{
        _time > 1818 && _time < 3400 ? {
            _closed = 2.9600000
        } : {
            _closed = 0
        };
        _time = scene.my.time;
        angvel = (_closed - angle) * 40
    };

/Catching_puppets_crane/scene.phn

postStep := (e)=>{
        scene.my.p = pos
    };

/Catching_puppets_crane/scene.phn

postStep := (e)=>{
        vel = ((scene.my.p + _p) - (pos)) * 10;
        _X = pos(0) - scene.my.p(0);
        _x > (-0.050000001) && _x < 0.050000001 ? {_x = 0} : {};
        scene.my.x = _X
    };

/Catching_puppets_crane/scene.phn

postStep := (e)=>{
        scene.my.x < _x ? {
            color = [0.0000000, 1.0000000, 0.50000000, 1.0000000]
        } : {
            color = [1.0000000, 0.0000000, 0.0000000, 0.0000000]
        }
    };

/Catching_puppets_crane/scene.phn

postStep := (e)=>{
        _time = scene.my.time;
        _time > 0 ? {
            textColor = [0.0000000, 1.0000000, 0.0000000, 1.0000000]
        } : {
            textColor = [1.0000000, 1.0000000, 1.0000000, 0.0000000]
        };
        _tim = (math.sin(_time * 0.050000001)) * 0.20000000;
        textScale = 1.2000000 + _tim
    };

/Catching_puppets_crane/scene.phn

postStep := (e)=>{
        _time = scene.my.time;
        _time > 0 ? {
            color = [1.0000000, 1.0000000, 1.0000000, 0.0000000]
        } : {
            color = [1.0000000, 1.0000000, 1.0000000, 1.0000000]
        }
    };

/Catching_puppets_crane/scene.phn

postStep := (e)=>{
        _time = scene.my.time;
        _time > 0 ? {
            color = [1.0000000, 1.0000000, 1.0000000, 1]
        } : {
            color = [1.0000000, 1.0000000, 1.0000000, 0.0000000]
        }
    };

/Plasma_cannon/scene.phn

postStep := (e)=>{
        scene.my.pp1 = pos
    };

/Plasma_cannon/scene.phn

postStep := (e)=>{
        q = scene.my.rad1;
        radius = 0.020000000 + (q * 0.020000000);
        radius > 0.80000001 ? {
            _c = _c + 0.10000000
        } : {_c = 0};
        colorHSVA = [180.00000 + (_c * 1000), 1.0000000, 1.0000000, 0.69999999 - _c]
    };

/Plasma_cannon/scene.phn

postStep := (e)=>{
        _qq = _qq + 1;
        q = ((math.sin(_qq * radius * 3)) * 0.30000001);
        scene.my.fire == 1 ? {
            color = [1.0000000, 0.0000000 + q, 0.0000000, 1.0000000]
        } : {
            color = [0.0000000, 1.0000000, 1.0000000, 0]
        };
        edgeBlur = 0.60000002 + q
    };

/Plasma_cannon/scene.phn

postStep := (e)=>{
        scene.my.fire = _qq
    };

/Plasma_cannon/scene.phn

postStep := (e)=>{
        scene.camera.zoom = _k + (angle * _k1)
    };

/Plasma_cannon/scene.phn

postStep := (e)=>{
        scene.my.qq = _q
    };

/Plasma_cannon/scene.phn

postStep := (e)=>{
        vel = [6, 3];
        scene.my.qq == 1 ? {
            timeToLive = 0
        } : {}
    };

/Magic_shield/scene.phn

postStep := (e)=>{
        vel = (_p - pos) * 5;
        angvel = (0 - angle) * 5;
        cc = _v * 155;
        cc > 100 ? {cc = 100} : {};
        colorHSVA = [120 + cc, 1, 1, (_v * 4) - 0.40000001]
    };

/Magic_shield/scene.phn

postStep := (e)=>{
        _tt = _tt + 0.69999999 + rand.normal;
        _tt > 50 ? {
            _ball2;
            _tt = 0
        } : {}
    };

/Magic_shield/scene.phn

postStep := (e)=>{
        angle < 0.14000000 ? {_N = 1} : {};
        angle > 3 ? {_N = 0} : {};
        scene.my.n = _N
    };

/Magic_shield/scene.phn

postStep := (e)=>{
        scene.my.pm = pos
    };

/Magic_shield/scene.phn

postStep := (e)=>{
        q = scene.my.n;
        q == 0 ? {
            ccw = false
        } : {
            ccw = true
        }
    };

/Magic_shield/scene.phn

postStep := (e)=>{
        _v == 1 ? {_v1} : {};
        _v == 2 ? {_v2} : {};
        _v == 3 ? {_v3} : {};
        _v == 4 ? {_v4} : {};
        angvel = 19 + ((math.sin(sim.time)) * 10)
    };

/Magic_shield/scene.phn

postStep := (e)=>{
        _qq = _qq + 0.0099999998;
        ta = math.sin(_qq + pos(0) + pos(1));
        ta > 0.99299997 ? {
            color = [1.0000000, 1.0000000, 1.0000000, 1.0000000]
        } : {
            color = [1.0000000, 1.0000000, 1.0000000, 0]
        }
    };

/BAINO_series_presentation/scene.phn

postStep := (e)=>{
        q = (math.sin(sim.time * 4)) * 100;
        colorHSVA = [q, 0.50000000, 0.50000000, 1]
    };

/Pong_playtig_alone_NO_human_control/scene.phn

postStep := (e)=>{
        my.scene.p = pos(1);
        my.scene.po = pos(0);
        vel(0) < (-20) ? {
            vel = [-20, vel(1)]
        } : {};
        vel(0) > 20 ? {
            vel = [20, vel(1)]
        } : {}
    };

/Pong_playtig_alone_NO_human_control/scene.phn

postStep := (e)=>{
        c = my.scene.motorSx;
        color = [c, 0.50000000, 1, 1]
    };

/Pong_playtig_alone_NO_human_control/scene.phn

postStep := (e)=>{
        q = rand.normal;
        color = [0.55306399, 0.35445884 + q, 0.93430424, 1.0000000]
    };

/Pong_playtig_alone_NO_human_control/scene.phn

postStep := (e)=>{
        my.scenepSx = pos(1)
    };

/Pong_playtig_alone_NO_human_control/scene.phn

postStep := (e)=>{
        q = sin(sim.time);
        color = [0.0000000 + q, 1.0000000, 0.0000000, 1.0000000]
    };

/Pong_playtig_alone_NO_human_control/scene.phn

postStep := (e)=>{
        q = rand.normal;
        color = [0.0000000 + q, 0.83333331, 0.83333331, 1.0000000]
    };

/Pong_playtig_alone_NO_human_control/scene.phn

postStep := (e)=>{
        c = 1 / ((my.scene.po - pos(0)) ^ 2 + (my.scene.p - pos(1)) ^ 2) ^ 0.50000000;
        color = [0, c, c, 0.10000000]
    };

/Brachistochrone_curve_with_timer/scene.phn

postStep := (e)=>{
        my.scene.red = sim.time
    };

/Brachistochrone_curve_with_timer/scene.phn

postStep := (e)=>{
        my.scene.yel = sim.time
    };

/Brachistochrone_curve_with_timer/scene.phn

postStep := (e)=>{
        my.scene.cyan = sim.time
    };

/Circular_fractal_vise_automatic_succession_of_objects/scene.phn

postStep := (e)=>{
        scene.my.a = angle
    };

/Circular_fractal_vise_automatic_succession_of_objects/scene.phn

postStep := (e)=>{
        timetolive < 1 ? {
            _kk = timetolive
        } : {_kk = 1};
        colorhsva = [colorhsva(0), colorhsva(1), colorhsva(2), _kk]
    };

/Circular_fractal_vise_automatic_succession_of_objects/scene.phn

postStep := (e)=>{
        _k = scene.my.k;
        _k == 0 ? {_k = 16} : {}
    };

/Realistic_fireworks_script/scene.phn

postStep := (e)=>{
        _tt = _tt + 0.50000000 + rand.normal;
        _tt > 200 ? {
            _fire;
            _tt = 0
        } : {}
    };

/Realistic_fireworks_script/scene.phn

postStep := (e)=>{
        _t = _t + 1;
        colorHSVA = [_t, colorHSVA(1), colorHSVA(2), colorHSVA(3)]
    };

/Ferrocell_simulation_magnetic_visualizer/scene.phn

postStep := (e)=>{
        my.scene.a0 = pos(0);
        my.scene.a1 = pos(1)
    };

/Ritual_animation_script/scene.phn

postStep := (e)=>{
        x = scene.my.x;
        y = scene.my.y;
        y0 = 1 - y;
        pos1 = [5.4431381, 4.0353260] * [y, y];
        pos2 = [4.9819031, 15.721291] * [y0, y0];
        pos = pos1 + pos2
    };

/Ritual_animation_script/scene.phn

postStep := (e)=>{
        x = scene.my.x;
        color = [0.0000000, 1.0000000, 1.0000000, x];
        q = rand.normal;
        w = rand.normal;
        w1 = w * (x / 35);
        q1 = q * (x / 35);
        pos = [5.4460044 + w1, 3.1181543 + q1]
    };

/Ritual_animation_script/scene.phn

postStep := (e)=>{
        x = scene.my.x;
        refractiveIndex = 1 - x
    };

/Ritual_animation_script/scene.phn

postStep := (e)=>{
        x = scene.my.x;
        color = [0.0000000, 1.0000000, 0.083333254, x];
        q = rand.normal;
        w = rand.normal;
        w1 = w * (x / 15);
        q1 = q * (x / 15);
        pos = [5.4460044 + w1, 3.1181543 + q1]
    };

/Ritual_animation_script/scene.phn

postStep := (e)=>{
        x = pos(0);
        y = pos(1) / 2;
        x < 0 ? {x = 0} : {};
        y < 0 ? {y = 0} : {};
        scene.my.x = x;
        scene.my.y = y
    };

/ECO_localization/scene.phn

postStep := (e)=>{
        scene.my.angle = angle;
        scene.my.pos = pos
    };

/ECO_localization/scene.phn

postStep := (e)=>{
        q = scene.my.r;
        color = [1.0000000, 1.0000000, 0.0000000, q]
    };

/ECO_localization/scene.phn

postStep := (e)=>{
        angle = scene.my.angle;
        pos = scene.my.pos
    };

/ECO_localization/scene.phn

postStep := (e)=>{
        q = scene.my.r;
        fadeDist = 2.5000000 - q;
        fadeDist < 0 ? {
            fadeDist = 0
        } : {}
    };

/ECO_localization/scene.phn

postStep := (e)=>{
        q = scene.my.laserSX;
        fadeDist = q / 3
    };

/Crowler_with_engine_accelerator_gearbox_and_clutch/scene.phn

postStep := (e)=>{
        scene.my.pos1 = pos;
        scene.my.angle1 = angle
    };

/Crowler_with_engine_accelerator_gearbox_and_clutch/scene.phn

postStep := (e)=>{
        _k == 1 ? {
            _rad = _rad + 0.0049999999;
            radius = 0.69999999 + _rad;
            color = [1, 1, 1, 0.50000000 - (_rad / 2.2000000)];
            density = 0.10000000 - (_rad / 5);
            density < 0.0010000000 ? {
                density = 0.0010000000
            } : {}
        } : {}
    };

/Crowler_with_engine_accelerator_gearbox_and_clutch/scene.phn

postStep := (e)=>{
        scene.my.acc = angle
    };

/Crowler_with_engine_accelerator_gearbox_and_clutch/scene.phn

postStep := (e)=>{
        scene.my.onoff = _onoff
    };

/Crowler_with_engine_accelerator_gearbox_and_clutch/scene.phn

postStep := (e)=>{
        fri = scene.my.fri;
        collideSet = fri;
        fri == 1 ? {
            color = [0.0000000, 1.0000000, 0.0000000, 0.75000000]
        } : {};
        fri == 0 ? {
            color = [1.0000000, 0.0000000, 0.0000000, 0.75000000]
        } : {}
    };

/Crowler_with_engine_accelerator_gearbox_and_clutch/scene.phn

postStep := (e)=>{
        scene.my.fri = _fri
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        scene.my.fri = _fri
    };

/Crowler_with_engine_accelerator_gearbox_and_clutch/scene.phn

postStep := (e)=>{
        q = scene.my.poss + [8, 78];
        w = q - pos;
        vel = w
    };

/Crowler_with_engine_accelerator_gearbox_and_clutch/scene.phn

postStep := (e)=>{
        scene.my.smoke = _smoke
    };

/Stabilized_remote_controller_four_engine_drone_sript/scene.phn

postStep := (e)=>{
        my.scene.UpDown = ((pos(1) - 10.197667) * (-1)) * 40;
        my.scene.DxSx = ((pos(0) - 12.198166) * (-1)) * 40
    };

/Stabilized_remote_controller_four_engine_drone_sript/scene.phn

postStep := (e)=>{
        my.scene.SX = angvel + angle;
        my.scene.DX = (angvel + angle) * (-1);
        my.scene.p0 = my.scene.DxSx + pos(0) + vel(0);
        my.scene.p1 = my.scene.UpDown + pos(1) + vel(1);
        my.scene.AngLed = angle
    };

/Stabilized_remote_controller_four_engine_drone_sript/scene.phn

postStep := (e)=>{
        my.scene.AngLed < 0 ? {
            color = [1.0000000, 0.0000000, 0.0000000, 1.0000000]
        } : {
            color = [0, 0, 0, 0]
        }
    };

/Stabilized_remote_controller_four_engine_drone_sript/scene.phn

postStep := (e)=>{
        force = 15 + my.scene.SX + (my.scene.p1 * (-1))
    };

/Arduino_line_follower_laser_script/scene.phn

postStep := (e)=>{
        p = scene.my.SX;
        p > 0 ? {
            color = [0, 1, 0, 1]
        } : {
            color = [1, 0, 0, 1]
        }
    };

/Arduino_line_follower_laser_script/scene.phn

postStep := (e)=>{
        force = scene.my.DX
    };

/Air_conditioner_simulator_script/scene.phn

postStep := (e)=>{
        _count = _count - 9.9999999e-09;
        density = density + _count;
        density < 0.0010000000 ? {
            density = 0.0010000000;
            _count = 0
        } : {};
        c = density * 30;
        f = (density * 100) * (-1) + 1;
        color = [0, 0, 1, c]
    };

/Self_sync/scene.phn

postStep := (e)=>{
        scene.my.p = pos(0)
    };

/Snake_Nokya_working_script/scene.phn

postStep := (e)=>{
        scene.my.end == 1 ? {
            timetolive = 0
        } : {}
    };

/Snake_Nokya_working_script/scene.phn

postStep := (e)=>{
        _t = _t + 0.20000000;
        _sin = math.sin(_t);
        _sin > (-0.60000002) ? {
            textcolor = [0, 0, 0, 1.0000000]
        } : {
            textcolor = [1.0000000, 1.0000000, 1.0000000, 0]
        };
        scene.my.start == 1 ? {
            timetolive = 0
        } : {}
    };

/Snake_Nokya_working_script/scene.phn

postStep := (e)=>{
        App.GUI.playMode = true
    };

/Self_solve_the_maze/scene.phn

postStep := (e)=>{
        pos = scene.my.Centro;
        angle = 0
    };

/Self_solve_the_maze/scene.phn

postStep := (e)=>{
        _anv;
        _dira;
        pos = scene.my.Centro;
        _move = scene.my.direzione;
        angvel = (_aa - angle) * 6;
        colorHSVA = [15.000000, 0.0000000 + _ve, 1.0000000, 1.0000000]
    };

/Self_solve_the_maze/scene.phn

postStep := (e)=>{
        pos = scene.my.Centro;
        color = [0, 1, 0, scene.my.veloc]
    };

/Self_solve_the_maze/scene.phn

postStep := (e)=>{
        _move = scene.my.direzione;
        _move == _direzione ? {
            color = [1.0000000, 0.0000000, 0.0000000, 1.0000000]
        } : {
            color = [1.0000000, 0.0000000, 0.0000000, 0]
        }
    };

/Self_solve_the_maze/scene.phn

postStep := (e)=>{
        _letture;
        _VEDI_PARETI;
        _11sendMove1;
        _11sendMoveCurve;
        _11sendMoveT;
        _11sendMove_corridoio1;
        _11sendMove_corridoio2;
        _11sendMoveNul1;
        _11sendMoveNul2;
        _11sendMoveNul3;
        _11sendMoveNul4;
        scene.my.pass = _perGiaPassato
    };

/Robot_with_radar_avoids_moving_obstacles/scene.phn

postStep := (e)=>{
        pos = [scene.my.pos0, scene.my.pos1];
        q = sim.time;
        angle = q * 4
    };

/Robot_with_radar_avoids_moving_obstacles/scene.phn

postStep := (e)=>{
        q = scene.my.r * 4;
        w = math.sin(sim.time);
        colorHSVA = [36.923851 + w * q, 1.0000000, 0.44999999, 1.0000000]
    };

/Robot_with_radar_avoids_moving_obstacles/scene.phn

postStep := (e)=>{
        q = scene.my.r;
        w = math.sin(sim.time);
        a = scene.my.ang;
        s = scene.my.av;
        k = q * a * s * 200;
        colorHSVA = [268.13959 + k, 1.0000000, 1.0000000, 1.0000000]
    };

/Robot_with_radar_avoids_moving_obstacles/scene.phn

postStep := (e)=>{
        q = scene.my.r;
        color = [0.0000000, 0.0000000, 0.25999999 + (q / 5), 1.0000000]
    };

/Robot_with_radar_avoids_moving_obstacles/scene.phn

postStep := (e)=>{
        pos = [scene.my.pos0, scene.my.pos1];
        angle = scene.my.ang;
        a = scene.my.av;
        color = [1.0000000, 1.0000000, 1.0000000, 0 - a * 10]
    };

/Robot_with_radar_avoids_moving_obstacles/scene.phn

postStep := (e)=>{
        x = scene.my.pos0;
        y = scene.my.pos1;
        a = scene.my.ang;
        pos = [(x / 8) + 56, y / 8];
        angle = a
    };

/Robot_with_radar_avoids_moving_obstacles/scene.phn

postStep := (e)=>{
        pos = scene.my.q2;
        angle = scene.my.a2
    };

/Robot_with_radar_avoids_moving_obstacles/scene.phn

postStep := (e)=>{
        q = sim.time * 100;
        colorHSVA = [q, 1.0000000, 1.0000000, 0.69999999]
    };

/Robot_with_radar_avoids_moving_obstacles/scene.phn

postStep := (e)=>{
        q = sim.time;
        rotation = q * 4
    };

/Robot_with_radar_avoids_moving_obstacles/scene.phn

postStep := (e)=>{
                scene.my.p = pos
            };
            opaqueBorders := true;
            geomID := 11223;
            body := 0;
            edgeBlur := 0.0099999998;
            angle := -0.85762119;
            timeToLive := 50;
            zDepth := 7.0000000;
            layer := 0
        })
    };

/Robot_with_radar_avoids_moving_obstacles/scene.phn

postStep := (e)=>{
        q = scene.my.r * 4;
        w = math.sin(sim.time / 2.2000000);
        colorHSVA = [145 + w * q, 1.0000000, 0.40000001, 1.0000000]
    };

/Robot_with_radar_avoids_moving_obstacles/scene.phn

postStep := (e)=>{
        scene.my.q2 = pos;
        scene.my.a2 = angle
    };

/LUMEN_working_videogame/scene.phn

postStep := (e)=>{
        vel = (scene.my.player - pos + [0, 0.69999999]) * 7;
        scene.my.luce < 0 || scene.my.win1 == 1 ? {
            timetolive = 0
        } : {};
        scene.my.punti = pos
    };

/LUMEN_working_videogame/scene.phn

postStep := (e)=>{
        pos = scene.my.punti + [-0.055000000, -0.059999999];
        scene.my.win1 == 1 || scene.my.luce < 0 ? {
            timetolive = 0
        } : {}
    };

/LUMEN_working_videogame/scene.phn

postStep := (e)=>{
        vel = (scene.my.player - pos) * 20;
        scene.my.end > 0 ? {
            timetolive = 0
        } : {}
    };

/LUMEN_working_videogame/scene.phn

postStep := (e)=>{
        scene.my.win1 == 1 ? {
            collideset = 0;
            vel = ([8, 2.5000000] - pos) * 6
        } : {}
    };

/LUMEN_working_videogame/scene.phn

postStep := (e)=>{
        colorhsva = [rand.normal * 300, 0.50000000, 1.0000000, 1.0000000];
        vel = (scene.my.pCr - pos) * 1
    };

/LUMEN_working_videogame/scene.phn

postStep := (e)=>{
        scene.my.luce < 0 || scene.my.expl == 1 ? {
            timetolive = 0
        } : {};
        scene.my.pmove = pos
    };

/LUMEN_working_videogame/scene.phn

postStep := (e)=>{
        scene.my.expl == 1 ? {
            _t = _t - 0.0099999998
        } : {};
        pos = scene.my.psche + [0, 0.25000000];
        colorhsva = [60.000000, 1.0000000, 1.0000000, _t + 0.38000000 + (rand.uniform01 * 0.33000001)]
    };

/LUMEN_working_videogame/scene.phn

postStep := (e)=>{
        scene.my.win1 == 1 ? {
            timetolive = 0
        } : {};
        _t = _t + 1 + (1 - rand.uniform01);
        _t > 153 ? {
            _cambio = 1;
            _t = 0
        } : {};
        _cambio == 1 ? {
            _r = rand.uniform01;
            _cambio = 0
        } : {};
        _dirRand;
        vel = _dir;
        scene.my.fantasma = pos
    };

/LUMEN_working_videogame/scene.phn

postStep := (e)=>{
        pos = scene.my.player;
        Xpallona = my.scene.Xpallona;
        Xpallina = my.scene.Xpallina;
        Xpallina = pos(0);
        Ypallina = pos(1);
        XX = Xpallina - Xpallona;
        YY = Ypallina - Ypallona;
        angolo = math.atan(YY / XX);
        my.scene.angolo = angolo;
        my.scene.Xpallina = pos(0);
        my.scene.Ypallina = pos(1)
    };

/LUMEN_working_videogame/scene.phn

postStep := (e)=>{
        colorhsva = [240.00000, 1.0000000, 0.33333334, 1.0000000 - scene.my.ef]
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        vel = (scene.my.pos - pos + [0, 8]) * 2;
        q = scene.my.mcolor;
        colorHSVA = [q, colorHSVA(1), colorHSVA(2), colorHSVA(3)]
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        vel = (scene.my.pos - pos) * 100
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        q = scene.my.mcolor;
        colorHSVA = [q, colorHSVA(1), colorHSVA(2), colorHSVA(3)]
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        q = scene.my.fri;
        q == 1 ? {
            collideSet = 2
        } : {
            collideSet = 0
        }
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        scene.my.anvel = angle * 7
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        scene.my.pos = pos;
        scene.my.ang = angle
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        angle > 1.3000000 ? {
            color = [1, 0, 1, 1]
        } : {};
        angle < (-0.89999998) ? {
            color = [0, 0, 1, 1]
        } : {};
        scene.my.c1 = color;
        scene.my.angle = angle
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        scene.my.mimetic1 = colorHSVA(0)
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        scene.my.mimetic6 = colorHSVA(0)
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        scene.my.mimetic5 = colorHSVA(0)
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        scene.my.mimetic4 = colorHSVA(0)
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        scene.my.mimetic3 = colorHSVA(0)
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        scene.my.mimetic2 = colorHSVA(0)
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        c1 = scene.my.mimetic1;
        c2 = scene.my.mimetic2;
        c3 = scene.my.mimetic3;
        c4 = scene.my.mimetic4;
        c5 = scene.my.mimetic5;
        c6 = scene.my.mimetic6;
        _colorTot = (c1 + c2 + c3 + c4 + c5 + c6) / 6;
        q = _colorTot - pos(1);
        vel = [0, q * 7];
        scene.my.mcolor = pos(1)
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        motorSpeed = scene.my.anvel
    };

/Octopus_mimetization/scene.phn

postStep := (e)=>{
        a = scene.my.ang2;
        k = (a - 1.3000000) * 10;
        k1 = (a + 1.3000000) * 4;
        c = scene.my.c1;
        c == [1, 0, 1, 1] ? {
            motorSpeed = k
        } : {
            motorSpeed = k1
        }
    };

/virus_scripted/scene.phn

postStep := (e)=>{
        pos = scene.my.pos + [(-0.039999999), 0.60000002]
    };

/Beyblade/scene.phn

postStep := (e)=>{
        r = sin(rand.uniform01);
        color = [0.50000000, 0.0000000, 0.0000000, r]
    };

/mechanism_various_script_interface/scene.phn

postStep := (e)=>{
        _pan = scene.camera.pan;
        pos = _pan
    };

/mechanism_various_script_interface/scene.phn

postStep := (e)=>{
        _kk = _kk - 0.0099999998;
        _kk < 0 ? {_kk = 0} : {};
        colorHSVA = [0.0000000, _kk, 1.0000000, 1];
        _pan = scene.camera.pan;
        pos = _pan
    };

/mechanism_various_script_interface/scene.phn

postStep := (e)=>{
        _pan = scene.camera.pan;
        pos = _pan + _pp
    };

/mechanism_various_script_interface/scene.phn

postStep := (e)=>{
        _pan = scene.camera.pan;
        pos = _pan + _pp;
        color = [1.0000000, 0.64499998, 0.29000002, _k]
    };

/mechanism_various_script_interface/scene.phn

postStep := (e)=>{
        _pan = scene.camera.pan;
        pos = _pan + _pp;
        color = [0.73534560, 1.0000000, 0.13999999, _k]
    };

/mechanism_various_script_interface/scene.phn

postStep := (e)=>{
        scene.camera.pan = [_scroll, 0];
        scene.camera.zoom = 150;
        _scroll < (-5) ? {
            _scroll = (-5)
        } : {};
        _scroll > 195 ? {
            _scroll = 195
        } : {}
    };

/mechanism_various_script_interface/scene.phn

postStep := (e)=>{
        _t = _t - 0.0070000002;
        color = [0, 0, 0, _t];
        color(3) < 0 ? {
            timeToLive = 0
        } : {}
    };

/mechanism_various_script_interface/scene.phn

postStep := (e)=>{
        _kk = _kk - 0.020000000;
        _kk < 0 ? {_kk = 0} : {};
        colorHSVA = [0.0000000, 0, 0.0000000, _kk];
        _pan = scene.camera.pan;
        pos = _pan
    };

/SCRIPT_COLLECTION_2/scene.phn

postStep := (e)=>{
        Refractiveindex = 39.000000 - 44.000000 * math.sin(sim.time)
    };

/SCRIPT_COLLECTION_2/scene.phn

postStep := (e)=>{
        radius = 0.20000000 + 0.029999999 * math.sin(sim.time * 10)
    };

/SCRIPT_COLLECTION_2/scene.phn

postStep := (e)=>{
                rotation = 0.0000000 - 0.69999999 * math.sin(sim.time)
            };
            onLaserHit := (e)=>{};
            collideSet := 1023;
            onKey := (e)=>{};
            colorHSVA := [60.000000, 1.0000000, 1.0000000, 0.0000000];
            layer := 0
        })
    };

/SCRIPT_COLLECTION_2/scene.phn

postStep := (e)=>{
        rotation = 10.000000 - 0.69999999 * math.sin(sim.time * 3)
    };

/SCRIPT_COLLECTION_2/scene.phn

postStep := (e)=>{
        length = 1.6000000 + 1.0000000 * math.sin(sim.time * 6);
        size = 0.60000002 + 2.0000000 * math.sin(sim.time * 6)
    };

/SCRIPT_COLLECTION_2/scene.phn

postStep := (e)=>{
        length = 3.0000000 + 1.7000000 * math.sin(sim.time)
    };

/STOPlight/scene.phn

postStep := (e)=>{
        scene.my.red = _timeRED;
        scene.my.yellow = _timeYELLOW;
        scene.my.green = _timeGREEN
    };

/Kaleidoscopic_screensaver/scene.phn

postStep := (e)=>{
        color = my.scene.c107
    };

/Smart_bacterium_avoids_obstacles/scene.phn

postStep := (e)=>{
        scene.my.ang = angle;
        scene.my.pos = pos
    };

/Smart_bacterium_avoids_obstacles/scene.phn

postStep := (e)=>{
        q = scene.my.S1;
        w = scene.my.S2;
        t = math.sin(sim.time);
        q = (q * (-1)) + 1.5000000;
        q < 0 ? {q = 0} : {};
        w = (w * (-1)) + 1.5000000;
        w < 0 ? {w = 0} : {};
        a = (w - q) * 3;
        angle = a + scene.my.ang + t / 3;
        scene.my.q = angle
    };

/Smart_bacterium_avoids_obstacles/scene.phn

postStep := (e)=>{
        pos = scene.my.pos
    };

/Smart_bacterium_avoids_obstacles/scene.phn

postStep := (e)=>{
        q = math.sin(sim.time * 5) * 0.10000000;
        angle =  - q + scene.my.ang
    };

/Smart_bacterium_avoids_obstacles/scene.phn

postStep := (e)=>{
        q = scene.my.S1;
        q = (q * (-1)) + 1.5000000;
        q < 0 ? {q = 0} : {};
        force = q * 60
    };

/Scaner_anatomy/scene.phn

postStep := (e)=>{
        scene.my.base = pos
    };

/Scaner_anatomy/scene.phn

postStep := (e)=>{
        vel = (((scene.my.braccio + scene.my.base + scene.my.palla) / 2) - pos) * 6
    };

/Scaner_anatomy/scene.phn

postStep := (e)=>{
        scene.my.palla = pos;
        vel = (Scene.my.pinza - pos) * 10;
        pos(0) < scene.my.girati ? {
            _angscanner = 1.5707964
        } : {
            _angscanner = (-1.5707964)
        };
        angvel = (_angscanner - angle) * 9
    };

/Scaner_anatomy/scene.phn

postStep := (e)=>{
        _apri0Chiudi1 == 0 ? {
            collideset = 0;
            colorhsva = [120.00000, 1.0000000, 1.0000000, 1.0000000]
        } : {
            collideset = 1;
            colorhsva = [0, 1.0000000, 1.0000000, 1.0000000]
        }
    };

/Scaner_anatomy/scene.phn

postStep := (e)=>{
        _pX = (pos(0) - _p(0));
        _pY = (pos(1) - _p(1));
        texturematrix = [1.2305282, 0.0000000, 0.49999976 + (_pX * 1.2300000), 0.0000000, 0.49996936, 0.93750346 + (_pY * 0.50000000), 0.0000000, 0.0000000, 0.99999958]
    };

/Scaner_anatomy/scene.phn

postStep := (e)=>{
        _mov > 0.10000000 ? {_t = 2} : {};
        _t = _t - 0.0099999998;
        color = [1.0000000, 1.0000000, 1.0000000, _t]
    };

/Scaner_anatomy/scene.phn

postStep := (e)=>{
        _t = _t + 1 + (1 + rand.uniform01);
        _t > 300 ? {
            pos = scene.my.Pscanner;
            _t = 0
        } : {};
        scene.my.p3 = pos
    };

/Scaner_anatomy/scene.phn

postStep := (e)=>{
        scene.my.Pscanner = pos
    };

/infinite_landscape_desert_auto_driving_jeep/scene.phn

postStep := (e)=>{
        my.scene.a = angVel
    };

/infinite_landscape_desert_auto_driving_jeep/scene.phn

postStep := (e)=>{
        a = my.scene.p;
        pos = [2.8000000, a * 2]
    };

/infinite_landscape_desert_auto_driving_jeep/scene.phn

postStep := (e)=>{
        my.scene.p1 = pos(1);
        my.scene.p2 = pos(0)
    };

/infinite_landscape_desert_auto_driving_jeep/scene.phn

postStep := (e)=>{
        pos = [pos(0), -0.36607003]
    };

/infinite_landscape_desert_auto_driving_jeep/scene.phn

postStep := (e)=>{
        a = a + 0.20000000;
        radius = 0.0099999998 + a
    };

/infinite_landscape_desert_auto_driving_jeep/scene.phn

postStep := (e)=>{
        q = math.sin(sim.time);
        a = q * 17;
        colorHSVA = [50.000000 - a, 1.0000000, 0.77999997, 1.0000000]
    };

/infinite_landscape_desert_auto_driving_jeep/scene.phn

postStep := (e)=>{
        q = math.sin(sim.time);
        a = q * 17;
        colorHSVA = [50.000000 - a, 0.20000000, 0.50000000, 1.0000000]
    };

/infinite_landscape_desert_auto_driving_jeep/scene.phn

postStep := (e)=>{
        scene.my.tpNo6 = pos
    };

/script_COLLECTION/scene.phn

postStep := (e)=>{
        scene.my.tpNo7 = pos + [0, 0]
    };

/Toys_for_kids/scene.phn

postStep := (e)=>{
        scene.my.tpNo7 = pos + [0, 0]
    };

/balance_ball_script/scene.phn

postStep := (e)=>{
        my.scene.angle = angle;
        my.scene.posRet = pos(0)
    };

/balance_ball_script/scene.phn

postStep := (e)=>{
        q = (my.scene.posb - pos(0)) * 1;
        w = my.scene.velb / 2;
        d = (w + q) * (1);
        angle = (d / 10)
    };

/balance_ball_script/scene.phn

postStep := (e)=>{
        my.scene.rad = {
            a = my.scene.angvelc * 20;
            s = my.scene.anglec * 10;
            q = (my.scene.posc - my.scene.posRetc) * 1;
            r = (q - s) * 2;
            w = my.scene.velc * 10;
            d = (w + r - a)
        };
        my.scene.radius = my.scene.rad / 20
    };

/balance_ball_script/scene.phn

postStep := (e)=>{
        my.scene.posb = pos(0);
        my.scene.velb = vel(0)
    };

/balance_ball_script/scene.phn

postStep := (e)=>{
        radius = 0.25000000 + my.scene.radius
    };

/balance_ball_script/scene.phn

postStep := (e)=>{
        my.scene.pos = pos(0);
        my.scene.vel = vel(0)
    };

/balance_ball_script/scene.phn

postStep := (e)=>{
        radius = 0.25000000 + my.scene.radius * (-1)
    };

/balance_ball_script/scene.phn

postStep := (e)=>{
        my.scene.posc = pos(0);
        my.scene.velc = vel(0)
    };

/balance_ball_script/scene.phn

postStep := (e)=>{
        my.scene.radd = {
            a = my.scene.angveld * 0;
            s = my.scene.angled * 2;
            q = (my.scene.posd - my.scene.posRetd) * 1;
            r = (q - s) * 2;
            w = my.scene.veld * 10;
            d = (w + r - a)
        };
        my.scene.length = (my.scene.radd / 10) * (-1)
    };

/balance_ball_script/scene.phn

postStep := (e)=>{
        s = my.scene.angle * 10;
        q = (my.scene.pos - my.scene.posRet) * 1;
        r = (q - s) * 10;
        w = my.scene.vel * 10;
        d = (w + r) * (-1);
        motorSpeed = (d)
    };

/balance_ball_script/scene.phn

postStep := (e)=>{
        length = 1.7677670 + my.scene.length
    };

/elettric_bell_mechanism/scene.phn

postStep := (e)=>{
        _q = _q - 0.0010000000;
        _q < 0 ? {_q = 0} : {};
        _q > 1 ? {_q = 1} : {};
        pos = [_r1, _r2] * [_q, _q]
    };

/elettric_bell_mechanism/scene.phn

postStep := (e)=>{
        scene.my.onoff = _on;
        _onoff == 1 ? {
            collideSet = 3
        } : {
            collideSet = 1
        }
    };

/Vault_76_Fallout_door_animation/scene.phn

postStep := (e)=>{
        color = [1, 1, 1, 1 - (scene.my.level * 5)]
    };

/Vault_76_Fallout_door_animation/scene.phn

postStep := (e)=>{
        _leva = scene.my.leva;
        _leva > 1.4000000 ? {
            _pX = 1.4177366
        } : {
            _pX = 2.4529757
        };
        vel = ([_pX, 1.4059985] - pos) * [1, 20];
        scene.my.Pdoor = pos
    };

/Vault_76_Fallout_door_animation/scene.phn

postStep := (e)=>{
        _pdoor = scene.my.Pdoor;
        vel = (_pdoor - pos - [0, 1.4059985]) * [10, 2];
        _level = pos(1) + 0.078226835;
        _level < 0 ? {
            _level = 0
        } : {};
        scene.my.level = _level
    };

update

Set object text with a variable

(e)=>{
    text = {
        "x: " + Scene.my.cpos(0) + "\n" + "y: " + Scene.my.cpos(1)
    }
}

/LUMEN_working_videogame/scene.phn

update := (e)=>{
        App.GUI.playMode = sim.running
    };

/Quadruplicate_image_pixel_trick/scene.phn

update := (e)=>{
        keys.isDown("2") ? {
            e.this.color = [1, 1, 1, 1]
        } : {
            e.this.color = [1, 1, 1, 0]
        }
    };

/SCRIPT_COLLECTION_2/scene.phn

update := (e)=>{
        attraction = 0.10000000 + 3.0999999 * math.sin(sim.time);
        color = 1.0000000 + 1.1000000 * math.sin(sim.time)
    };

/SCRIPT_COLLECTION_2/scene.phn

update := (e)=>{
        motorspeed = 3.0999999 + 11.100000 * math.sin(sim.time)
    };

onCollide

/Convective_motion_fluid_particle_simulator/scene.phn

onCollide := (e)=>{
        e.other.density = 0.00079999998
    };

/primitive_adder_of_numbers_up_to_5_digits/scene.phn

onCollide := (e)=>{
        e.other.pos = [-4.4058409, 9.0216341];
        my.scene.score2 = my.scene.score2 + 1;
        my.scene.hits = 0
    };

/self_equilibrium/scene.phn

onCollide := (e)=>{
        e.other.pos = scene.my.tpNo0;
        e.other.vel = [0, 0]
    };

/armed_robot_mission_3/scene.phn

onCollide := (e)=>{
        e.other.pos = scene.my.tpNo0;
        e.other.vel = [0, 0]
    };

/Plasma_cannon/scene.phn

onCollide := (e)=>{
        _q = 1;
        timeToLive = 0.10000000
    };

/Magic_shield/scene.phn

onCollide := (e)=>{
        e.other._v = 1
    };

/stable_and_jumping_vehicle_robot_crawler_armed_with_laser_AND_ACID/scene.phn

onCollide := (e)=>{
                e.other.color = e.this.color;
                e.other.density = 1
            };
            density := 26.000000;
            radius := 0.11000000;
            edgeBlur := 1.0000000
        })
    };

/Pong_playtig_alone_NO_human_control/scene.phn

onCollide := (e)=>{
        e.other.pos = [0.0000000, 4.0000000];
        e.other.vel = [0, 20]
    };

/Brachistochrone_curve_with_timer/scene.phn

onCollide := (e)=>{
        e.other.materialname == "stop" ? {
            postStep = 0
        } : {}
    };

/SAFE_MECHANICAL_DISC_COMBINATION/scene.phn

onCollide := (e)=>{
        scene.camera.zoom = 55.500000
    };

/Display_4_FRAMES_ANIMATIONS_DISC_LOADING_SYSTEM/scene.phn

onCollide := (e)=>{
        e.other.color = e.this.color;
        e.other.density = 0.0010000000
    };

/ECO_localization/scene.phn

onCollide := (e)=>{
        e.other.materialName == "eco" ? {
            _yes = _yes + 1
        } : {}
    };

/Crowler_with_engine_accelerator_gearbox_and_clutch/scene.phn

onCollide := (e)=>{
        e.other.materialname == "on" ? {
            _onoff = 1
        } : {};
        e.other.materialname == "off" ? {
            _onoff = 0
        } : {}
    };

/Crowler_with_engine_accelerator_gearbox_and_clutch/scene.phn

onCollide := (e)=>{
        e.other.materialname == "friOn" ? {_fri = 1} : {};
        e.other.materialname == "friOff" ? {_fri = 0} : {}
    };

/Octopus_mimetization/scene.phn

onCollide := (e)=>{
        e.other.materialname == "friOn" ? {_fri = 1} : {};
        e.other.materialname == "friOff" ? {_fri = 0} : {}
    };

/Crowler_with_engine_accelerator_gearbox_and_clutch/scene.phn

onCollide := (e)=>{
        e.other.materialname == "smokeOn" ? {
            _smoke = 1
        } : {};
        e.other.materialname == "smokeOff" ? {
            _smoke = 0
        } : {}
    };

/armed_robot_mission_1/scene.phn

onCollide := (e)=>{
        scene.camera.zoom = 11.000000
    };

/armed_robot_mission_1/scene.phn

onCollide := (e)=>{
        sim.running = false
    };

/script_COLLECTION/scene.phn

onCollide := (e)=>{
        sim.running = false
    };

/armed_robot_mission_2/scene.phn

onCollide := (e)=>{
        sim.running = false
    };

/Air_conditioner_simulator_script/scene.phn

onCollide := (e)=>{
        e.other.density = 0.0099999998
    };

/TESLA_VALVE_playing_an_idea_of_nikola_teslapluscounter/scene.phn

onCollide := (e)=>{
        e.other.pos = [-4.4058409, 9.0216341];
        my.scene.score = my.scene.score + 1;
        my.scene.hits = 0
    };

/Snake_Nokya_working_script/scene.phn

onCollide := (e)=>{
        e.other._segmentiN = e.other._segmentiN + 1;
        timetolive = 0
    };

/Snake_Nokya_working_script/scene.phn

onCollide := (e)=>{
        e.other.materialname == "end" ? {_end = 1} : {}
    };

/Self_solve_the_maze/scene.phn

onCollide := (e)=>{
        _barrier = 1
    };

/LUMEN_working_videogame/scene.phn

onCollide := (e)=>{
        e.other.materialname == "scheletro" ? {
            _morte0o1 = 1;
            scene.my.expl = 1
        } : {}
    };

/LUMEN_working_videogame/scene.phn

onCollide := (e)=>{
        e.other.materialname == "q" ? {
            collideset = 0;
            _end = 1;
            scene.my.luce = scene.my.luce + 0.67000002
        } : {}
    };

/LUMEN_working_videogame/scene.phn

onCollide := (e)=>{
        _cambio = 1
    };

/Octopus_mimetization/scene.phn

onCollide := (e)=>{
        colorHSVA = e.other.colorHSVA
    };

/virus_scripted/scene.phn

onCollide := (e)=>{
        e.other.materialName == "virus" ? {
            _inff = 1;
            timeToLive = 0.0099999998
        } : {}
    };

/engine_gearbox_and_clutch_mechanism/scene.phn

onCollide := (e)=>{
        scene.addCircle({
            radius := 0.14000000;
            density := 27.000000;
            restitution := 0.50000000;
            friction := 0.050000001;
            color := [0.89995694, 0.59997129, 0.0000000, 1.0000000];
            pos := e.pos;
            collideSet := 3;
            drawCake := false;
            edgeBlur := 0.18000001
        })
    };

/SCRIPT_COLLECTION_2/scene.phn

onCollide := (e)=>{
        e.other.color = e.this.color;
        e.other.COLLIDESET = 5
    };

/SCRIPT_COLLECTION_2/scene.phn

onCollide := (e)=>{
        Scene.addWater({
            vecs = [e.pos]
        });
        e.other.text = "Hit The Water Spawner"
    };

/Laser_counter_no_collision/scene.phn

onCollide := (e)=>{
        my.scene.hits = my.scene.hits + 1;
        e.other.pos = [-3.8449609, 1.9727136]
    };

/Laser_counter_with_1_laser/scene.phn

onCollide := (e)=>{
        my.scene.hits = my.scene.hits + 1;
        e.other.pos = [-3.8449609, 1.9727136]
    };

/OLD_WRITING_MACHINE/scene.phn

onCollide := (e)=>{
        e.other.color = e.this.color
    };

/infinite_landscape_desert_auto_driving_jeep/scene.phn

onCollide := (e)=>{
        e.other.pos = scene.my.tpNo6;
        e.other.vel = [0, 0];
        e.other.color = e.this.color
    };

/script_COLLECTION/scene.phn

onCollide := (e)=>{
        scene.camera.zoom = 21.500000
    };

/armed_robot_mission_2/scene.phn

onCollide := (e)=>{
        scene.camera.zoom = 21.500000
    };

/script_COLLECTION/scene.phn

onCollide := (e)=>{
        my.scene.hits = my.scene.hits + 1
    };

/script_COLLECTION/scene.phn

onCollide := (e)=>{
        e.other.pos = [-0.66366851, -0.78284615];
        my.scene.score = my.scene.score + 1;
        my.scene.hits = 0
    };

/script_COLLECTION/scene.phn

onCollide := (e)=>{
        e.other.pos = scene.my.tpNo7;
        e.other.vel = [0, 0]
    };

/Toys_for_kids/scene.phn

onCollide := (e)=>{
        e.other.pos = scene.my.tpNo7;
        e.other.vel = [0, 0]
    };

/script_COLLECTION/scene.phn

onCollide := (e)=>{
        e.other.color = e.this.color;
        e.other.density = 1
    };

/script_COLLECTION/scene.phn

onCollide := (e)=>{
        e.other.color = e.this.color;
        e.other.density = 0.0010000000;
        e.other.radius = 0.064999998;
        e.other.edgeblur = 0
    };

/armed_robot_mission_3/scene.phn

onCollide := (e)=>{
        scene.camera.zoom = 14.700000
    };

/armed_robot_mission_3/scene.phn

onCollide := (e)=>{
        scene.camera.zoom = 6.6999998
    };

/PSYCHEDELIC_LASER_PINBALL_plus_SCORE_COUNTER/scene.phn

onCollide := (e)=>{
        my.scene.score = my.scene.score + 1;
        my.scene.hits = 0
    };

/elettric_bell_mechanism/scene.phn

onCollide := (e)=>{
        _q = _q + 0.10000000
    };

/elettric_bell_mechanism/scene.phn

onCollide := (e)=>{
        e.other.materialName == "on" ? {_on = 1} : {};
        e.other.materialName == "off" ? {_on = 0} : {}
    };

onSpawn

/primitive_adder_of_numbers_up_to_5_digits/scene.phn

onSpawn := (e)=>{
        my.scene.hits = 0
    };

/Automatic_scripted_pinball_no_human_control/scene.phn

onSpawn := (e)=>{
        my.scene.hits = 0
    };

/Beyblade/scene.phn

onSpawn := (e)=>{
        my.scene.hits = 0
    };

/Laser_counter_no_collision/scene.phn

onSpawn := (e)=>{
        my.scene.hits = 0
    };

/Pong_playtig_alone_NO_human_control/scene.phn

onSpawn := (e)=>{
        my.scene.score = 0
    };

/script_COLLECTION/scene.phn

onSpawn := (e)=>{
        my.scene.score = 0
    };

/PSYCHEDELIC_LASER_PINBALL_plus_SCORE_COUNTER/scene.phn

onSpawn := (e)=>{
        my.scene.score = 0
    };

/orbits2/scene.phn

onSpawn := (e)=>{
        Scene.my.last_fire = 0
    };

/Laser_counter_with_1_laser/scene.phn

onSpawn := (e)=>{
        my.scene.hits3 = 0
    };

onKey

Smooth-move an object to the cursor when a key is held

(e)=>{
    keys.isDown("1") ? {
        e.this.color = [0.2, 0.4, 0.6, 1];
        e.this.pos = lerp(pos, App.mousePos, 0.15)
    } : {
        e.this.color = [1, 1, 1, 0]
    }
}

/Catching_puppets_crane/scene.phn

onKey := (e)=>{
        keys.isDown("return") ? {
            _start = 1
        } : {}
    };

/Plasma_cannon/scene.phn

onKey := (e)=>{
        keys.isDown("v") ? {_fire} : {};
        keys.isDown("b") ? {_firen} : {}
    };

/LUMEN_working_videogame/scene.phn

onKey := (e)=>{
        keys.isDown("w") ? {_dir = 0} : {};
        keys.isDown("d") ? {_dir = 1} : {};
        keys.isDown("a") ? {_dir = 2} : {};
        keys.isDown("s") ? {_dir = 3} : {}
    };

/mechanism_various_script_interface/scene.phn

onKey := (e)=>{
        keys.isDown("return") ? {_kk = 1} : {};
        keys.isDown("backspace") ? {_kk = 1} : {}
    };

/mechanism_various_script_interface/scene.phn

onKey := (e)=>{
        keys.isDown("backspace") ? {_k = 1} : {_k = 0}
    };

/mechanism_various_script_interface/scene.phn

onKey := (e)=>{
        keys.isDown("return") ? {_k = 1} : {_k = 0}
    };

/mechanism_various_script_interface/scene.phn

onKey := (e)=>{
        keys.isDown("return") ? {
            _scroll = _scroll + 5
        } : {};
        keys.isDown("backspace") ? {
            _scroll = _scroll - 5
        } : {}
    };

/mechanism_various_script_interface/scene.phn

onKey := (e)=>{
        keys.isDown("return") ? {
            _kk = 1.5000000
        } : {};
        keys.isDown("backspace") ? {
            _kk = 1.5000000
        } : {}
    };
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "bdb86c03-659e-4464-9090-7e1536481304",
"metadata": {
"collapsed": true,
"jupyter": {
"outputs_hidden": true
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Looking in indexes: https://pypi.company.com/simple\n",
"Collecting python-lsp-server[all]\n",
" Downloading https://pypi.company.com/packages/packages/ca/bb/1b0df050aaf10e6aacdb15dc0f3ed58b32cb0fa0661d278e1cf57bdb1b65/python_lsp_server-1.6.0-py3-none-any.whl (63 kB)\n",
"\u001b[K |████████████████████████████████| 63 kB 2.1 MB/s eta 0:00:011\n",
"\u001b[?25hCollecting docstring-to-markdown\n",
" Downloading https://pypi.company.com/packages/packages/a9/ad/71cb84c8be4aa428d27b2c8e380a265b61671b2a15ce0dc4103133d12f6b/docstring_to_markdown-0.10-py3-none-any.whl (17 kB)\n",
"Requirement already satisfied: jedi<0.19.0,>=0.17.2 in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from python-lsp-server[all]) (0.18.1)\n",
"Requirement already satisfied: setuptools>=39.0.0 in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from python-lsp-server[all]) (61.2.0)\n",
"Requirement already satisfied: pluggy>=1.0.0 in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from python-lsp-server[all]) (1.0.0)\n",
"Collecting python-lsp-jsonrpc>=1.0.0\n",
" Downloading https://pypi.company.com/packages/packages/06/ee/754bfd5f6bfe7162c10d3ecb0aeef6f882f91d3231596c83f761a75efd0b/python_lsp_jsonrpc-1.0.0-py3-none-any.whl (8.5 kB)\n",
"Collecting ujson>=3.0.0\n",
" Downloading https://pypi.company.com/packages/packages/24/18/844fa5d6668900a6fb2cfcc1bd38a6b2cd0b75783943b4e422a8c867ba1f/ujson-5.5.0-cp39-cp39-macosx_11_0_arm64.whl (45 kB)\n",
"\u001b[K |████████████████████████████████| 45 kB 22.3 MB/s eta 0:00:01\n",
"\u001b[?25hCollecting autopep8<1.7.0,>=1.6.0\n",
" Using cached https://pypi.company.com/packages/packages/39/3a/cd60ecce0d9737efefc06a074ae280a5d0e904d697fe59b414bf8ab5c472/autopep8-1.6.0-py2.py3-none-any.whl (45 kB)\n",
"Requirement already satisfied: pycodestyle<2.10.0,>=2.9.0 in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from python-lsp-server[all]) (2.9.1)\n",
"Collecting whatthepatch\n",
" Downloading https://pypi.company.com/packages/packages/93/f7/3276ba8d661f459afb171af169a7f68a390ede84c5510baf4575ce3316df/whatthepatch-1.0.3-py3-none-any.whl (11 kB)\n",
"Collecting flake8<5.1.0,>=5.0.0\n",
" Downloading https://pypi.company.com/packages/packages/cf/a0/b881b63a17a59d9d07f5c0cc91a29182c8e8a9aa2bde5b3b2b16519c02f4/flake8-5.0.4-py2.py3-none-any.whl (61 kB)\n",
"\u001b[K |████████████████████████████████| 61 kB 3.3 MB/s eta 0:00:01\n",
"\u001b[?25hCollecting pydocstyle>=2.0.0\n",
" Downloading https://pypi.company.com/packages/packages/87/67/4df10786068766000518c6ad9c4a614e77585a12ab8f0654c776757ac9dc/pydocstyle-6.1.1-py3-none-any.whl (37 kB)\n",
"Collecting pyflakes<2.6.0,>=2.5.0\n",
" Downloading https://pypi.company.com/packages/packages/dc/13/63178f59f74e53acc2165aee4b002619a3cfa7eeaeac989a9eb41edf364e/pyflakes-2.5.0-py2.py3-none-any.whl (66 kB)\n",
"\u001b[K |████████████████████████████████| 66 kB 30.3 MB/s eta 0:00:01\n",
"\u001b[?25hRequirement already satisfied: pylint>=2.5.0 in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from python-lsp-server[all]) (2.12.2)\n",
"Requirement already satisfied: mccabe<0.8.0,>=0.7.0 in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from python-lsp-server[all]) (0.7.0)\n",
"Requirement already satisfied: rope>=0.10.5 in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from python-lsp-server[all]) (0.22.0)\n",
"Collecting yapf\n",
" Using cached https://pypi.company.com/packages/packages/47/88/843c2e68f18a5879b4fbf37cb99fbabe1ffc4343b2e63191c8462235c008/yapf-0.32.0-py2.py3-none-any.whl (190 kB)\n",
"Requirement already satisfied: toml in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from autopep8<1.7.0,>=1.6.0->python-lsp-server[all]) (0.10.2)\n",
"Requirement already satisfied: parso<0.9.0,>=0.8.0 in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from jedi<0.19.0,>=0.17.2->python-lsp-server[all]) (0.8.3)\n",
"Requirement already satisfied: snowballstemmer in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from pydocstyle>=2.0.0->python-lsp-server[all]) (2.2.0)\n",
"Requirement already satisfied: astroid<2.10,>=2.9.0 in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from pylint>=2.5.0->python-lsp-server[all]) (2.9.0)\n",
"Collecting pylint>=2.5.0\n",
" Downloading https://pypi.company.com/packages/packages/d5/5f/dbeceb81e1b3700d1cca3e8b19b0f6643b0e32b675bb75cb9f74de95e920/pylint-2.15.6-py3-none-any.whl (508 kB)\n",
"\u001b[K |████████████████████████████████| 508 kB 113.0 MB/s eta 0:00:01\n",
"\u001b[?25hCollecting dill>=0.2\n",
" Downloading https://pypi.company.com/packages/packages/be/e3/a84bf2e561beed15813080d693b4b27573262433fced9c1d1fea59e60553/dill-0.3.6-py3-none-any.whl (110 kB)\n",
"\u001b[K |████████████████████████████████| 110 kB 152.3 MB/s eta 0:00:01\n",
"\u001b[?25hRequirement already satisfied: tomli>=1.1.0 in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from pylint>=2.5.0->python-lsp-server[all]) (1.2.2)\n",
"Requirement already satisfied: platformdirs>=2.2.0 in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from pylint>=2.5.0->python-lsp-server[all]) (2.4.0)\n",
"Collecting astroid<=2.14.0-dev0,>=2.12.12\n",
" Downloading https://pypi.company.com/packages/packages/b1/61/42e075b7d29ed4d452d91cbaaca142710d50d04e68eb7161ce5807a00a30/astroid-2.12.13-py3-none-any.whl (264 kB)\n",
"\u001b[K |████████████████████████████████| 264 kB 180.4 MB/s eta 0:00:01\n",
"\u001b[?25hCollecting tomlkit>=0.10.1\n",
" Downloading https://pypi.company.com/packages/packages/2b/df/971fa5db3250bb022105d17f340339370f73d502e65e687a94ca1a4c4b1f/tomlkit-0.11.6-py3-none-any.whl (35 kB)\n",
"Requirement already satisfied: isort<6,>=4.2.5 in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from pylint>=2.5.0->python-lsp-server[all]) (5.9.3)\n",
"Requirement already satisfied: typing-extensions>=3.10.0 in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from pylint>=2.5.0->python-lsp-server[all]) (4.1.1)\n",
"Requirement already satisfied: lazy-object-proxy>=1.4.0 in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from astroid<=2.14.0-dev0,>=2.12.12->pylint>=2.5.0->python-lsp-server[all]) (1.6.0)\n",
"Requirement already satisfied: wrapt<2,>=1.11 in /Users/andre/.pyenv/versions/anaconda3-2022.05/lib/python3.9/site-packages (from astroid<=2.14.0-dev0,>=2.12.12->pylint>=2.5.0->python-lsp-server[all]) (1.13.3)\n",
"Installing collected packages: ujson, tomlkit, python-lsp-jsonrpc, pyflakes, docstring-to-markdown, dill, astroid, yapf, whatthepatch, python-lsp-server, pylint, pydocstyle, flake8, autopep8\n",
" Attempting uninstall: pyflakes\n",
" Found existing installation: pyflakes 2.4.0\n",
" Uninstalling pyflakes-2.4.0:\n",
" Successfully uninstalled pyflakes-2.4.0\n",
" Attempting uninstall: astroid\n",
" Found existing installation: astroid 2.9.0\n",
" Uninstalling astroid-2.9.0:\n",
" Successfully uninstalled astroid-2.9.0\n",
" Attempting uninstall: pylint\n",
" Found existing installation: pylint 2.12.2\n",
" Uninstalling pylint-2.12.2:\n",
" Successfully uninstalled pylint-2.12.2\n",
" Attempting uninstall: autopep8\n",
" Found existing installation: autopep8 1.7.0\n",
" Uninstalling autopep8-1.7.0:\n",
" Successfully uninstalled autopep8-1.7.0\n",
"Successfully installed astroid-2.12.13 autopep8-1.6.0 dill-0.3.6 docstring-to-markdown-0.10 flake8-5.0.4 pydocstyle-6.1.1 pyflakes-2.5.0 pylint-2.15.6 python-lsp-jsonrpc-1.0.0 python-lsp-server-1.6.0 tomlkit-0.11.6 ujson-5.5.0 whatthepatch-1.0.3 yapf-0.32.0\n"
]
}
],
"source": [
"!pip install 'python-lsp-server[all]' jupyterlab-lsp"
]
},
{
"cell_type": "code",
"execution_count": 816,
"id": "ba6b613d-5606-4bbd-a5dc-50c0fa9368c7",
"metadata": {},
"outputs": [],
"source": [
"import re\n",
"from glob import glob\n",
"from pprint import pprint as pp\n",
"# # := (e)=>{\\n}.*?\\n };$))\n",
"#\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 817,
"id": "8077efe7-4524-4965-bf5d-0f75979ba018",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"postStep := (e)=>{\n",
" q = (math.sin(sim.time * 5)) * 16;\n",
" colorHSVA = [230.00000 + q, 1.0000000, 1.0000000, 1.0000000]\n",
" };\n",
"onKey := (e)=>{\n",
" if(e.keyCode == \"up\", {\n",
" if((Sim.time - Scene.my.last_fire) > 0.32, {\n",
" Scene.addCircle({\n",
" color := [1.0, 0.5, 0.0, 1.0];\n",
" pos := App.mousePos;\n",
" radius := 0.2;\n",
" vel = [4, 0]\n",
" });\n",
" Scene.my.last_fire = Sim.time\n",
" })\n",
" })\n",
" };\n"
]
},
{
"data": {
"text/plain": [
"[[None, None]]"
]
},
"execution_count": 817,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# thyme code looks something like this:\n",
"s = \"\"\"\n",
" postStep := (e)=>{\n",
" q = (math.sin(sim.time * 5)) * 16;\n",
" colorHSVA = [230.00000 + q, 1.0000000, 1.0000000, 1.0000000]\n",
" };\n",
" foo := 'baz';\n",
" update := (e)=>{};\n",
" onKey := (e)=>{\n",
" if(e.keyCode == \"up\", {\n",
" if((Sim.time - Scene.my.last_fire) > 0.32, {\n",
" Scene.addCircle({\n",
" color := [1.0, 0.5, 0.0, 1.0];\n",
" pos := App.mousePos;\n",
" radius := 0.2;\n",
" vel = [4, 0]\n",
" });\n",
" Scene.my.last_fire = Sim.time\n",
" })\n",
" })\n",
" };\n",
" \"\"\"\n",
"# here's our pattern for extracting interesting function definitions\n",
"pat = re.compile(\n",
" r\"\"\"\n",
" # interesting function names\n",
" ((?:postStep|update|onCollide|onSpawn|onKey)\n",
" \\s := \\s\n",
" # anything other than an empty function definition\n",
" \\(e\\)=>{[^}]\n",
" # everything until the first \"}\" or \"};\" at the end of a line\n",
" .*?\\n\\s\\s\\s\\s};$)\"\"\", re.MULTILINE | re.DOTALL | re.X)\n",
"\n",
"m = re.findall(pat, s)\n",
"[[print(i) for i in m]]"
]
},
{
"cell_type": "code",
"execution_count": 818,
"id": "b2693c92-3851-486b-b460-e2f9dafa2cb7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"glob matched 140 files\n"
]
}
],
"source": [
"files = glob(\"**/*.phn\", recursive=True)\n",
"print(f\"glob matched {len(files)} files\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b57fc11f-36ae-4ef6-b2e9-ed78e7e62226",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 819,
"id": "4d928a36-00ef-4195-8369-bcb7c583ee67",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'// FileVersion 21\\n// Algodoo scene created by Algodoo v2.1.3\\n\\nFileInfo -> {\\n '"
]
},
"execution_count": 819,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"del(s)\n",
"s = open(files[9], 'r', encoding='utf-8-sig').read()\n",
"type(s)\n",
"s[0:80]\n",
"#print(s)"
]
},
{
"cell_type": "code",
"execution_count": 820,
"id": "9c3af835-7e71-48a7-b2c7-f74d1a880b5d",
"metadata": {},
"outputs": [],
"source": [
"def extractPhun(s):\n",
" m = re.findall(pat, s)\n",
" return m"
]
},
{
"cell_type": "code",
"execution_count": 821,
"id": "be954ee5-e050-4bb5-b8ab-03374098ae02",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"243\n"
]
}
],
"source": [
"# we'll key our results dict by the hexdigest of a script snippet body\n",
"import hashlib\n",
"# d = hashlib.sha3_256(b\"foobar\")\n",
"# d.hexdigest()\n",
"\n",
"# we also want to keep track of the file each snippet came from\n",
"# { digest : {s: snippet, files: [file1, file2]}}\n",
"results = dict()\n",
"\n",
"# only take the first 10 samples from a given file\n",
"from collections import Counter\n",
"c = Counter()\n",
"\n",
"# there are lots of very similar snippets. remember the previous\n",
"# snippet so we can filter out the similar ones.\n",
"from difflib import SequenceMatcher\n",
"prev = \"\"\n",
"\n",
"for file in files:\n",
" s = open(file, 'r', encoding='utf-8-sig').read()\n",
" s = extractPhun(s)\n",
" # remove the first directory path component\n",
" file = file.replace('algodoo_scenes', '')\n",
" for i in s:\n",
" # don't take excessively long snippets,\n",
" # just because by inspection they seem repetitive\n",
" if len(i) > 400:\n",
" continue\n",
" m = SequenceMatcher(None, i, prev)\n",
" if m.ratio() > 0.7:\n",
" # too similar, skip\n",
" continue\n",
" prev = i\n",
" h = hashlib.sha3_256(i.encode(\"utf-8\")).hexdigest()\n",
" # #print(f\"generated hash {h} for chunk of length {len(i)} from file {file}\")\n",
" # cap the number of samples from each file\n",
" # if c['file'] > 5:\n",
" # print(f\"got enough from {file}\")\n",
" # break\n",
" c.update(file)\n",
" if h not in results:\n",
" results.update({h: {\"files\": [file], \"s\": i}})\n",
" elif file not in results[h]['files']:\n",
" #print(results[h]['files'])\n",
" results[h]['files'].append(file)\n",
"\n",
"print(len(results))\n"
]
},
{
"cell_type": "code",
"execution_count": 822,
"id": "f2bd07dc-b0a4-4bf4-a278-65c38897013c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('f5d40e85a497aac5349083fd8a2ffa0ab9b155db881fe6908543253cdff88fb4',\n",
" {'files': ['/Self_pilot_two_engine_stabilized_drone/scene.phn'],\n",
" 's': 'postStep := (e)=>{\\n'\n",
" ' my.scene.UpDown = ((pos(1) - 70.699997) * (-1)) * 10;\\n'\n",
" ' my.scene.DxSx = ((pos(0) - 64.300003) * (-1)) * 10\\n'\n",
" ' };'})\n"
]
}
],
"source": [
"pp(list(results.items())[15])"
]
},
{
"cell_type": "code",
"execution_count": 823,
"id": "4e95e500-7465-48c6-b22c-c44c210219d8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"243\n"
]
}
],
"source": [
"print(len(results.keys()))\n",
"outfile = open('thyme.md', 'w')\n",
"funcs = ['postStep', 'update', 'onCollide', 'onSpawn', 'onKey']\n",
"\n",
"def writeExamples(function, results):\n",
" print(f\"## {function}\\n\", file=outfile)\n",
" for k, v in results.items():\n",
" if not v['s'].startswith(function):\n",
" continue\n",
" for f in v['files']: \n",
" print(f\"{f}\", file=outfile)\n",
" print(f\"```\\n{v['s']}\\n```\\n\", file=outfile)\n",
"\n",
"for fun in funcs:\n",
" writeExamples(fun, results)\n",
" \n",
"outfile.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d1d0717f-8b38-42f2-9e01-1ce013da8da4",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment