Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.69 KB | None | 0 0
  1. float t = 0;
  2. color[] pal;
  3.  
  4. Console con;
  5.  
  6. int dimX = 50; //40
  7. int dimY = 100; //80
  8.  
  9. void setup() {
  10.   //fullScreen(P3D);    // Phone version
  11.   size(576, 1024, P3D); // PC version
  12.   noSmooth();
  13.   frameRate(60);
  14.   //ortho();
  15.  
  16.   con = new Console();
  17.  
  18.   pulse_reset();
  19.   color_reset();
  20. }
  21.  
  22. void draw() {
  23.   background(0);
  24.  
  25.   t = frameCount * 0.1;
  26.  
  27.   con.clear();
  28.  
  29.   if ( frameCount % 200 == 0 ) {
  30.     pulse_reset();
  31.     color_reset();
  32.   }
  33.  
  34.   pulse_();
  35.  
  36.   noise_(floor(sin(t*0.05)*100));
  37.  
  38.   con.render();
  39. }
  40.  
  41.  
  42. class Console {
  43.  
  44.   int[][] c;
  45.   int[][] cc;
  46.  
  47.   PVector dim = new PVector(
  48.     width/dimX,
  49.     height/dimY
  50.     );
  51.  
  52.   Console() {
  53.     this.build();
  54.   }
  55.  
  56.   void build() {
  57.     c = new int[dimX][dimY];
  58.     cc = new int[dimX][dimY];
  59.  
  60.     this.clear();
  61.   }
  62.  
  63.   void clear() {
  64.     for ( int x = 0; x < dimX; ++x ) {
  65.       for ( int y = 0; y < dimY; ++y ) {
  66.         c[x][y] = 0;
  67.         cc[x][y] = 0;
  68.       }
  69.     }
  70.   }
  71.  
  72.   void write(int x, int y, int v) {
  73.     if ( x < 0 || y < 0 || x >= dimX || y >= dimY ) {
  74.       return;
  75.     }
  76.     c[x][y] = v;
  77.   }
  78.  
  79.   void writeCol(int x, int y, int v) {
  80.     if ( x < 0 || y < 0 || x >= dimX || y >= dimY ) {
  81.       return;
  82.     }
  83.     cc[x][y] = v;
  84.   }
  85.  
  86.   void render() {
  87.     beginShape(QUADS);
  88.     noStroke();
  89.     for ( int x = 0; x < dimX; ++x ) {
  90.       for ( int y = 0; y < dimY; ++y ) {
  91.         float alpha = 0;
  92.         color col = color(255);
  93.  
  94.         switch ( c[x][y] ) {
  95.         case 0:
  96.           break;
  97.         case 1:
  98.           alpha = 90;
  99.           break;
  100.         case 2:
  101.           alpha = 150;
  102.           break;
  103.         case 3:
  104.           alpha = 255;
  105.           break;
  106.         }
  107.  
  108.  
  109.         col = pal[
  110.           constrain(cc[x][y], 0, 4)
  111.         ];
  112.  
  113.         if ( alpha > 0.01 ) {
  114.           float x_ = x * dim.x;
  115.           float y_ = y * dim.y;
  116.           float z_ = noise(x_, y_) * 100;
  117.           fill(col, alpha);
  118.           vertex(x_, y_, z_);
  119.           vertex(x_, y_ + dim.y, z_);
  120.           vertex(x_ + dim.x, y_ + dim.y, z_);
  121.           vertex(x_ + dim.x, y_, z_);
  122.         }
  123.       }
  124.     }
  125.     endShape();
  126.   }
  127. }
  128.  
  129. int rX(float x) {
  130.   return round(map(x, 0, width, 0, dimX));
  131. }
  132.  
  133. int rY(float y) {
  134.   return round(map(y, 0, height, 0, dimY));
  135. }
  136.  
  137.  
  138. void noise_(int count) {
  139.   if ( count <= 0 ) {
  140.     return;
  141.   }
  142.   for ( int i = 0; i < count; ++i ) {
  143.     int x = floor(random(dimX));
  144.     int y = floor(random(dimY));
  145.  
  146.     con.write(x, y, floor(random(1, 2)));
  147.     con.writeCol(x, y, floor(random(3)));
  148.   }
  149. }
  150.  
  151. void line_(int p, boolean vert) {
  152.  
  153.   int steps = vert ? dimY : dimX;
  154.   for ( int i = 0; i < steps; ++i ) {
  155.     int x = vert ? p : i;
  156.     int y = vert ? i : p;
  157.  
  158.     con.write(x, y, floor(random(2, 4)));
  159.     con.writeCol(x, y, 4);
  160.   }
  161. }
  162.  
  163. float pulse_ex;
  164. float pulse_spd;
  165. float pulse_str;
  166.  
  167. void pulse_reset() {
  168.   pulse_ex = random(0.03, 0.003);
  169.   pulse_spd = random(-0.03, 0.03);
  170.   pulse_str = random(-500, 500);
  171. }
  172.  
  173. void pulse_() {
  174.   for ( int x = 0; x < dimX; ++x ) {
  175.     for ( int y = 0; y < dimY; ++y ) {
  176.       float d = dist(x, y, dimX/2, dimY/2);
  177.       d += noise(
  178.         x*pulse_ex,
  179.         y*pulse_ex,
  180.         t*pulse_spd)
  181.         *pulse_str;
  182.  
  183.       float ctrl = (map(
  184.         d,
  185.         0, dimY/2, 0, 1) +
  186.         t * 0.3 + sin(t*0.5)*0.1)%1;
  187.       con.write(x, y,
  188.         floor(map(ctrl, 0, 1, 0, 4)));
  189.       con.writeCol(x, y,
  190.         floor(map(ctrl, 0, 1, 0, 5)));
  191.     }
  192.   }
  193. }
  194.  
  195. void pulse__() {
  196.   float off = 9999;
  197.   for ( int x = 0; x < dimX; ++x ) {
  198.     for ( int y = 0; y < dimY; ++y ) {
  199.       float d = dist(x, y, dimX/2, dimY/2);
  200.  
  201.       float x_ = (x < width/2) ? x : x + off;
  202.       float y_ = (y < height/2) ? y : y + off;
  203.  
  204.       d += noise(
  205.         x_*pulse_ex,
  206.         y_*pulse_ex,
  207.         t*pulse_spd)
  208.         *pulse_str;
  209.  
  210.       float ctrl = (map(
  211.         d,
  212.         0, dimY/2, 0, 1) +
  213.         t * 0.3 + sin(t*0.5)*0.1)%1;
  214.       con.write(x, y,
  215.         floor(map(ctrl, 0, 1, 0, 4)));
  216.       con.writeCol(x, y,
  217.         floor(map(ctrl, 0, 1, 0, 5)));
  218.     }
  219.   }
  220. }
  221.  
  222. void lines_() {
  223.   if ( frameCount % floor(1+abs(sin(t)*100)) == 0 ) {
  224.     int count = floor(random(1, 7));
  225.     boolean vert = random(1) > 0.5;
  226.     for ( int i = 0; i < count; ++i ) {
  227.       line_(
  228.         floor(random(vert?dimY:dimX)),
  229.         vert
  230.         );
  231.     }
  232.   }
  233. }
  234.  
  235.  
  236. color[][] pals = {
  237.   {
  238.     color(32, 17, 72),
  239.     color(32, 17, 162),
  240.     color(255, 52, 178),
  241.     color(0, 204, 254),
  242.     color(85, 231, 255)
  243.   },
  244.   {
  245.     color(140, 30, 255),
  246.     color(255, 41, 117),
  247.     color(242, 34, 255),
  248.     color(255, 144, 31),
  249.     color(255, 211, 25)
  250.   }
  251. };
  252.  
  253. void color_reset() {
  254.   pal = pals[floor(random(2))];
  255. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement