Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final int width = 600;
- final int height = 600;
- final int numframes = 101;
- color[] line = new color[ 600 ];
- float[] offset = new float[ 600 ];
- int c = 0;
- int framenum = 0;
- PImage[] frames = new PImage[ numframes ];
- PImage bg;
- boolean running = true;
- boolean background = true;
- boolean grain = false;
- boolean scan = false;
- boolean clear = false;
- int flicker = 0;
- void setup() {
- size( width, height );
- frameRate( 20 );
- for ( int i = 0; i < numframes; i++ ) {
- String framename = "" + i;
- int r = ( 4 - ( "" + i ).length() );
- for ( int l = 0; l < r; l++ ) {
- framename = "0" + framename;
- }
- frames[ i ] = loadImage( framename + ".png" );
- }
- bg = loadImage( "test.png" );
- }
- void draw() {
- c++;
- if ( running ) {
- framenum++;
- framenum %= numframes;
- }
- background( 50 );
- tint(255, 128);
- if (background) image( bg, -201, -30 );
- noTint();
- image( frames[framenum], 0, 80 );
- if ( !running ) {
- fill( 130, 0, 0 );
- rect( 520, 20, 20, 50 );
- rect( 560, 20, 20, 50 );
- }
- if ( clear ) {
- for ( int i = 0; i < offset.length; i++ )
- offset[ i ] = 0;
- }
- int f = 5;
- int g = 8;
- if ( random( 1 ) > 0.98 )
- flicker = 10;
- if ( flicker > 0 ) {
- f = 20;
- g = 50;
- flicker--;
- }
- for ( int y = 0; y < height; y++ ) {
- if ( scan ) scanlines( y, c );
- for ( int x = 0; x < width; x++ ) {
- line[ x ] = get( x, y );
- }
- if ( !clear) yFlickLine( y, c, f, g );
- for ( int x = 0; x < width; x++ ) {
- set( x + int( offset[ y ] ), y, line[ x ] );
- }
- }
- if ( grain ) grain( 30 );
- }
- void keyPressed() {
- if ( key == ' ' )
- running = !running;
- if ( key == 'b' || key == 'B' )
- background = !background;
- if ( key == 'f' || key == 'F' )
- clear = !clear;
- if ( key == 'g' || key == 'G' )
- grain = !grain;
- if ( key == 's' || key == 'S' )
- scan = !scan;
- }
- // ACTUAL GRAPHICS CODE BELOW //
- void scanlines( int y, int count ) {
- float s = sin( y / 20.0 * random( 0.95, 1.05 ) + c / 5.0 );
- if ( s < 0.4 )
- return;
- s += 0.2;
- s *= 60;
- for( int x = 0; x < width; x++ ) {
- color a = get( x, y );
- float red = min( 255, red( a ) + s * 0.3 );
- float green = min( 255, green( a ) + s * 0.5 );
- float blue = min( 255, blue( a) + s );
- a = color( red, green, blue );
- set( x, y + int( x / 80 + random( 5 ) ), a );
- }
- }
- void yFlickLine( int y, int count, int distort, int max ) {
- offset[ y ] += random( -distort, distort );
- if ( abs( offset[ y ] ) > max )
- offset[ y ] /= 1.3;
- offset[ y ] += sin( y * 3 + count ) * 50 / max;
- }
- void grain( int add ) {
- for ( int x = 0; x < width; x++ )
- for ( int y = 0; y < height; y++ ) {
- color a = get( x, y );
- float red = red( a ) + random( add );
- float green = green( a ) + random( add );
- float blue = blue( a ) + random( add );
- a = color( red, green, blue );
- set( x, y, a );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement