Advertisement
ForrestFox

Animation 3 shapes

Feb 28th, 2021
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include <sdl2framework.cc>
  2.  
  3. using namespace std;
  4.  
  5. SDL2framework* win;
  6.  
  7. float t = 0;
  8. const float PI = 3.141592;
  9. const float tri[3] = {0, 2*PI/3, 4*PI/3};
  10. const float square[4] = {0, 2*PI/4, 2*2*PI/4, 3*2*PI/4};
  11.  
  12. // Рисование выпуклой фигуры
  13. void closeup(int k, float t, struct vec3i ap, const float shape[], int cl) {
  14.  
  15.     int x = ap.x, y = ap.y, r = ap.z;
  16.  
  17.     for (int i = 0; i < k; i++) {
  18.         win->line(
  19.             x+sin(t+shape[i])*r,       y+cos(t+shape[i])*r,
  20.             x+sin(t+shape[(i+1)%k])*r, y+cos(t+shape[(i+1)%k])*r,
  21.             cl
  22.         );
  23.     }
  24. }
  25.  
  26. void update() {
  27.  
  28.     int w = win->w(), h = win->h();
  29.  
  30.     // Ослабление цветов
  31.     for (int y = 0; y < h; y++)
  32.     for (int x = 0; x < w; x++) {
  33.  
  34.         struct vec3i cl = win->i2rgb( win->point(x, y) );
  35.  
  36.         cl.x *= 0.92;
  37.         cl.y *= 0.92;
  38.         cl.z *= 0.92;
  39.  
  40.         // Фоновые облака
  41.         float b =  win->fbm((float)x/100 + t, (float)y/100 + sin(t))*16;
  42.  
  43.         cl.x += b*0.5;
  44.         cl.y += b*0.75;
  45.         cl.z += b;
  46.  
  47.         win->pset(x, y, -win->rgb(cl.x, cl.y, cl.z) );
  48.     }
  49.  
  50.     // Рисование фигур
  51.     win->circle(160, h/2, 10 + abs(sin(t))*64.0, 10);
  52.     win->circle(160, h/2, 10 + abs(cos(t))*32.0, 12);
  53.     win->circle(160, h/2, 10 + abs(sin(t)*cos(t))*48.0, 14);
  54.  
  55.     // Вращение фигур
  56.     closeup(3, t, {50, h/2, (int)(50 + sin(t)*25) }, tri, 13);
  57.     closeup(4, t, {270, h/2, (int)(50 + cos(t)*25) }, square, 11);
  58.  
  59.     t += 0.05;
  60. }
  61.  
  62. int main(int argc, char* argv[]) {
  63.  
  64.     win = new SDL2framework(14);
  65.     while (win->poll()) {
  66.  
  67.         if (win->timer()) {
  68.  
  69.             update();
  70.             win->record(argc, argv);
  71.         }
  72.     }
  73.  
  74.     return 0;
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement