Giter VIP home page Giter VIP logo

consolefun's Introduction

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' }
    ];
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.