Skip to content

alvov/consolefun

Repository files navigation

ConsoleFun

ConsoleFun provides a tool for perfoming console output at a certain time.
It is made just for fun, no practical usage, sorry.

Simple start

First, link ConsoleFun script to the page:

<script src="consolefun.js"></script>

The ConsoleFun object accepts map object as a parameter. The example of valid map object:

var map = [
		{ l: 'console', t: 0, e: 'inline' },
		{ l: 'log', t: 1000 },
		{ l: 'me', t: 2000, e : '/inline uppercase' }
	];

Here l stands for lexeme to be printed, t stands for time in seconds since launch, at which the lexeme will be printed, and e stands for output effects.
Note: closing tag for an effect being put on the line means, that the effect won't work since the current lexeme.
In our example this means that inline effect will be appended to lexemes console and log, but not me.

Now create the instance of ConsoleFun with map as a parameter:

var cf = new ConsoleFun( map );

Now you can perform:

cf.launch();
// or
cf.pause();
// and
cf.lag(); //for timer shifting

As simple as that.

Built-in effects

ConsoleFun contains several built-in effects:

EffectHas closing tagDescription
inlineyesperforms output in one line
inline_backyesperforms right-to-left output in one line
stepyesperforms 'staircase' output
step_backyesperforms right-to-left 'staircase' output
betweenyesputs characters of the current lexeme between characters of the previous lexeme
breakyesinserts the current lexeme in the middle of the previous lexeme
stackyessimilar to 'inline' but with no spaces between words
uppercasenooutputs lexeme in upper case
errornouses `console.error` output method instead of `console.log`
tableyesuses `console.table` output method instead of `console.log`
noclearnoprevents console clearing on next step

Custom effects

You can create your own custom effects and link them to your project by following these steps:

  1. Create a function, that returns a plain object with methods go and off.

    var customEffect = function(){
    	return {
    		'go': function( state ){
    			//...
    		},
    		'off': function(){
    			//...
    		}
    	}
    }
    

    Method go accepts state object, which contains information about the current step. For example, state.lexeme contains an array of current lexemes.
    Method off doesn't accept any arguments, and is optional.

    This is how a custom effect for lexeme output in lower case could look like:

    var lowercase = function(){
    		return {
    			'go': function( state ){
    				for ( var i = 0, l = state.lexeme.length; i < l; i++ ){
    					state.lexeme[i] = state.lexeme[i].toLowerCase();
    				}
    			}
    		}
    	};
    
  2. Now that you have your customEffect function, attach it to global ConsoleFunEffects object like this:

    if ( window.ConsoleFunEffects ) {
    	window.ConsoleFunEffects['customEffect'] = customEffect;
    } else {
    	window.ConsoleFunEffects = { 'customEffect': customEffect };
    }
    
  3. From now on you can use your customEffect effect in the map object:

    var map = [
    	{ l: 'apply custom effect to me', t: 1000, e: 'customEffect' }
    ];
    

About

Various console logging synchronized with music

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published