class kscroll { float speed=0; float start; float decay; float decay_start; int decay_maxmillis=5000; // decrease scrolling speed once mouse is released float slowdown() { float d=0; // if there is still some scrolling energy if(this.decay>0) { //i tried a few slowing formulas this.decay=1-inverse(millis()-this.decay_start,this.decay_maxmillis); //this.decay=1-sigmoid(millis()-this.decay_start,this.decay_maxmillis); //this.decay=this.decay*.9; d=this.speed*this.decay; } return d; } //slowdown void begin(int x) { // the initial scrolling speed is the speed it was being dragged this.speed = x-this.start; this.start = x; } //begin void grab(int x) { // while grabbing is occuring, the scrolling link to mouse movement this.start = x; this.speed = 0; } //grab void startslowdown() { // the mouse has been released and we can start slowing the scroll // the speed starts at 100% of the current scroll speed // record the time so we can calualte the decay rate this.decay=1; this.decay_start=millis(); } //startslodown }//kdrag