
Animation sliders are like tracks on a mixing console. In fact, the slider is a number from 0.0 to 1.0, where 0.0 is the beginning of the animation, and 1.0 is its end. This number is substituted into the mathematical formula. Why do we need these sliders? They are needed because usually there are many elements in the interface, everyone needs animation and their movement must begin and end at the same time. But the type of animation and the coordinates of each element on the screen can be different.#define MAXSLIDES 5 // #define LOOP_ANIM 1 // #define FORWBACK_ANIM 2 // - static float slide[MAXSLIDES]={0.0f}; // , 0.0 1.0 static bool slideback[MAXSLIDES]={false}; // , static bool loopback[MAXSLIDES]={false}; // -, static void ANIM(int n, float speed=1.0f, bool forw=true, char loop=0){ //n - //speed - //forw - //loop - if(loopback[n])forw=!forw; // - slideback[n]=!forw; // slide[n]+=fpsf*(forw?speed:-speed); // , fpsf = 1.0/FPS switch(loop){ case LOOP_ANIM: // if(slide[n]>1.0f)slide[n]-=1.0f; else if(slide[n]<0.0f)slide[n]+=1.0f; break; case FORWBACK_ANIM: // - if(slide[n]>1.0f){ slide[n]=2.0f-slide[n]; loopback[n]=!loopback[n]; }else if(slide[n]<0.0f){ slide[n]=-slide[n]; loopback[n]=!loopback[n]; } break; default: // 0.0 1.0 if(slide[n]>1.0f)slide[n]=1.0f; else if(slide[n]<0.0f)slide[n]=0.0f; break; } } // #define LINEAR 0 #define FADEIN 1 #define FADEOUT 2 #define BALL 3 #define SIN 4 #define INCENTER 5 #define FADEBOTH 6 #define FADEBOTH2 7 #define STEPS 8 #define LAMP 9 #define JUMPIN 10 #define JUMPOUT 11 static float A(int n, int type, float s, float e, int typeout=0, float e2=-1000.0f){ // n - //type - //s e - , //typeout - () //e2 - () if(n<0){ // float tmp=s; s=e; e=tmp; n=-n; if(!slideback[n]){ if(typeout)type=typeout; if(e2!=-1000.0f)e=e2; } }else{ // , if(slideback[n]){ if(typeout)type=typeout; if(e2!=-1000.0f)s=e2; } } float x=slide[n]; // switch(type){ case FADEOUT: x=x*x; break; case FADEIN: x=1.0f-pow(x-1.0f, 2); break; case FADEBOTH: x=pow(sinf(x*M_PI*0.5f), 2); break; case FADEBOTH2: x=pow(sinf(x*M_PI*0.5f), 2); x=pow(sinf(x*M_PI*0.5f), 2); break; case INCENTER: x=tanf(x*2.0f-1.0f)/3.0f+0.5f; break; case BALL:{ float d=sinf((x-1.0f/12.0f)*M_PI*6.0f)*0.65f+0.65f; x=d+sinf(x*M_PI*0.5f)*(1.0fd); }break; case STEPS: x=(int)(x*7.0f)/7.0f; break; case LAMP: x=sinf(pow(expf(1.25fx), 2)*4.0f); if(x>0.0f)x=1.0f; else x=0.0f; break; case JUMPOUT: x=x*x*8.0f/3.0fx*5.0f/3.0f; break; case JUMPIN: x=x-1.0f; x=-x*x*8.0f/3.0fx*5.0f/3.0f+1.0f; break; } // return s+(es)*x; } static void mainLoop(){ // ANIM(1, 1.0f, showPage); // №1 , ANIM(2, 2.0f, true, LOOP_ANIM); // №2 , // glColor4f(1.0f, 1.0f, 1.0f, A(1, FADEIN, 0.0f, 1.0f)); DrawSomeImage(width/2, A(1, BALL, -150, height/2, FADEIN, height+200)); DrawOtherImage(A(2, INCENTER, -150, width+150), 100); } 

glColor4f(1.0f, 1.0f, 1.0f, A(1, FADEBOTH, 0.0f, 1.0f)); DrawSomeImage1(); glColor4f(1.0f, 1.0f, 1.0f, A(-1, FADEBOTH, 0.0f, 1.0f)); DrawSomeImage2(); Source: https://habr.com/ru/post/163197/
All Articles