Permalink
Browse files

support for y>f(x)

  • Loading branch information...
1 parent a54de9d commit 2d3e139a6d0abec38a5a77a20b28fe95f6211426 Anthony F committed Jun 18, 2011
Showing with 22 additions and 7 deletions.
  1. +22 −7 main.js
View
@@ -42,12 +42,11 @@ function compile(n){
eq=eq.simplify();
//Functions of x
-
var funcs=[];
-
+
//Functions of y
var yfuncs=[];
-
+
//Functions of theta
var tfuncs=[];
@@ -64,8 +63,11 @@ function compile(n){
var changed=[];
if(eq===undefined){
- }
- else if(eq.type==eqtype.equality){
+ }else if(eq.type==eqtype.equality || eq.type==eqtype.lessthan || eq.type==eqtype.greaterthan){
+ if(eq.type==eqtype.lessthan || eq.type==eqtype.greaterthan){
+ eq[1]=[eq[1]].setType(eq.type);
+ }
+
if(typeof eq[0]=="string"){
if(eq[0]=="y"){
//y=f(x)
@@ -150,7 +152,11 @@ function compile(n){
var fn=funcs[i].simplify();
//Get javascript expression.
- var jsc=fn.getString(0,true);
+ if(fn.type==eqtype.lessthan || fn.type==eqtype.greaterthan){
+ var jsc=fn[0].getString(0,true);
+ }else{
+ var jsc=fn.getString(0,true);
+ }
if(first){
//ret.f=eval("("+"function(x){return "+jsc+";})");
//The first value of a multi-valued function shall be its
@@ -185,7 +191,16 @@ function compile(n){
//The loop is within the function because calling a function is too slow in javascript (last time I checked)
//Plot each point: (jsc is the expression generated by CAS)
builder+="for(var x=boundleft;x<boundright;x+=(boundright-boundleft)/width){"+"ctx.line(x,"+jsc+");}ctx.stroke();";
- }
+ if(fn.type==eqtype.greaterthan){
+ builder+="ctx.line(boundright+2,boundtop+2);ctx.line(boundleft-2,boundtop+2);";
+ builder+="ctx.globalAlpha=0.2;ctx.fill();ctx.globalAlpha=1.0;";
+ }else if(fn.type==eqtype.lessthan){
+ builder+="ctx.line(boundright+2,boundbottom-2);ctx.line(boundleft-2,boundbottom-2);";
+ builder+="ctx.globalAlpha=0.2;ctx.fill();ctx.globalAlpha=1.0;";
+ }
+
+ builder+="ctx.stroke();";
+ }
try{
//Find stationary points:

0 comments on commit 2d3e139

Please sign in to comment.