This scene is intended for viewers as young as 3 years old who might not grasp the toggle idea. It also gives them an active part in driving the car and allows them to explore going frontwards and backwards. The light switch is the down key. There are only three controls (left, right, and down) which are very close together in order to keep it simple.
I assume you wish to pixelate a polygon. You define a function within a defined function within a defined function. This is not good, for reasons that Xray has already mentioned. Each function needs to defined only once, not 105 times a second. I got an "out of memory" while running this scene. If you can explain what the "AnyOf" and "scene.my.displaySurface" functions are supposed to do, then maybe we can help.
P.S.: Here is how they can be run as three separate functions that need to be defined once in the console;
Although "scene.my.displaySurface" is only loaded once, it creates (2) functions (scene.my.xFor and AnyOf) each time it's called. Wit 64 boxes calling "scene.my.displaySurface" 105 times a second, it seems that the scene can create up to 13440 new functions a second (64 * 2 * 105). If you use the (3) independent functions shown in my previous response, then no new fuctions are created when the scene is running.
Regarding "AnyOf is supposed to read the nearest surface to each box.", it doesn't. The following should do what I think you intended:
scene.my.displaySurface = (poly, disp)=>{
ra = scene.my.sf;
n = string.length(ra) - 1;
v = 100;
Scene.my.xFor(0, n, (i)=>{
d = math.vec.dist(poly.pos + ra(i), disp.pos);
d < v ? {v = d} : {}
});
disp.colorHSVA = [0.0, 0.0, 2 * v, 1.0]
};
in poly onSpawn:
scene.my.poly = entity;
scene.my.sf = (readable(owner)).surfaces(0);
in poly postStep:
pos = app.mousepos
in box postStep:
scene.my.displaySurface(scene.my.poly,entity)
At any rate, this does not pixelate the polygon but should pixelate the border of the polygon. I tried to design the code for minimum lag, but it didn't seem to help much.
Thyme scripting. Keys control the axle. The axle is connected to the circle which is connected to the spring. Circle rotation is converted to spring length change and is passed from the circle to the spring. Increase the motor speed to increase slide speed.
I think there is a lot simpler way of doing this, which I may eventually do to this scene or in future scenes.
Thanks for asking. I had thought that the "update" event happened every frame while "postStep" happens at sim.frequency. I tested this and I can see that they both run at the same rate.
P.S.
My test was flawed. The "update" event does happen every frame (usually at 60fps) and "postStep" does happen at sim.frequency.
Good call, Xray. It looks like _mp constantly updates when in onKey but not when in postStep. Also, the code only needs to be in one object (the spring), not three. Use the Alt key to select just one object.