Skip to content

Instantly share code, notes, and snippets.

@Sunjammer
Last active August 29, 2015 14:16
Show Gist options
  • Save Sunjammer/b6941cd35d17527fad2b to your computer and use it in GitHub Desktop.
Save Sunjammer/b6941cd35d17527fad2b to your computer and use it in GitHub Desktop.
Difficulty curve generation
inline function shape(input:Float, drive:Float):Float{
var k:Float = 2.0 * drive / (1.0 - drive);
return (1.0 + k) * input / (1.0 + k * Math.abs(input));
}
inline function tri(a:Float, x:Float):Float {
x = x / (2.0*Math.PI);
x = x % 1.0;
if( x<0.0 ) x = 1.0+x;
if(x<a) x=x/a; else x=1.0-(x-a)/(1.0-a);
return -1.0+2.0*x;
}
public function genDifficultyCurve(t:Float, diff:Float) {
var v = tri(0.7+diff*0.1, t * 6.28) * 0.5 + 0.5;
v = shape(v, 0.4);
v = shape(v, -0.9+diff*1);
v = 1 - v;
return v;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment