Skip to content

Commit

Permalink
gallery-2012.01.04-22-09 jafl gallery-mathcanvas
Browse files Browse the repository at this point in the history
  • Loading branch information
YUI Builder committed Jan 4, 2012
1 parent 03295a9 commit 7082448
Show file tree
Hide file tree
Showing 45 changed files with 3,674 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/gallery-mathcanvas/assets/gallery-mathcanvas-core.css
@@ -0,0 +1,10 @@
.keyboard {position:fixed;width:98%;max-width:400px;bottom:0;text-align:center;background-color:#666;border-top-left-radius:5px;border-top-right-radius:5px;padding:2px;}
.keyboard p.last {margin-bottom:0;}
.keyboard button {height:30px;border-radius:5px;border:1px solid #444;min-width:28px;width:10%;background-color:#EEE;box-shadow:2px 2px #222;}
.keyboard-hide {float:left;}
.keyboard-eval {float:left;margin-left:10px;}
.keyboard-expand {float:right;}
.keyboard-delete {float:right;margin-left:15px;}
.keyboard-func,
.keyboard-const {width:100px;}
.keyboard-const {margin-top:5px;}
Empty file.
10 changes: 10 additions & 0 deletions src/gallery-mathcanvas/build.properties
@@ -0,0 +1,10 @@
builddir=../../../builder/componentbuild
component=gallery-mathcanvas
component.jsfiles=RectList.js,MathFunction.js,Value.js,Variable.js,Pi.js,E.js,I.js,FunctionWithArgs.js,Negate.js,Sum.js,Product.js,Quotient.js,Magnitude.js,Phase.js,Conjugate.js,Rotate.js,RealPart.js,ImaginaryPart.js,Min.js,Max.js,SquareRoot.js,Exponential.js,Logarithm.js,NaturalLog.js,Sine.js,Cosine.js,Tangent.js,Arcsine.js,Arccosine.js,Arctangent.js,Arctangent2.js,HyperbolicCosine.js,HyperbolicSine.js,HyperbolicTangent.js,InverseHyperbolicCosine.js,InverseHyperbolicSine.js,InverseHyperbolicTangent.js,MathParser.js,MathCanvas.js
component.requires=widget,collection,node-screen,gallery-complexnumber,gallery-canvas,gallery-node-optimizations,anim-base,array-extras
#component.supersedes=
component.optional=
component.skinnable=true

# auto-generated MathParser is not clean
lint.skip=true
6 changes: 6 additions & 0 deletions src/gallery-mathcanvas/build.xml
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Canvas" default="local">
<description>Canvas build file</description>
<property file="build.properties" />
<import file="${builddir}/3.x/bootstrap.xml" />
</project>
174 changes: 174 additions & 0 deletions src/gallery-mathcanvas/jison/MathParser.jison
@@ -0,0 +1,174 @@
/* node `which jison` MathParser.jison; mv MathParser.js ../js/ */

/* http://zaach.github.com/jison/docs/ */

/* lexical grammar */
%lex

%%
"0"[xX][0-9a-fA-F]+ return 'NUMBER'; /* hex */
[0-9]+[eE][-+]?[0-9]+ return 'NUMBER'; /* integer w/ exponent */
[0-9]+"."([0-9]+)?([eE][-+]?[0-9]+)? return 'NUMBER'; /* decimal w/ exponent */
([0-9]+)?"."[0-9]+([eE][-+]?[0-9]+)? return 'NUMBER'; /* decimal w/ exponent */
[1-9][0-9]* return 'NUMBER'; /* decimal integer */
"0" return 'NUMBER'; /* zero */

"pi" return 'PI';
"\u03c0" return 'PI';
"e" return 'E';
"i" return 'I';

"*" return '*';
"/" return '/';
"-" return '-';
"+" return '+';
"^" return '^';
"(" return '(';
")" return ')';

"," return ',';
"re" return 'RE';
"im" return 'IM';
"abs" return 'ABS';
"phase" return 'PHASE';
"conjugate" return 'CONJUGATE';
"rotate" return 'ROTATE';
"max" return 'MAX';
"min" return 'MIN';
"sqrt" return 'SQRT';
"log" return 'LOG';
"log2" return 'LOG2';
"log10" return 'LOG10';
"ln" return 'LN';
"arcsin" return 'ARCSIN';
"arccos" return 'ARCCOS';
"arctan" return 'ARCTAN';
"arctan2" return 'ARCTAN2';
"sin" return 'SIN';
"cos" return 'COS';
"tan" return 'TAN';
"sinh" return 'SINH';
"cosh" return 'COSH';
"tanh" return 'TANH';
"arcsinh" return 'ARCSINH';
"arccosh" return 'ARCCOSH';
"arctanh" return 'ARCTANH';

[^-*/+^(),\s0-9][^-*/+^(),\s]* return 'VARIABLE';

\s+ /* skip whitespace */
<<EOF>> return 'EOF';

/lex

/* operator associations and precedence */

%left '+' '-'
%left '*' '/'
%left '^'
%left UMINUS

%start expression

%% /* language grammar */

expression
: e EOF
{return $1;}
;

e
: NUMBER
{$$ = new yy.MathFunction.Value(yytext);}
| E
{$$ = new yy.MathFunction.E();}
| PI
{$$ = new yy.MathFunction.Pi();}
| I
{$$ = new yy.MathFunction.I();}
| VARIABLE
{$$ = new yy.MathFunction.Variable(yytext);}

| '(' e ')'
{$$ = $2;}

| e '+' e
{$$ = yy.MathFunction.updateSum($1, $3);}
| e '-' e
{$$ = yy.MathFunction.updateSum($1, new yy.MathFunction.Negate($3));}
| e '*' e
{$$ = yy.MathFunction.updateProduct($1, $3);}
| e '/' e
{$$ = new yy.MathFunction.Quotient($1, $3);}
| e '^' e
{$$ = new yy.MathFunction.Exponential($1, $3);}
| '-' e %prec UMINUS
{$$ = new yy.MathFunction.Negate($2);}

| ABS '(' e ')'
{$$ = new yy.MathFunction.Magnitude($3);}
| PHASE '(' e ')'
{$$ = new yy.MathFunction.Phase($3);}
| CONJUGATE '(' e ')'
{$$ = new yy.MathFunction.Conjugate($3);}
| ROTATE '(' arglist ')'
{$$ = new yy.MathFunction.Rotate($3);}
| RE '(' e ')'
{$$ = new yy.MathFunction.RealPart($3);}
| IM '(' e ')'
{$$ = new yy.MathFunction.ImaginaryPart($3);}

| MIN '(' arglist ')'
{$$ = new yy.MathFunction.Min($3);}
| MAX '(' arglist ')'
{$$ = new yy.MathFunction.Max($3);}

| SQRT '(' e ')'
{$$ = new yy.MathFunction.SquareRoot($3);}

| LOG '(' arglist ')'
{$$ = new yy.MathFunction.Logarithm($3);}
| LOG2 '(' e ')'
{$$ = new yy.MathFunction.Logarithm(new yy.MathFunction.Value(2), $3);}
| LOG10 '(' e ')'
{$$ = new yy.MathFunction.Logarithm(new yy.MathFunction.Value(10), $3);}
| LN '(' e ')'
{$$ = new yy.MathFunction.NaturalLog($3);}

| ARCSIN '(' e ')'
{$$ = new yy.MathFunction.Arcsine($3);}
| ARCCOS '(' e ')'
{$$ = new yy.MathFunction.Arccosine($3);}
| ARCTAN '(' e ')'
{$$ = new yy.MathFunction.Arctangent($3);}
| ARCTAN2 '(' arglist ')'
{$$ = new yy.MathFunction.Arctangent2($3);}

| SIN '(' e ')'
{$$ = new yy.MathFunction.Sine($3);}
| COS '(' e ')'
{$$ = new yy.MathFunction.Cosine($3);}
| TAN '(' e ')'
{$$ = new yy.MathFunction.Tangent($3);}

| SINH '(' e ')'
{$$ = new yy.MathFunction.HyperbolicSine($3);}
| COSH '(' e ')'
{$$ = new yy.MathFunction.HyperbolicCosine($3);}
| TANH '(' e ')'
{$$ = new yy.MathFunction.HyperbolicTangent($3);}

| ARCSINH '(' e ')'
{$$ = new yy.MathFunction.InverseHyperbolicSine($3);}
| ARCCOSH '(' e ')'
{$$ = new yy.MathFunction.InverseHyperbolicCosine($3);}
| ARCTANH '(' e ')'
{$$ = new yy.MathFunction.InverseHyperbolicTangent($3);}
;

arglist
: e
{$$ = [ $1 ];}
| arglist ',' e
{$$ = $1.concat($3);}
;
26 changes: 26 additions & 0 deletions src/gallery-mathcanvas/js/Arccosine.js
@@ -0,0 +1,26 @@
/**********************************************************************
* <p>Inverse trigonometric cosine.</p>
*
* @namespace MathFunction
* @class Arccosine
* @extends MathFunction.FunctionWithArgs
* @constructor
* @param f {MathFunction}
*/

function MathArccosine(
/* MathFunction */ f)
{
MathArccosine.superclass.constructor.call(this, "arccos", f);
}

Y.extend(MathArccosine, MathFunctionWithArgs,
{
evaluate: function(
/* map */ var_list)
{
return Math.acos(this.args[0].evaluate(var_list));
}
});

MathFunction.Arccosine = MathArccosine;
26 changes: 26 additions & 0 deletions src/gallery-mathcanvas/js/Arcsine.js
@@ -0,0 +1,26 @@
/**********************************************************************
* <p>Inverse trigonometric sine.</p>
*
* @namespace MathFunction
* @class Arcsine
* @extends MathFunction.FunctionWithArgs
* @constructor
* @param f {MathFunction}
*/

function MathArcsine(
/* MathFunction */ f)
{
MathArcsine.superclass.constructor.call(this, "arcsin", f);
}

Y.extend(MathArcsine, MathFunctionWithArgs,
{
evaluate: function(
/* map */ var_list)
{
return Math.asin(this.args[0].evaluate(var_list));
}
});

MathFunction.Arcsine = MathArcsine;
26 changes: 26 additions & 0 deletions src/gallery-mathcanvas/js/Arctangent.js
@@ -0,0 +1,26 @@
/**********************************************************************
* <p>Inverse trigonometric cosine.</p>
*
* @namespace MathFunction
* @class Arctangent
* @extends MathFunction.FunctionWithArgs
* @constructor
* @param f {MathFunction}
*/

function MathArctangent(
/* MathFunction */ f)
{
MathArctangent.superclass.constructor.call(this, "arctan", f);
}

Y.extend(MathArctangent, MathFunctionWithArgs,
{
evaluate: function(
/* map */ var_list)
{
return Math.atan(this.args[0].evaluate(var_list));
}
});

MathFunction.Arctangent = MathArctangent;
29 changes: 29 additions & 0 deletions src/gallery-mathcanvas/js/Arctangent2.js
@@ -0,0 +1,29 @@
/**********************************************************************
* <p>Inverse trigonometric cosine.</p>
*
* @namespace MathFunction
* @class Arctangent2
* @extends MathFunction.FunctionWithArgs
* @constructor
* @param y {MathFunction}
* @param x {MathFunction}
*/

function MathArctangent2(
/* MathFunction */ y,
/* MathFunction */ x)
{
MathArctangent2.superclass.constructor.call(this, "arctan2", y, x);
}

Y.extend(MathArctangent2, MathFunctionWithArgs,
{
evaluate: function(
/* map */ var_list)
{
return Math.atan2(this.args[0].evaluate(var_list),
this.args[1].evaluate(var_list));
}
});

MathFunction.Arctangent2 = MathArctangent2;
55 changes: 55 additions & 0 deletions src/gallery-mathcanvas/js/Conjugate.js
@@ -0,0 +1,55 @@
/**********************************************************************
* <p>Conjugate of a complex number.</p>
*
* @namespace MathFunction
* @class Conjugate
* @extends MathFunction.FunctionWithArgs
* @constructor
* @param f {MathFunction}
*/

function MathConjugate(
/* MathFunction */ f)
{
MathConjugate.superclass.constructor.call(this, "conjugate", f);
}

Y.extend(MathConjugate, MathFunctionWithArgs,
{
evaluate: function(
/* map */ var_list)
{
return Y.ComplexMath.conjugate(this.args[0].evaluate(var_list));
},

prepareToRender: function(
/* Context2d */ context,
/* point */ top_left,
/* percentage */ font_size,
/* RectList */ rect_list)
{
var bar_height = context.getHorizontalBarHeight();

var arg_top_left = Y.clone(top_left, true);
arg_top_left.y += bar_height;

var arg_index = this.args[0].prepareToRender(context, arg_top_left, font_size, rect_list);
var arg_info = rect_list.get(arg_index);

var r = Y.clone(arg_info.rect, true);
r.top -= bar_height;

return rect_list.add(r, arg_info.midline, font_size, this);
},

render: function(
/* Context2d */ context,
/* RectList */ rect_list)
{
var info = rect_list.find(this);
context.drawHorizontalBar(info.rect);
this.args[0].render(context, rect_list);
}
});

MathFunction.Conjugate = MathConjugate;
26 changes: 26 additions & 0 deletions src/gallery-mathcanvas/js/Cosine.js
@@ -0,0 +1,26 @@
/**********************************************************************
* <p>Trigonometric cosine.</p>
*
* @namespace MathFunction
* @class Cosine
* @extends MathFunction.FunctionWithArgs
* @constructor
* @param f {MathFunction}
*/

function MathCosine(
/* MathFunction */ f)
{
MathCosine.superclass.constructor.call(this, "cos", f);
}

Y.extend(MathCosine, MathFunctionWithArgs,
{
evaluate: function(
/* map */ var_list)
{
return Y.ComplexMath.cos(this.args[0].evaluate(var_list));
}
});

MathFunction.Cosine = MathCosine;

0 comments on commit 7082448

Please sign in to comment.