Advertisement
Guest User

BRCKHMPTN

a guest
Nov 13th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.57 KB | None | 0 0
  1. boolean recording = true;
  2. int samples_per_frame = 2;
  3. int[][] frame_buffer;
  4. float shutter_time = 0.55; // must be normal
  5.  
  6. float running_time = 8;
  7. int fps = 60;
  8. float millis_per_frame = 1000.0 / fps;
  9. int millis_per_cycle = int(running_time * 1000);
  10.  
  11. int num_frames = int(running_time * fps);
  12.  
  13.  
  14.  
  15.  
  16. int WIDTH = 1600;
  17. int HEIGHT = 760;
  18.  
  19. float TEXT_SIZE = 200;
  20. PFont font;
  21.  
  22. color colors[];
  23. float cweights[];
  24.  
  25. void settings() {
  26.   size(WIDTH, HEIGHT, P2D);
  27.   smooth(8);
  28. }
  29.  
  30. void setup() {
  31.     frameRate(fps);
  32.    
  33.   String[] font_list = PFont.list();
  34.   printArray(font_list);
  35.  
  36.   colors = new color[7];
  37.   cweights = new float[7];
  38.  
  39.   colors[0] = color(255, 255, 255);
  40.   colors[1] = color(9, 207, 242);
  41.   colors[2] = color(116, 231, 3);
  42.   colors[3] = color(255, 210, 0);
  43.   colors[4] = color(252, 45, 152);
  44.   colors[5] = color(255, 0, 90);
  45.   colors[6] = color(255, 255, 255);
  46.  
  47.   cweights[0] = 0.04;
  48.   //cweights[0] = 0.15;
  49.   cweights[1] = 0.19;
  50.   cweights[2] = 0.32;
  51.   cweights[3] = 0.45;
  52.   cweights[4] = 0.65;
  53.   cweights[5] = 0.80;
  54.   cweights[6] = 0.94;
  55.  
  56.   font = createFont("HelveticaNeueLTStd-BlkExO", TEXT_SIZE, true);
  57.   textFont(font);
  58.  
  59.     frame_buffer = new int[width*height][3];
  60. }
  61.  
  62. void draw() {
  63.     if (recording) {
  64.         for (int i = 0; i < width*height; i++) {
  65.             frame_buffer[i][0] = 0;
  66.             frame_buffer[i][1] = 0;
  67.             frame_buffer[i][2] = 0;
  68.         }
  69.        
  70.         for (int sample = 0; sample < samples_per_frame; sample++) {
  71.             float time = map((frameCount - 1) + sample * shutter_time / samples_per_frame, 0, num_frames, 0, 1);
  72.             _draw(time);
  73.             loadPixels();
  74.             for (int i = 0; i < pixels.length; i++) {
  75.                 frame_buffer[i][0] += (pixels[i] >> 16) & 0xff;
  76.                 frame_buffer[i][1] += (pixels[i] >>  8) & 0xff;
  77.                 frame_buffer[i][2] += (pixels[i]      ) & 0xff;
  78.             }
  79.         }
  80.        
  81.         loadPixels();
  82.        
  83.         for (int i = 0; i < pixels.length; i++) {
  84.             pixels[i] = ((frame_buffer[i][0] / samples_per_frame) << 16) |
  85.                         ((frame_buffer[i][1] / samples_per_frame) <<  8) |
  86.                         ((frame_buffer[i][2] / samples_per_frame)      ) |
  87.                         255 << 24;
  88.         }
  89.        
  90.         updatePixels();
  91.        
  92.         String file_out[] = new String[3];
  93.         file_out[0] = "BRCKHMPTN_";
  94.         file_out[1] = nf(frameCount, 4);
  95.         file_out[2] = ".png";
  96.         saveFrame(join(file_out, ""));
  97.         if (frameCount == num_frames) {
  98.             exit();
  99.         }
  100.     } else {
  101.         float time = map(millis() % millis_per_cycle, 0, millis_per_cycle, 0, 1);
  102.         _draw(time);
  103.     }
  104. }
  105.  
  106. color determine_color(float t) {
  107.     int end = 5;
  108.     for (int i = 0; i < 6; i++) {
  109.         if (cweights[i] > t) {
  110.             end = i;
  111.             break;
  112.         }
  113.     }
  114.  
  115.     int start = 0;
  116.     for (int i = 0; i < 6; i++) {
  117.         if (cweights[5-i] < t) {
  118.             start = 5-i;
  119.             break;
  120.         }
  121.     }
  122.    
  123.     float a;
  124.     if (start == end) {
  125.         float r = 1.0 - cweights[5] + cweights[0];
  126.        
  127.         if (start == 5) {
  128.             // in the last bit
  129.             a = map(t - cweights[5], 0, r, 0, 1);
  130.         } else {
  131.             // in the first bit
  132.             a = map(t + (1.0 - cweights[5]), 0, r, 0, 1);
  133.         }
  134.        
  135.         start = 5;
  136.         end = 0;
  137.     } else {
  138.         a = map(t, cweights[start], cweights[end], 0, 1);
  139.     }
  140.    
  141.     return lerpColor(colors[start], colors[end], a);
  142. }
  143.  
  144. void _draw(float time) {
  145.     background(3, 10, 105);
  146.  
  147.   noStroke();
  148.  
  149.   // ================ BROCKHAMPTON ===================
  150.  
  151.   for (int i = 0; i < 200; i++) {
  152.       float t = time + i * 0.001 + 0.02;
  153.       while (t >= 1.0) { t -= 1.0; }
  154.       color c = determine_color(t);
  155.       fill(c);
  156.       text("HAMPTON", 150 + i * 0.2 + random(1) * 1, i + TEXT_SIZE + 280 + random(1) * 1);
  157.   }
  158.  
  159.   for (int i = 0; i < 200; i++) {
  160.       float t = time + i * 0.001;
  161.       while (t >= 1.0) { t -= 1.0; }
  162.       color c = determine_color(t);
  163.       fill(c);
  164.       text("BROCK", i * 0.2 + random(1) * 1, i + TEXT_SIZE + 30 + random(1) * 1);
  165.   }
  166.  
  167.   // ============ FILM GRAIN ==============
  168.  
  169.   loadPixels();
  170.   for (int i = 0; i < width*height; i++) {
  171.       float k = random(1);
  172.       if (k > 0.95) {
  173.           pixels[i] = lerpColor(color(255), pixels[i], 0.75 + random(0.25));
  174.       } else {
  175.           pixels[i] = lerpColor(color(0), pixels[i], 0.9 + random(0.1));
  176.       }
  177.   }
  178.   updatePixels();
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement