Skip to content

Instantly share code, notes, and snippets.

@makoConstruct
Last active August 1, 2019 05:57
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 makoConstruct/4c5376b50d362ee5fecfe2e3b2240cff to your computer and use it in GitHub Desktop.
Save makoConstruct/4c5376b50d362ee5fecfe2e3b2240cff to your computer and use it in GitHub Desktop.
A thing for sort of averaging a quantity over time with just a single float
const float MemerPower = 2;
struct Memer{ //where p represents the pulse magnitude and delta represents the amount of time that has passed since the last pulse, the Memer sort of remembers the last couple of pulses and how long ago they were. For any consistent p, d, Will arrive at an equilibrium v that is higher if delta is lower and higher if p are higher. And I think- I'm not sure of this but it seems like something like this will hold- I think that for any a,b p,d where a/b = p/d, if you keep pulsing (a,b) and (p,d) they'll end up similar?
float v;
Memer(float v = 1):v(v){}
void pulse(float p, float delta){
float xof = log(v)/log(MemerPower);
v = pow(MemerPower, xof-delta) + p;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment