Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float t = 0;
- color[] pal;
- Console con;
- int dimX = 50; //40
- int dimY = 100; //80
- void setup() {
- //fullScreen(P3D); // Phone version
- size(576, 1024, P3D); // PC version
- noSmooth();
- frameRate(60);
- //ortho();
- con = new Console();
- pulse_reset();
- color_reset();
- }
- void draw() {
- background(0);
- t = frameCount * 0.1;
- con.clear();
- if ( frameCount % 200 == 0 ) {
- pulse_reset();
- color_reset();
- }
- pulse_();
- noise_(floor(sin(t*0.05)*100));
- con.render();
- }
- class Console {
- int[][] c;
- int[][] cc;
- PVector dim = new PVector(
- width/dimX,
- height/dimY
- );
- Console() {
- this.build();
- }
- void build() {
- c = new int[dimX][dimY];
- cc = new int[dimX][dimY];
- this.clear();
- }
- void clear() {
- for ( int x = 0; x < dimX; ++x ) {
- for ( int y = 0; y < dimY; ++y ) {
- c[x][y] = 0;
- cc[x][y] = 0;
- }
- }
- }
- void write(int x, int y, int v) {
- if ( x < 0 || y < 0 || x >= dimX || y >= dimY ) {
- return;
- }
- c[x][y] = v;
- }
- void writeCol(int x, int y, int v) {
- if ( x < 0 || y < 0 || x >= dimX || y >= dimY ) {
- return;
- }
- cc[x][y] = v;
- }
- void render() {
- beginShape(QUADS);
- noStroke();
- for ( int x = 0; x < dimX; ++x ) {
- for ( int y = 0; y < dimY; ++y ) {
- float alpha = 0;
- color col = color(255);
- switch ( c[x][y] ) {
- case 0:
- break;
- case 1:
- alpha = 90;
- break;
- case 2:
- alpha = 150;
- break;
- case 3:
- alpha = 255;
- break;
- }
- col = pal[
- constrain(cc[x][y], 0, 4)
- ];
- if ( alpha > 0.01 ) {
- float x_ = x * dim.x;
- float y_ = y * dim.y;
- float z_ = noise(x_, y_) * 100;
- fill(col, alpha);
- vertex(x_, y_, z_);
- vertex(x_, y_ + dim.y, z_);
- vertex(x_ + dim.x, y_ + dim.y, z_);
- vertex(x_ + dim.x, y_, z_);
- }
- }
- }
- endShape();
- }
- }
- int rX(float x) {
- return round(map(x, 0, width, 0, dimX));
- }
- int rY(float y) {
- return round(map(y, 0, height, 0, dimY));
- }
- void noise_(int count) {
- if ( count <= 0 ) {
- return;
- }
- for ( int i = 0; i < count; ++i ) {
- int x = floor(random(dimX));
- int y = floor(random(dimY));
- con.write(x, y, floor(random(1, 2)));
- con.writeCol(x, y, floor(random(3)));
- }
- }
- void line_(int p, boolean vert) {
- int steps = vert ? dimY : dimX;
- for ( int i = 0; i < steps; ++i ) {
- int x = vert ? p : i;
- int y = vert ? i : p;
- con.write(x, y, floor(random(2, 4)));
- con.writeCol(x, y, 4);
- }
- }
- float pulse_ex;
- float pulse_spd;
- float pulse_str;
- void pulse_reset() {
- pulse_ex = random(0.03, 0.003);
- pulse_spd = random(-0.03, 0.03);
- pulse_str = random(-500, 500);
- }
- void pulse_() {
- for ( int x = 0; x < dimX; ++x ) {
- for ( int y = 0; y < dimY; ++y ) {
- float d = dist(x, y, dimX/2, dimY/2);
- d += noise(
- x*pulse_ex,
- y*pulse_ex,
- t*pulse_spd)
- *pulse_str;
- float ctrl = (map(
- d,
- 0, dimY/2, 0, 1) +
- t * 0.3 + sin(t*0.5)*0.1)%1;
- con.write(x, y,
- floor(map(ctrl, 0, 1, 0, 4)));
- con.writeCol(x, y,
- floor(map(ctrl, 0, 1, 0, 5)));
- }
- }
- }
- void pulse__() {
- float off = 9999;
- for ( int x = 0; x < dimX; ++x ) {
- for ( int y = 0; y < dimY; ++y ) {
- float d = dist(x, y, dimX/2, dimY/2);
- float x_ = (x < width/2) ? x : x + off;
- float y_ = (y < height/2) ? y : y + off;
- d += noise(
- x_*pulse_ex,
- y_*pulse_ex,
- t*pulse_spd)
- *pulse_str;
- float ctrl = (map(
- d,
- 0, dimY/2, 0, 1) +
- t * 0.3 + sin(t*0.5)*0.1)%1;
- con.write(x, y,
- floor(map(ctrl, 0, 1, 0, 4)));
- con.writeCol(x, y,
- floor(map(ctrl, 0, 1, 0, 5)));
- }
- }
- }
- void lines_() {
- if ( frameCount % floor(1+abs(sin(t)*100)) == 0 ) {
- int count = floor(random(1, 7));
- boolean vert = random(1) > 0.5;
- for ( int i = 0; i < count; ++i ) {
- line_(
- floor(random(vert?dimY:dimX)),
- vert
- );
- }
- }
- }
- color[][] pals = {
- {
- color(32, 17, 72),
- color(32, 17, 162),
- color(255, 52, 178),
- color(0, 204, 254),
- color(85, 231, 255)
- },
- {
- color(140, 30, 255),
- color(255, 41, 117),
- color(242, 34, 255),
- color(255, 144, 31),
- color(255, 211, 25)
- }
- };
- void color_reset() {
- pal = pals[floor(random(2))];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement