Based Processing realization of "The Matrix" Code rain

He came, he came, junior high school read "The Matrix", was absolutely amazing, from the point of view taken, the effects of which today's leading domestic movie special effects a few blocks, but also 20 young thing. Which most impressed me is that the code rain effects, remember ah, now engaged in a great programmer because of rain read the code, the code is really feeling anything. Ha ha ha! !
Movie special effects:
Here Insert Picture Description
Here Insert Picture Description
Processing effects:
Here Insert Picture Description
the source code:

static final int C_MAX_LIT=0xEE;
static final int C_NORMAL_LIT=0x66;
static final int C_BASIC_LIT=0x33;
static final int C_GRADIENT_LIT=0x11;

int pbRowCount=0;
int pbCharSetCount=0;
float pbTextGrid=0f;

String[] pbCharSet;
EcSingleLine[] pbLines;

void setup(){  
  //[ use this instead ]::fullScreen(P2D);
  size(500,500);
  frameRate(16);noStroke();
  textAlign(LEFT,TOP);
  //[ change size if necessary]::textSize(22);
  
  pbTextGrid=textAscent()+textDescent();
  pbRowCount=ceil(height/pbTextGrid);
  
  int lpColumnCount=ceil(width/pbTextGrid);
  pbLines=new EcSingleLine[lpColumnCount];
  for(int i=0,s=pbLines.length;i<s;i++){
    pbLines[i]=new EcSingleLine();
    pbLines[i].cmX=i*ceil(pbTextGrid);
    pbLines[i].cmDripHead=ceil(random(1,pbRowCount));
  }//..~
  
  pbCharSetCount=0x79-0x21;//..see the ascii table!!
  pbCharSet=new String[pbCharSetCount];
  for(int i=0,s=pbCharSet.length;i<s;i++){
    pbCharSet[i]=new StringBuilder().append((char)(i+0x21)).toString();
  } 
}

void draw(){
  background(0);
  
  for(EcSingleLine it:pbLines){
    it.ccUpdate();
    if(random(1f)<0.2){
      it.ccDrip();
    }
  } 
}

void keyPressed(){switch(key){
  case 'f':println(frameRate);break;
  case 'q':exit();break;
  default:break;
}}

class EcSingleLine{  
  int cmX=0;
  int cmDripHead=0;
  boolean cmDripping;
  
  void ccUpdate(){
    cmDripping=cmDripHead<(pbRowCount*2);
    cmDripHead+=cmDripping?1:0;
    
    int lpGreen;
    for(int i=0;i<pbRowCount;i++){
      if(i<cmDripHead){
        lpGreen=C_MAX_LIT-(C_GRADIENT_LIT*(cmDripHead-i));
        lpGreen=constrain(lpGreen,C_NORMAL_LIT,C_MAX_LIT);
        fill(C_BASIC_LIT,lpGreen,C_BASIC_LIT);
      }else{
        fill(C_BASIC_LIT,C_NORMAL_LIT,C_BASIC_LIT);
      }//..?
      
      text(
        pbCharSet[ceil(random(0,pbCharSetCount-1))],
        cmX,
        i*pbTextGrid
      );      
    }
  } 
  void ccDrip(){if(!cmDripping){cmDripHead=0;}}
}
Published 69 original articles · won praise 37 · views 180 000 +

Guess you like

Origin blog.csdn.net/xi_gua_gua/article/details/105206687