Skip to content

Commit

Permalink
Merge branch 'master' of github.com:0xdata/h2o
Browse files Browse the repository at this point in the history
automerge
  • Loading branch information
tomasnykodym committed Feb 9, 2013
2 parents da5b1d3 + b674ef2 commit b8410a9
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/resources/h2o/console.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<div class='container' style='margin: 0px auto'>
<link rel="stylesheet" type="text/css" href="h2o/console.css">
<div id="console"></div>

<script src="jquery/jqconsole.min.js" type="text/javascript" charset="utf-8"></script>
<script>

<link rel="stylesheet" type="text/css" href="jquery/jquery.matrix.css" />
<script type="text/javascript" src="jquery/jquery.matrix.js"></script>

<script type="text/javascript">
$(function () {
var jqconsole = $('#console').jqconsole('Welcome to the H\u2082O interactive repl\n', 'H\u2082O> ');
var toFixed = function(n) {
Expand All @@ -25,6 +30,11 @@
if( input == '?' || input == 'help' ) {
%HELP
startPrompt();
} else if( input == 'h2o-matrix' ) {
var c = $('#console')
c.matrix({'height':c.height(),'width':c.width()})
jqconsole.Write("There is no spoon\n", 'jqconsole-output');
startPrompt();
} else if( input ) {
$.get('Exec',
{ expression: input, destination_key : 'Result_'+(resultNumber++)+'.hex', escape_nan : true },
Expand Down
30 changes: 30 additions & 0 deletions lib/resources/jquery/jquery.matrix.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.ui-matrix {
position: relative;
border: 1px solid #080;
background: black;
overflow: hidden;
font-family: "Courier New",Courier,monospace;
margin: 0;
}

.ui-matrix-string {
color: #080;
text-shadow: #0f0 0 0 6px,
#050 0 -6px 12px;
position: absolute;
}

.ui-matrix-string-size0 { font-size: 24px; line-height: 24px; z-index: 100; opacity: 1.0; }
.ui-matrix-string-size1 { font-size: 21px; line-height: 21px; z-index: 90; opacity: .75; }
.ui-matrix-string-size2 { font-size: 18px; line-height: 18px; z-index: 80; opacity: .50; }
.ui-matrix-string-size3 { font-size: 15px; line-height: 15px; z-index: 70; opacity: .25; }

.ui-matrix-string span {
display: block;
}

.ui-matrix-string .ui-matrix-string-first {
font-weight: bold;
color: #3f3;
}

126 changes: 126 additions & 0 deletions lib/resources/jquery/jquery.matrix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**
* jMatrix
* http://code.google.com/p/jquery-matrix/
*
* Copyright (c) 2009 Manuel Strehl
* Licensed under the MIT license
*
* $Id$
*/
(function ($) {

/**
* Return a random integer
*/
var rand = function (max) {
return max? Math.round (Math.random () * max) : 0;
};

/**
* Extends jQuery objects with the matrix method
*/
$.fn.matrix = function (options) {

/**
* Settings get defaulted with values from $.fn.matrix.settings
*/
var settings = $.extend ({}, $.fn.matrix.settings, options);

/**
* Add string data to a single matrix string
*/
var addData = function ($element, initelement, n, data, randset, matrix_height) {
if ($element.length) { // could be, that the element is deleted meanwhile
if (n % settings.charstep == 1) { // every charstep'th iteration adds a new character
var add = document.createElement ("span");
add.appendChild (document.createTextNode (data.substr (n%data.length, 1)));
$(add).animate ({'opacity':'0'}, randset);
initelement.parentNode.insertBefore (add, initelement);
}
initelement.firstChild.nodeValue = data.substr (n%data.length, 1);
if ($element.position ().top < matrix_height + 10) {
window.setTimeout (function () { addData ($element, initelement, n+1, data, randset, matrix_height); }, 50);
}
}
};

/**
* Add a new matrix string (one vertically floating text stripe)
*/
var addString = function ($matrix, matrix_width, matrix_height, string_count) {
var size = rand (3); // the size of the string (0: large, foreground; 3: small, background)
var seed = 20-3*size;
var pos = seed*rand (matrix_width/seed); // the position from the left border (foreground is wider apart)
var speed = settings.speedSeed + rand (settings.speedSeed)
+ (3-size) * rand (settings.speedSeed); // the downwards speed (foreground is faster)

// The string to append:
var span = document.createElement ("span");
var init = document.createElement ("span");
span.setAttribute ("class", 'ui-matrix-string ui-matrix-string-size'+size);
span.style.left = pos+'px';
span.style.top = "-"+(50+rand (matrix_height))+'px';
init.setAttribute ("class", "ui-matrix-string-first");
init.appendChild (document.createTextNode ("0"));
span.appendChild (init);
var $mstring = $(span);

$matrix.append ($mstring);
// move it:
$mstring.animate ({"top": matrix_height + 10}, speed, function () {
this.parentNode.removeChild (this);
});

addData ($mstring, init, 0, settings.data[rand(settings.data.length-1)], settings.fadingSeed + rand (settings.fadingSeed), matrix_height);

if (string_count < settings.number) {
// add the next string here. Gives a nicer, cascading result than a while loop in the main body
string_count++;
window.setTimeout (function () { addString ($matrix, matrix_width, matrix_height, string_count); }, settings.distanceRoot + rand (settings.distanceSeed));
}
};

// don't break the chain
return this.each (function () {
var $matrix = $(this);
$matrix.addClass ("ui-matrix");
$matrix.height (settings.height);
var matrix_height = settings.height;
$matrix.width (settings.width);
var matrix_width = settings.width;

addString ($matrix, matrix_width, matrix_height, 0);
});

};

/**
* Publicly available settings for jMatrix
*
* data: array of strings that are used for the matrix effect
* number: number of strings generated per matrix (more will lead to a
* significant performance impact)
*/
$.fn.matrix.settings = {
'data': [
"H2O: the data is the system",
"H2O: make hadoop do math",
"案ずるより産むが易し",
"虎穴に入らずんば虎子を得ず",
"猿も木から落ちる",
"井の中の蛙大海を知らず",
"二兎を追う者は一兎をも得ず",
"門前の小僧習わぬ経を読む",
"脳ある鷹は爪を隠す"
],
'number': 100,
'charstep': 7,
'speedSeed': 10000,
'fadingSeed': 8000,
'distanceRoot': 100,
'distanceSeed': 500,
'width': 500,
'height': 500
};

})(jQuery);

0 comments on commit b8410a9

Please sign in to comment.