/***
|''Name:''|MathSVGPlugin|
|''Description:''|This plugin translates a subset of the LaTeX math notation to MathML with a customisable image fallback when MathML is not supported. It also provides an easy way to produce mathematical SVG graphics with dynamical features and animation.|
|''Version:''|1.1|
|''Date:''|2009-05-05|
|''Source:''|http://www.math.ist.utl.pt/~psoares/mathsvg.html|
|''Author:''|Paulo Soares|
|''License:''|[[GNU Lesser General Public License|http://www.gnu.org/licences/lgpl.html]]|
|''~CoreVersion:''|2.5.0|
!Original copyright notice
{{{
ASCIIMathML.js
==============
Version 2.1 Oct 8, 2008, (c) Peter Jipsen http://www.chapman.edu/~jipsen
This version extends ASCIIMathML.js with LaTeXMathML.js and ASCIIsvg.js.
Latest version at http://www.chapman.edu/~jipsen/mathml/ASCIIMathML.js
If you use it on a webpage, please send the URL to jipsen@chapman.edu
The LaTeXMathML modifications were made by Douglas Woodall, June 2006.
(for details see header on the LaTeXMathML part in middle of file)
Extensive clean-up and improvements by Paulo Soares, Oct 2007.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
(at http://www.gnu.org/licences/lgpl.html) for more details.
}}}
!~MathSVG code (minified)
***/
//{{{
Math.sec=function(a){return 1/Math.cos(a)};Math.csc=function(a){return 1/Math.sin(a)};Math.cot=function(a){return 1/Math.tan(a)};Math.asec=function(a){return Math.acos(1/a)};Math.acsc=function(a){return Math.asin(1/a)};Math.acot=function(a){return Math.atan(1/a)};Math.sinh=function(a){return(Math.exp(a)-Math.exp(-a))/2};Math.cosh=function(a){return(Math.exp(a)+Math.exp(-a))/2};Math.tanh=function(a){return(Math.exp(a)-Math.exp(-a))/(Math.exp(a)+Math.exp(-a))};Math.sech=function(a){return 1/Math.cosh(a)};Math.csch=function(a){return 1/Math.sinh(a)};Math.coth=function(a){return 1/Math.tanh(a)};Math.asinh=function(a){return Math.log(a+Math.sqrt(a*a+1))};Math.acosh=function(a){return Math.log(a+Math.sqrt(a*a-1))};Math.atanh=function(a){return Math.log((1+a)/(1-a))/2};Math.sech=function(a){return 1/Math.cosh(a)};Math.csch=function(a){return 1/Math.sinh(a)};Math.coth=function(a){return 1/Math.tanh(a)};Math.asech=function(a){return Math.acosh(1/a)};Math.acsch=function(a){return Math.asinh(1/a)};Math.acoth=function(a){return Math.atanh(1/a)};Math.sign=function(a){return(a===0?0:(a<0?-1:1))};Math.step=function(a,c,b){return(a<0?(b?b:0):(c?c:1))};Math.root=function(a,b){return Math.pow(a,1/b)};Math.factorial=function(b){if(b===0){return 1}if(b<0){if((b%1)===0){return}if(b>-1){return Math.factorial(b+1)/(b+1)}return -Math.PI/(Math.factorial(-1-b)*Math.sin(Math.PI*b))}var a=b;if((b%1)===0){while(b>1){b=b-1;a=a*b}}else{a=Math.exp((b+0.5)*Math.log(b+1)-b-b*(0.1121105+b*0.08106103)/(1.452342+b*(2.410858+b)))}return a};Math.Gamma=function(a){return Math.factorial(a-1)};Math.Beta=function(a,b){return Math.Gamma(a)*Math.Gamma(b)/Math.Gamma(a+b)};Math.C=function(a,b){var c=1/((a+1)*Math.Beta(b+1,a-b+1));return c};Math.truncate=function(a,c){var b=c||0;return Math.floor(a*Math.pow(10,b))/Math.pow(10,b)};Math.randomString=function(b,d){var c,e="";var a=b.length-1;for(c=0;c<d;c++){e+=b.substr(Math.runif(0,a),1)}return e};Math.runif=function(d,c,f){var e=f||0;return Math.truncate((c+Math.pow(10,-e)-d)*Math.random()+d,e)};Math.rnormal=function(a,b){a=a||0;b=b||1;var d=0,c=0;while(d*c===0){d=Math.random();c=Math.random()}return b*(Math.sqrt(-2*Math.log(d))*Math.cos(2*Math.PI*c))+a};Math.range=function(e,a,d){if((a-e)*d<=0){return}var c,b=[];for(c=e;c<=a;c+=d){b[b.length]=c}return b};var MSVG=function(m){var h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";var t=["\uD835\uDC9C","\u212C","\uD835\uDC9E","\uD835\uDC9F","\u2130","\u2131","\uD835\uDCA2","\u210B","\u2110","\uD835\uDCA5","\uD835\uDCA6","\u2112","\u2133","\uD835\uDCA9","\uD835\uDCAA","\uD835\uDCAB","\uD835\uDCAC","\u211B","\uD835\uDCAE","\uD835\uDCAF","\uD835\uDCB0","\uD835\uDCB1","\uD835\uDCB2","\uD835\uDCB3","\uD835\uDCB4","\uD835\uDCB5","\uD835\uDCB6","\uD835\uDCB7","\uD835\uDCB8","\uD835\uDCB9","\u212F","\uD835\uDCBB","\u210A","\uD835\uDCBD","\uD835\uDCBE","\uD835\uDCBF","\uD835\uDCC0","\uD835\uDCC1","\uD835\uDCC2","\uD835\uDCC3","\u2134","\uD835\uDCC5","\uD835\uDCC6","\uD835\uDCC7","\uD835\uDCC8","\uD835\uDCC9","\uD835\uDCCA","\uD835\uDCCB","\uD835\uDCCC","\uD835\uDCCD","\uD835\uDCCE","\uD835\uDCCF"];var D=["\uD835\uDD04","\uD835\uDD05","\u212D","\uD835\uDD07","\uD835\uDD08","\uD835\uDD09","\uD835\uDD0A","\u210C","\u2111","\uD835\uDD0D","\uD835\uDD0E","\uD835\uDD0F","\uD835\uDD10","\uD835\uDD11","\uD835\uDD12","\uD835\uDD13","\uD835\uDD14","\u211C","\uD835\uDD16","\uD835\uDD17","\uD835\uDD18","\uD835\uDD19","\uD835\uDD1A","\uD835\uDD1B","\uD835\uDD1C","\u2128","\uD835\uDD1E","\uD835\uDD1F","\uD835\uDD20","\uD835\uDD21","\uD835\uDD22","\uD835\uDD23","\uD835\uDD24","\uD835\uDD25","\uD835\uDD26","\uD835\uDD27","\uD835\uDD28","\uD835\uDD29","\uD835\uDD2A","\uD835\uDD2B","\uD835\uDD2C","\uD835\uDD2D","\uD835\uDD2E","\uD835\uDD2F","\uD835\uDD30","\uD835\uDD31","\uD835\uDD32","\uD835\uDD33","\uD835\uDD34","\uD835\uDD35","\uD835\uDD36","\uD835\uDD37"];var s=["\uD835\uDD38","\uD835\uDD39","\u2102","\uD835\uDD3B","\uD835\uDD3C","\uD835\uDD3D","\uD835\uDD3E","\u210D","\uD835\uDD40","\uD835\uDD41","\uD835\uDD42","\uD835\uDD43","\uD835\uDD44","\u2115","\uD835\uDD46","\u2119","\u211A","\u211D","\uD835\uDD4A","\uD835\uDD4B","\uD835\uDD4C","\uD835\uDD4D","\uD835\uDD4E","\uD835\uDD4F","\uD835\uDD50","\u2124","\uD835\uDD52","\uD835\uDD53","\uD835\uDD54","\uD835\uDD55","\uD835\uDD56","\uD835\uDD57","\uD835\uDD58","\uD835\uDD59","\uD835\uDD5A","\uD835\uDD5B","\uD835\uDD5C","\uD835\uDD5D","\uD835\uDD5E","\uD835\uDD5F","\uD835\uDD60","\uD835\uDD61","\uD835\uDD62","\uD835\uDD63","\uD835\uDD64","\uD835\uDD65","\uD835\uDD66","\uD835\uDD67","\uD835\uDD68","\uD835\uDD69","\uD835\uDD6A","\uD835\uDD6B"];var z=0,b=1,d=2,p=3,x=4,e=5,q=6,r=7,o=8,f=9,B=10,A=11,c=12,j=13,l=14;var a=[{input:"\\varepsilon",tag:"mi",output:"\u025B",ttype:z},{input:"\\varsigma",tag:"mi",output:"\u03C2",ttype:z},{input:"\\vartheta",tag:"mi",output:"\u03D1",ttype:z},{input:"\\varphi",tag:"mi",output:"\u03D5",ttype:z},{input:"\\varpi",tag:"mi",output:"\u03D6",ttype:z},{input:"\\varrho",tag:"mi",output:"\u03F1",ttype:z},{input:"\\alpha",tag:"mi",output:"\u03B1",ttype:z},{input:"\\beta",tag:"mi",output:"\u03B2",ttype:z},{input:"\\gamma",tag:"mi",output:"\u03B3",ttype:z},{input:"\\delta",tag:"mi",output:"\u03B4",ttype:z},{input:"\\epsilon",tag:"mi",output:"\u03B5",ttype:z},{input:"\\zeta",tag:"mi",output:"\u03B6",ttype:z},{input:"\\eta",tag:"mi",output:"\u03B7",ttype:z},{input:"\\theta",tag:"mi",output:"\u03B8",ttype:z},{input:"\\iota",tag:"mi",output:"\u03B9",ttype:z},{input:"\\kappa",tag:"mi",output:"\u03BA",ttype:z},{input:"\\lambda",tag:"mi",output:"\u03BB",ttype:z},{input:"\\mu",tag:"mi",output:"\u03BC",ttype:z},{input:"\\nu",tag:"mi",output:"\u03BD",ttype:z},{input:"\\xi",tag:"mi",output:"\u03BE",ttype:z},{input:"\\omicron",tag:"mi",output:"\u03BF",ttype:z},{input:"\\pi",tag:"mi",output:"\u03C0",ttype:z},{input:"\\rho",tag:"mi",output:"\u03C1",ttype:z},{input:"\\sigma",tag:"mi",output:"\u03C3",ttype:z},{input:"\\tau",tag:"mi",output:"\u03C4",ttype:z},{input:"\\upsilon",tag:"mi",output:"\u03C5",ttype:z},{input:"\\phi",tag:"mi",output:"\u03C6",ttype:z},{input:"\\chi",tag:"mi",output:"\u03C7",ttype:z},{input:"\\psi",tag:"mi",output:"\u03C8",ttype:z},{input:"\\omega",tag:"mi",output:"\u03C9",ttype:z},{input:"\\Alpha",tag:"mo",output:"\u0391",ttype:z},{input:"\\Beta",tag:"mo",output:"\u0392",ttype:z},{input:"\\Gamma",tag:"mo",output:"\u0393",ttype:z},{input:"\\Delta",tag:"mo",output:"\u0394",ttype:z},{input:"\\Epsilon",tag:"mo",output:"\u0395",ttype:z},{input:"\\Zeta",tag:"mo",output:"\u0396",ttype:z},{input:"\\Eta",tag:"mo",output:"\u0397",ttype:z},{input:"\\Theta",tag:"mo",output:"\u0398",ttype:z},{input:"\\Iota",tag:"mo",output:"\u0399",ttype:z},{input:"\\Kappa",tag:"mo",output:"\u039A",ttype:z},{input:"\\Lambda",tag:"mo",output:"\u039B",ttype:z},{input:"\\Mu",tag:"mo",output:"\u039C",ttype:z},{input:"\\Nu",tag:"mo",output:"\u039D",ttype:z},{input:"\\Xi",tag:"mo",output:"\u039E",ttype:z},{input:"\\Omicron",tag:"mo",output:"\u039F",ttype:z},{input:"\\Pi",tag:"mo",output:"\u03A0",ttype:z},{input:"\\Rho",tag:"mo",output:"\u03A1",ttype:z},{input:"\\Sigma",tag:"mo",output:"\u03A3",ttype:z},{input:"\\Tau",tag:"mo",output:"\u03A4",ttype:z},{input:"\\Upsilon",tag:"mo",output:"\u03A5",ttype:z},{input:"\\Phi",tag:"mo",output:"\u03A6",ttype:z},{input:"\\Chi",tag:"mo",output:"\u03A7",ttype:z},{input:"\\Psi",tag:"mo",output:"\u03A8",ttype:z},{input:"\\Omega",tag:"mo",output:"\u03A9",ttype:z},{input:"\\frac12",tag:"mo",output:"\u00BD",ttype:z},{input:"\\frac14",tag:"mo",output:"\u00BC",ttype:z},{input:"\\frac34",tag:"mo",output:"\u00BE",ttype:z},{input:"\\frac13",tag:"mo",output:"\u2153",ttype:z},{input:"\\frac23",tag:"mo",output:"\u2154",ttype:z},{input:"\\frac15",tag:"mo",output:"\u2155",ttype:z},{input:"\\frac25",tag:"mo",output:"\u2156",ttype:z},{input:"\\frac35",tag:"mo",output:"\u2157",ttype:z},{input:"\\frac45",tag:"mo",output:"\u2158",ttype:z},{input:"\\frac16",tag:"mo",output:"\u2159",ttype:z},{input:"\\frac56",tag:"mo",output:"\u215A",ttype:z},{input:"\\frac18",tag:"mo",output:"\u215B",ttype:z},{input:"\\frac38",tag:"mo",output:"\u215C",ttype:z},{input:"\\frac58",tag:"mo",output:"\u215D",ttype:z},{input:"\\frac78",tag:"mo",output:"\u215E",ttype:z},{input:"\\pm",tag:"mo",output:"\u00B1",ttype:z},{input:"\\mp",tag:"mo",output:"\u2213",ttype:z},{input:"\\triangleleft",tag:"mo",output:"\u22B2",ttype:z},{input:"\\triangleright",tag:"mo",output:"\u22B3",ttype:z},{input:"\\cdot",tag:"mo",output:"\u22C5",ttype:z},{input:"\\star",tag:"mo",output:"\u22C6",ttype:z},{input:"\\ast",tag:"mo",output:"\u002A",ttype:z},{input:"\\times",tag:"mo",output:"\u00D7",ttype:z},{input:"\\div",tag:"mo",output:"\u00F7",ttype:z},{input:"\\circ",tag:"mo",output:"\u2218",ttype:z},{input:"\\bullet",tag:"mo",output:"\u2022",ttype:z},{input:"\\oplus",tag:"mo",output:"\u2295",ttype:z},{input:"\\ominus",tag:"mo",output:"\u2296",ttype:z},{input:"\\otimes",tag:"mo",output:"\u2297",ttype:z},{input:"\\bigcirc",tag:"mo",output:"\u25CB",ttype:z},{input:"\\oslash",tag:"mo",output:"\u2298",ttype:z},{input:"\\odot",tag:"mo",output:"\u2299",ttype:z},{input:"\\land",tag:"mo",output:"\u2227",ttype:z},{input:"\\wedge",tag:"mo",output:"\u2227",ttype:z},{input:"\\lor",tag:"mo",output:"\u2228",ttype:z},{input:"\\vee",tag:"mo",output:"\u2228",ttype:z},{input:"\\cap",tag:"mo",output:"\u2229",ttype:z},{input:"\\cup",tag:"mo",output:"\u222A",ttype:z},{input:"\\sqcap",tag:"mo",output:"\u2293",ttype:z},{input:"\\sqcup",tag:"mo",output:"\u2294",ttype:z},{input:"\\uplus",tag:"mo",output:"\u228E",ttype:z},{input:"\\amalg",tag:"mo",output:"\u2210",ttype:z},{input:"\\bigtriangleup",tag:"mo",output:"\u25B3",ttype:z},{input:"\\bigtriangledown",tag:"mo",output:"\u25BD",ttype:z},{input:"\\dag",tag:"mo",output:"\u2020",ttype:z},{input:"\\dagger",tag:"mo",output:"\u2020",ttype:z},{input:"\\ddag",tag:"mo",output:"\u2021",ttype:z},{input:"\\ddagger",tag:"mo",output:"\u2021",ttype:z},{input:"\\lhd",tag:"mo",output:"\u22B2",ttype:z},{input:"\\rhd",tag:"mo",output:"\u22B3",ttype:z},{input:"\\unlhd",tag:"mo",output:"\u22B4",ttype:z},{input:"\\unrhd",tag:"mo",output:"\u22B5",ttype:z},{input:"\\sum",tag:"mo",output:"\u2211",ttype:r},{input:"\\prod",tag:"mo",output:"\u220F",ttype:r},{input:"\\bigcap",tag:"mo",output:"\u22C2",ttype:r},{input:"\\bigcup",tag:"mo",output:"\u22C3",ttype:r},{input:"\\bigwedge",tag:"mo",output:"\u22C0",ttype:r},{input:"\\bigvee",tag:"mo",output:"\u22C1",ttype:r},{input:"\\bigsqcap",tag:"mo",output:"\u2A05",ttype:r},{input:"\\bigsqcup",tag:"mo",output:"\u2A06",ttype:r},{input:"\\coprod",tag:"mo",output:"\u2210",ttype:r},{input:"\\bigoplus",tag:"mo",output:"\u2A01",ttype:r},{input:"\\bigotimes",tag:"mo",output:"\u2A02",ttype:r},{input:"\\bigodot",tag:"mo",output:"\u2A00",ttype:r},{input:"\\biguplus",tag:"mo",output:"\u2A04",ttype:r},{input:"\\int",tag:"mo",output:"\u222B",ttype:z},{input:"\\oint",tag:"mo",output:"\u222E",ttype:z},{input:":=",tag:"mo",output:":=",ttype:z},{input:"\\lt",tag:"mo",output:"<",ttype:z},{input:"\\gt",tag:"mo",output:">",ttype:z},{input:"\\ne",tag:"mo",output:"\u2260",ttype:z},{input:"\\neq",tag:"mo",output:"\u2260",ttype:z},{input:"\\le",tag:"mo",output:"\u2264",ttype:z},{input:"\\leq",tag:"mo",output:"\u2264",ttype:z},{input:"\\leqslant",tag:"mo",output:"\u2264",ttype:z},{input:"\\ge",tag:"mo",output:"\u2265",ttype:z},{input:"\\geq",tag:"mo",output:"\u2265",ttype:z},{input:"\\geqslant",tag:"mo",output:"\u2265",ttype:z},{input:"\\equiv",tag:"mo",output:"\u2261",ttype:z},{input:"\\ll",tag:"mo",output:"\u226A",ttype:z},{input:"\\gg",tag:"mo",output:"\u226B",ttype:z},{input:"\\doteq",tag:"mo",output:"\u2250",ttype:z},{input:"\\prec",tag:"mo",output:"\u227A",ttype:z},{input:"\\succ",tag:"mo",output:"\u227B",ttype:z},{input:"\\preceq",tag:"mo",output:"\u227C",ttype:z},{input:"\\succeq",tag:"mo",output:"\u227D",ttype:z},{input:"\\subset",tag:"mo",output:"\u2282",ttype:z},{input:"\\supset",tag:"mo",output:"\u2283",ttype:z},{input:"\\subseteq",tag:"mo",output:"\u2286",ttype:z},{input:"\\supseteq",tag:"mo",output:"\u2287",ttype:z},{input:"\\sqsubset",tag:"mo",output:"\u228F",ttype:z},{input:"\\sqsupset",tag:"mo",output:"\u2290",ttype:z},{input:"\\sqsubseteq",tag:"mo",output:"\u2291",ttype:z},{input:"\\sqsupseteq",tag:"mo",output:"\u2292",ttype:z},{input:"\\sim",tag:"mo",output:"\u223C",ttype:z},{input:"\\simeq",tag:"mo",output:"\u2243",ttype:z},{input:"\\approx",tag:"mo",output:"\u2248",ttype:z},{input:"\\cong",tag:"mo",output:"\u2245",ttype:z},{input:"\\Join",tag:"mo",output:"\u22C8",ttype:z},{input:"\\bowtie",tag:"mo",output:"\u22C8",ttype:z},{input:"\\in",tag:"mo",output:"\u2208",ttype:z},{input:"\\ni",tag:"mo",output:"\u220B",ttype:z},{input:"\\owns",tag:"mo",output:"\u220B",ttype:z},{input:"\\propto",tag:"mo",output:"\u221D",ttype:z},{input:"\\vdash",tag:"mo",output:"\u22A2",ttype:z},{input:"\\dashv",tag:"mo",output:"\u22A3",ttype:z},{input:"\\models",tag:"mo",output:"\u22A8",ttype:z},{input:"\\perp",tag:"mo",output:"\u22A5",ttype:z},{input:"\\smile",tag:"mo",output:"\u2323",ttype:z},{input:"\\frown",tag:"mo",output:"\u2322",ttype:z},{input:"\\asymp",tag:"mo",output:"\u224D",ttype:z},{input:"\\notin",tag:"mo",output:"\u2209",ttype:z},{input:"\\begin{eqnarray}",output:"X",ttype:l,invisible:true},{input:"\\begin{array}",output:"X",ttype:l,invisible:true},{input:"\\\\",output:"}&{",ttype:o},{input:"\\end{eqnarray}",output:"}}",ttype:o},{input:"\\end{array}",output:"}}",ttype:o},{input:"\\big",tag:"mo",output:"X",atval:"1.2",ttype:A},{input:"\\Big",tag:"mo",output:"X",atval:"1.6",ttype:A},{input:"\\bigg",tag:"mo",output:"X",atval:"2.2",ttype:A},{input:"\\Bigg",tag:"mo",output:"X",atval:"2.9",ttype:A},{input:"\\left",tag:"mo",output:"X",ttype:x},{input:"\\right",tag:"mo",output:"X",ttype:e},{input:"{",output:"{",ttype:x,invisible:true},{input:"}",output:"}",ttype:e,invisible:true},{input:"(",tag:"mo",output:"(",atval:"1",ttype:j},{input:"[",tag:"mo",output:"[",atval:"1",ttype:j},{input:"\\lbrack",tag:"mo",output:"[",atval:"1",ttype:j},{input:"\\{",tag:"mo",output:"{",atval:"1",ttype:j},{input:"\\lbrace",tag:"mo",output:"{",atval:"1",ttype:j},{input:"\\langle",tag:"mo",output:"\u2329",atval:"1",ttype:j},{input:"\\lfloor",tag:"mo",output:"\u230A",atval:"1",ttype:j},{input:"\\lceil",tag:"mo",output:"\u2308",atval:"1",ttype:j},{input:")",tag:"mo",output:")",rtag:"mi",atval:"1",ttype:j},{input:"]",tag:"mo",output:"]",rtag:"mi",atval:"1",ttype:j},{input:"\\rbrack",tag:"mo",output:"]",rtag:"mi",atval:"1",ttype:j},{input:"\\}",tag:"mo",output:"}",rtag:"mi",atval:"1",ttype:j},{input:"\\rbrace",tag:"mo",output:"}",rtag:"mi",atval:"1",ttype:j},{input:"\\rangle",tag:"mo",output:"\u232A",rtag:"mi",atval:"1",ttype:j},{input:"\\rfloor",tag:"mo",output:"\u230B",rtag:"mi",atval:"1",ttype:j},{input:"\\rceil",tag:"mo",output:"\u2309",rtag:"mi",atval:"1",ttype:j},{input:"|",tag:"mo",output:"\u2223",atval:"1",ttype:j},{input:"\\|",tag:"mo",output:"\u2225",atval:"1",ttype:j},{input:"\\vert",tag:"mo",output:"\u2223",atval:"1",ttype:j},{input:"\\Vert",tag:"mo",output:"\u2225",atval:"1",ttype:j},{input:"\\mid",tag:"mo",output:"\u2223",atval:"1",ttype:j},{input:"\\parallel",tag:"mo",output:"\u2225",atval:"1",ttype:j},{input:"/",tag:"mo",output:"/",atval:"1.01",ttype:j},{input:"\\backslash",tag:"mo",output:"\u2216",atval:"1",ttype:j},{input:"\\setminus",tag:"mo",output:"\\",ttype:z},{input:"\\!",tag:"mspace",atname:"width",atval:"-0.167em",ttype:q},{input:"\\,",tag:"mspace",atname:"width",atval:"0.167em",ttype:q},{input:"\\>",tag:"mspace",atname:"width",atval:"0.222em",ttype:q},{input:"\\:",tag:"mspace",atname:"width",atval:"0.222em",ttype:q},{input:"\\;",tag:"mspace",atname:"width",atval:"0.278em",ttype:q},{input:"~",tag:"mspace",atname:"width",atval:"0.333em",ttype:q},{input:"\\quad",tag:"mspace",atname:"width",atval:"1em",ttype:q},{input:"\\qquad",tag:"mspace",atname:"width",atval:"2em",ttype:q},{input:"\\prime",tag:"mo",output:"\u2032",ttype:z},{input:"'",tag:"mo",output:"\u02B9",ttype:z},{input:"''",tag:"mo",output:"\u02BA",ttype:z},{input:"'''",tag:"mo",output:"\u2034",ttype:z},{input:"''''",tag:"mo",output:"\u2057",ttype:z},{input:"\\ldots",tag:"mo",output:"\u2026",ttype:z},{input:"\\cdots",tag:"mo",output:"\u22EF",ttype:z},{input:"\\vdots",tag:"mo",output:"\u22EE",ttype:z},{input:"\\ddots",tag:"mo",output:"\u22F1",ttype:z},{input:"\\forall",tag:"mo",output:"\u2200",ttype:z},{input:"\\exists",tag:"mo",output:"\u2203",ttype:z},{input:"\\Re",tag:"mo",output:"\u211C",ttype:z},{input:"\\Im",tag:"mo",output:"\u2111",ttype:z},{input:"\\aleph",tag:"mo",output:"\u2135",ttype:z},{input:"\\hbar",tag:"mo",output:"\u210F",ttype:z},{input:"\\ell",tag:"mo",output:"\u2113",ttype:z},{input:"\\wp",tag:"mo",output:"\u2118",ttype:z},{input:"\\emptyset",tag:"mo",output:"\u2205",ttype:z},{input:"\\infty",tag:"mo",output:"\u221E",ttype:z},{input:"\\surd",tag:"mo",output:"\\sqrt{}",ttype:o},{input:"\\partial",tag:"mo",output:"\u2202",ttype:z},{input:"\\nabla",tag:"mo",output:"\u2207",ttype:z},{input:"\\triangle",tag:"mo",output:"\u25B3",ttype:z},{input:"\\therefore",tag:"mo",output:"\u2234",ttype:z},{input:"\\angle",tag:"mo",output:"\u2220",ttype:z},{input:"\\diamond",tag:"mo",output:"\u22C4",ttype:z},{input:"\\Diamond",tag:"mo",output:"\u25C7",ttype:z},{input:"\\neg",tag:"mo",output:"\u00AC",ttype:z},{input:"\\lnot",tag:"mo",output:"\u00AC",ttype:z},{input:"\\bot",tag:"mo",output:"\u22A5",ttype:z},{input:"\\top",tag:"mo",output:"\u22A4",ttype:z},{input:"\\square",tag:"mo",output:"\u25AB",ttype:z},{input:"\\Box",tag:"mo",output:"\u25A1",ttype:z},{input:"\\wr",tag:"mo",output:"\u2240",ttype:z},{input:"\\arccos",tag:"mi",output:"arccos",ttype:b,func:true},{input:"\\arcsin",tag:"mi",output:"arcsin",ttype:b,func:true},{input:"\\arctan",tag:"mi",output:"arctan",ttype:b,func:true},{input:"\\arg",tag:"mi",output:"arg",ttype:b,func:true},{input:"\\cos",tag:"mi",output:"cos",ttype:b,func:true},{input:"\\cosh",tag:"mi",output:"cosh",ttype:b,func:true},{input:"\\cot",tag:"mi",output:"cot",ttype:b,func:true},{input:"\\coth",tag:"mi",output:"coth",ttype:b,func:true},{input:"\\csc",tag:"mi",output:"csc",ttype:b,func:true},{input:"\\deg",tag:"mi",output:"deg",ttype:b,func:true},{input:"\\det",tag:"mi",output:"det",ttype:b,func:true},{input:"\\dim",tag:"mi",output:"dim",ttype:b,func:true},{input:"\\exp",tag:"mi",output:"exp",ttype:b,func:true},{input:"\\gcd",tag:"mi",output:"gcd",ttype:b,func:true},{input:"\\hom",tag:"mi",output:"hom",ttype:b,func:true},{input:"\\inf",tag:"mo",output:"inf",ttype:r},{input:"\\ker",tag:"mi",output:"ker",ttype:b,func:true},{input:"\\lg",tag:"mi",output:"lg",ttype:b,func:true},{input:"\\lim",tag:"mo",output:"lim",ttype:r},{input:"\\liminf",tag:"mo",output:"liminf",ttype:r},{input:"\\limsup",tag:"mo",output:"limsup",ttype:r},{input:"\\ln",tag:"mi",output:"ln",ttype:b,func:true},{input:"\\log",tag:"mi",output:"log",ttype:b,func:true},{input:"\\max",tag:"mo",output:"max",ttype:r},{input:"\\min",tag:"mo",output:"min",ttype:r},{input:"\\Pr",tag:"mi",output:"Pr",ttype:b,func:true},{input:"\\sec",tag:"mi",output:"sec",ttype:b,func:true},{input:"\\sin",tag:"mi",output:"sin",ttype:b,func:true},{input:"\\sinh",tag:"mi",output:"sinh",ttype:b,func:true},{input:"\\sup",tag:"mo",output:"sup",ttype:r},{input:"\\tan",tag:"mi",output:"tan",ttype:b,func:true},{input:"\\tanh",tag:"mi",output:"tanh",ttype:b,func:true},{input:"\\gets",tag:"mo",output:"\u2190",ttype:z},{input:"\\leftarrow",tag:"mo",output:"\u2190",ttype:z},{input:"\\to",tag:"mo",output:"\u2192",ttype:z},{input:"\\rightarrow",tag:"mo",output:"\u2192",ttype:z},{input:"\\leftrightarrow",tag:"mo",output:"\u2194",ttype:z},{input:"\\uparrow",tag:"mo",output:"\u2191",ttype:z},{input:"\\downarrow",tag:"mo",output:"\u2193",ttype:z},{input:"\\updownarrow",tag:"mo",output:"\u2195",ttype:z},{input:"\\Leftarrow",tag:"mo",output:"\u21D0",ttype:z},{input:"\\Rightarrow",tag:"mo",output:"\u21D2",ttype:z},{input:"\\Leftrightarrow",tag:"mo",output:"\u21D4",ttype:z},{input:"\\iff",tag:"mo",output:"~\\Longleftrightarrow~",ttype:o},{input:"\\Uparrow",tag:"mo",output:"\u21D1",ttype:z},{input:"\\Downarrow",tag:"mo",output:"\u21D3",ttype:z},{input:"\\Updownarrow",tag:"mo",output:"\u21D5",ttype:z},{input:"\\mapsto",tag:"mo",output:"\u21A6",ttype:z},{input:"\\longleftarrow",tag:"mo",output:"\u2190",ttype:c},{input:"\\longrightarrow",tag:"mo",output:"\u2192",ttype:c},{input:"\\longleftrightarrow",tag:"mo",output:"\u2194",ttype:c},{input:"\\Longleftarrow",tag:"mo",output:"\u21D0",ttype:c},{input:"\\Longrightarrow",tag:"mo",output:"\u21D2",ttype:c},{input:"\\implies",tag:"mo",output:"\u21D2",ttype:c},{input:"\\Longleftrightarrow",tag:"mo",output:"\u21D4",ttype:c},{input:"\\longmapsto",tag:"mo",output:"\u21A6",ttype:z},{input:"\\sqrt",tag:"msqrt",output:"sqrt",ttype:b},{input:"\\root",tag:"mroot",output:"root",ttype:d},{input:"\\frac",tag:"mfrac",output:"/",ttype:d},{input:"\\stackrel",tag:"mover",output:"stackrel",ttype:d},{input:"\\atop",tag:"mfrac",output:"",ttype:p},{input:"\\choose",tag:"mfrac",output:"",ttype:p},{input:"_",tag:"msub",output:"_",ttype:p},{input:"^",tag:"msup",output:"^",ttype:p},{input:"\\mbox",tag:"mtext",output:"mbox",ttype:B},{input:"\\acute",tag:"mover",output:"\u00B4",ttype:b,acc:true},{input:"\\grave",tag:"mover",output:"\u0060",ttype:b,acc:true},{input:"\\breve",tag:"mover",output:"\u02D8",ttype:b,acc:true},{input:"\\check",tag:"mover",output:"\u02C7",ttype:b,acc:true},{input:"\\dot",tag:"mover",output:".",ttype:b,acc:true},{input:"\\ddot",tag:"mover",output:"..",ttype:b,acc:true},{input:"\\mathring",tag:"mover",output:"\u00B0",ttype:b,acc:true},{input:"\\vec",tag:"mover",output:"\u20D7",ttype:b,acc:true},{input:"\\overrightarrow",tag:"mover",output:"\u20D7",ttype:b,acc:true},{input:"\\overleftarrow",tag:"mover",output:"\u20D6",ttype:b,acc:true},{input:"\\hat",tag:"mover",output:"\u005E",ttype:b,acc:true},{input:"\\widehat",tag:"mover",output:"\u0302",ttype:b,acc:true},{input:"\\tilde",tag:"mover",output:"~",ttype:b,acc:true},{input:"\\widetilde",tag:"mover",output:"\u02DC",ttype:b,acc:true},{input:"\\bar",tag:"mover",output:"\u203E",ttype:b,acc:true},{input:"\\overbrace",tag:"mover",output:"\u23B4",ttype:b,acc:true},{input:"\\overline",tag:"mover",output:"\u00AF",ttype:b,acc:true},{input:"\\underbrace",tag:"munder",output:"\u23B5",ttype:b,acc:true},{input:"\\underline",tag:"munder",output:"\u00AF",ttype:b,acc:true},{input:"\\displaystyle",tag:"mstyle",atname:"displaystyle",atval:"true",ttype:b},{input:"\\textstyle",tag:"mstyle",atname:"displaystyle",atval:"false",ttype:b},{input:"\\scriptstyle",tag:"mstyle",atname:"scriptlevel",atval:"1",ttype:b},{input:"\\scriptscriptstyle",tag:"mstyle",atname:"scriptlevel",atval:"2",ttype:b},{input:"\\mathrm",tag:"mtext",output:"text",ttype:B},{input:"\\textrm",tag:"mtext",output:"text",ttype:B},{input:"\\mathbf",tag:"mstyle",atname:"mathvariant",atval:"bold",ttype:b,codes:h},{input:"\\textbf",tag:"mstyle",atname:"mathvariant",atval:"bold",ttype:b,codes:h},{input:"\\mathit",tag:"mstyle",atname:"mathvariant",atval:"italic",ttype:b},{input:"\\textit",tag:"mstyle",atname:"mathvariant",atval:"italic",ttype:b},{input:"\\mathtt",tag:"mstyle",atname:"mathvariant",atval:"monospace",ttype:b},{input:"\\texttt",tag:"mstyle",atname:"mathvariant",atval:"monospace",ttype:b},{input:"\\mathsf",tag:"mstyle",atname:"mathvariant",atval:"sans-serif",ttype:b},{input:"\\mathbb",tag:"mstyle",atname:"mathvariant",atval:"double-struck",ttype:b,codes:s},{input:"\\mathcal",tag:"mstyle",atname:"mathvariant",atval:"script",ttype:b,codes:t},{input:"\\mathfrak",tag:"mstyle",atname:"mathvariant",atval:"fraktur",ttype:b,codes:D}];var u=[];function n(){if(m.browser.mozilla||m.browser.opera){return true}else{return false}}function G(H,I){if(H.input>I.input){return 1}else{return -1}}function w(){var H=a.length;a.sort(G);for(var I=0;I<H;I++){u[I]=a[I].input}}function y(H,I){return m.trim(H.slice(I))}function E(I,L,M){if(M===0){var K,H;M=-1;K=I.length;while(M+1<K){H=(M+K)>>1;if(I[H]<L){M=H}else{K=H}}return K}else{for(var J=M;J<I.length&&I[J]<L;J++){}}return J}function v(O){var H=0;var I=0;var K;var Q;var P;var L="";var N=true;var M=O.length;for(var J=1;J<=M&&N;J++){Q=O.slice(0,J);I=H;H=E(u,Q,I);if(H<u.length&&O.slice(0,u[H].length)==u[H]){L=u[H];K=H;J=L.length}N=H<u.length&&O.slice(0,u[H].length)>=u[H]}if(L!==""){return a[K]}H=1;Q=O.slice(0,1);if("0"<=Q&&Q<="9"){P="mn"}else{P=(("A">Q||Q>"Z")&&("a">Q||Q>"z")?"mo":"mi")}return{input:Q,tag:P,output:Q,ttype:z}}function g(P){var K,I,U,J,M,S,O=document.createDocumentFragment();P=m.trim(P);K=v(P);if(K===null||K.ttype==e){return[null,P,null]}if(K.ttype==o){P=K.output+y(P,K.input.length);K=v(P);if(K===null||K.ttype==e){return[null,P,null]}}P=y(P,K.input.length);switch(K.ttype){case q:I=C(K.tag);I.setAttribute(K.atname,K.atval);return[I,P,K.tag];case r:return[C(K.tag,document.createTextNode(K.output)),P,K.tag];case z:I=C(K.tag,document.createTextNode(K.output));return[I,P,K.tag];case c:I=C(K.tag,document.createTextNode(K.output));I.setAttribute("minsize","1.5");I.setAttribute("maxsize","1.5");I=C("mover",I);I.appendChild(C("mspace"));return[I,P,K.tag];case j:I=C(K.tag,document.createTextNode(K.output));if(K.input=="|"||K.input=="\\vert"||K.input=="\\|"||K.input=="\\Vert"){I.setAttribute("lspace","0em");I.setAttribute("rspace","0em")}I.setAttribute("maxsize",K.atval);if(K.rtag!==null){return[I,P,K.rtag]}else{return[I,P,K.tag]}break;case A:var N=K.atval;K=v(P);if(K===null){return[null,P,null]}P=y(P,K.input.length);I=C(K.tag,document.createTextNode(K.output));I.setAttribute("minsize",N);I.setAttribute("maxsize",N);return[I,P,K.tag];case x:if(K.input=="\\left"){K=v(P);if(K!==null){if(K.input=="."){K.invisible=true}P=y(P,K.input.length)}}U=k(P,true,false);if(K===null||(typeof K.invisible=="boolean"&&K.invisible)){I=C("mrow",U[0])}else{I=C("mo",document.createTextNode(K.output));I=C("mrow",I);I.appendChild(U[0])}return[I,U[1],U[2]];case l:if(K.input=="\\begin{array}"){var T="";K=v(P);P=m.trim(P);if(K===null){T="l"}else{P=y(P,K.input.length);if(K.input!="{"){T="l"}else{do{K=v(P);if(K!==null){P=y(P,K.input.length);if(K.input!="}"){T=T+K.input}}}while(K!==null&&K.input!==""&&K.input!="}")}}U=k("{"+P,true,true);I=C("mtable",U[0]);T=T.replace(/l/g,"left ");T=T.replace(/r/g,"right ");T=T.replace(/c/g,"center ");I.setAttribute("columnalign",T);I.setAttribute("displaystyle","false");return[I,U[1],null]}else{U=k("{"+P,true,true);I=C("mtable",U[0]);I.setAttribute("columnspacing","0.167em");I.setAttribute("columnalign","right center left");I.setAttribute("displaystyle","true");I=C("mrow",I);return[I,U[1],null]}break;case B:if(P.charAt(0)=="{"){M=P.indexOf("}")}else{M=0}if(M==-1){M=P.length}S=P.slice(1,M);O.appendChild(C(K.tag,document.createTextNode(S)));P=y(P,M+1);return[C("mrow",O),P,null];case b:U=g(P);if(U[0]===null){return[C(K.tag,document.createTextNode(K.output)),P]}if(typeof K.func=="boolean"&&K.func){S=P.charAt(0);if(S=="^"||S=="_"||S==","){return[C(K.tag,document.createTextNode(K.output)),P,K.tag]}else{I=C("mrow",C(K.tag,document.createTextNode(K.output)));I.appendChild(U[0]);return[I,U[1],K.tag]}}if(K.input=="\\sqrt"){return[C(K.tag,U[0]),U[1],K.tag]}else{if(typeof K.acc=="boolean"&&K.acc){I=C(K.tag,U[0]);var H=K.output;var R=C("mo",document.createTextNode(H));if(K.input=="\\vec"||K.input=="\\check"){R.setAttribute("maxsize","1.2")}if(K.input=="\\underbrace"||K.input=="\\underline"){R.setAttribute("accentunder","true")}else{R.setAttribute("accent","true")}I.appendChild(R);if(K.input=="\\overbrace"||K.input=="\\underbrace"){I.ttype=r}return[I,U[1],K.tag]}else{if(typeof K.codes!="undefined"){for(M=0;M<U[0].childNodes.length;M++){if(U[0].childNodes[M].nodeName=="mi"||U[0].nodeName=="mi"){S=(U[0].nodeName=="mi"?U[0].firstChild.nodeValue:U[0].childNodes[M].firstChild.nodeValue);var Q=[];for(var L=0;L<S.length;L++){if(S.charCodeAt(L)>64&&S.charCodeAt(L)<91){Q=Q+K.codes[S.charCodeAt(L)-65]}else{if(S.charCodeAt(L)>96&&S.charCodeAt(L)<123){Q=Q+K.codes[S.charCodeAt(L)-71]}}}if(U[0].nodeName=="mi"){U[0]=C("mo").appendChild(document.createTextNode(Q))}else{U[0].replaceChild(C("mo").appendChild(document.createTextNode(Q)),U[0].childNodes[M])}}}}I=C(K.tag,U[0]);I.setAttribute(K.atname,K.atval);if(K.input=="\\scriptstyle"||K.input=="\\scriptscriptstyle"){I.setAttribute("displaystyle","false")}return[I,U[1],K.tag]}}break;case d:U=g(P);if(U[0]===null){return[C("mo",document.createTextNode(K.input)),P,null]}J=g(U[1]);if(J[0]===null){return[C("mo",document.createTextNode(K.input)),P,null]}if(K.input=="\\root"||K.input=="\\stackrel"){O.appendChild(J[0])}O.appendChild(U[0]);if(K.input=="\\frac"){O.appendChild(J[0])}return[C(K.tag,O),J[1],K.tag];case p:P=y(P,K.input.length);return[C("mo",document.createTextNode(K.output)),P,K.tag];default:return[C(K.tag,document.createTextNode(K.output)),P,K.tag]}}function F(M){var L,J,I,K,O,P,N;M=m.trim(M);J=v(M);O=g(M);K=O[0];M=O[1];P=O[2];L=v(M);if(L.ttype==p){M=y(M,L.input.length);O=g(M);if(O[0]===null){O[0]=C("mo",document.createTextNode("\u25A1"))}M=O[1];P=O[2];if(L.input=="_"||L.input=="^"){I=v(M);P=null;N=((J.ttype==r)||(K.ttype==r));if(L.input=="_"&&I.input=="^"){M=y(M,I.input.length);var H=g(M);M=H[1];P=H[2];K=C((N?"munderover":"msubsup"),K);K.appendChild(O[0]);K.appendChild(H[0])}else{if(L.input=="_"){K=C((N?"munder":"msub"),K);K.appendChild(O[0])}else{K=C((N?"mover":"msup"),K);K.appendChild(O[0])}}K=C("mrow",K)}else{K=C(L.tag,K);if(L.input=="\\atop"||L.input=="\\choose"){K.setAttribute("linethickness","0ex")}K.appendChild(O[0]);if(L.input=="\\choose"){K=C("mfenced",K)}}}return[K,M,P]}function k(O,N,T){var S,P,K,V,Z,L=document.createDocumentFragment();do{O=m.trim(O);K=F(O);P=K[0];O=K[1];Z=K[2];S=v(O);if(P!=undefined){if((Z=="mn"||Z=="mi")&&S!==null&&typeof S.func=="boolean"&&S.func){var Y=C("mspace");Y.setAttribute("width","0.167em");P=C("mrow",P);P.appendChild(Y)}L.appendChild(P)}}while((S.ttype!=e)&&S!==null&&S.output!="");Z=null;if(S.ttype==e){if(S.input=="\\right"){O=y(O,S.input.length);S=v(O);if(S!==null&&S.input=="."){S.invisible=true}if(S!==null){Z=S.rtag}}if(S!==null){O=y(O,S.input.length)}var W=L.childNodes.length;if(T&&W>0&&L.childNodes[W-1].nodeName=="mrow"&&W>1&&L.childNodes[W-2].nodeName=="mo"&&L.childNodes[W-2].firstChild.nodeValue=="&"){var I=[];var Q=L.childNodes.length;for(V=0;T&&V<Q;V=V+2){I[V]=[];P=L.childNodes[V];for(var U=0;U<P.childNodes.length;U++){if(P.childNodes[U].firstChild.nodeValue=="&"){I[V][I[V].length]=U}}}var J,H,M,R,X=document.createDocumentFragment();for(V=0;V<Q;V=V+2){J=document.createDocumentFragment();H=document.createDocumentFragment();P=L.firstChild;M=P.childNodes.length;R=0;for(U=0;U<M;U++){if(typeof I[V][R]!="undefined"&&U==I[V][R]){P.removeChild(P.firstChild);J.appendChild(C("mtd",H));R++}else{H.appendChild(P.firstChild)}}J.appendChild(C("mtd",H));if(L.childNodes.length>2){L.removeChild(L.firstChild);L.removeChild(L.firstChild)}X.appendChild(C("mtr",J))}return[X,O]}if(typeof S.invisible!="boolean"||!S.invisible){P=C("mo",document.createTextNode(S.output));L.appendChild(P)}}return[L,O,Z]}if(!document.createElementNS){document.createElementNS=function(I,H){return this.createElement(H)}}function C(H,J){var I=document.createElementNS("http://www.w3.org/1998/Math/MathML",H);if(J){m(I).append(J)}return I}return{showFormulaOnMouseOver:false,latexImages:false,latexConverter:"http://www.forkosh.dreamhost.com/mimetex.cgi?",mathColor:"black",mathFontSize:"",mathFontFamily:"",createElementXHTML:function(H,I,K){var J=document.createElementNS("http://www.w3.org/1999/xhtml",H);if(I){J.id=I}if(K){J.className=K}return J},define:function(J,K){if(MSVG.latexImages){return}if((typeof J)=="string"){J=[J];K=[K]}var I,H=J.length;if(H!=K.length){return}for(I=0;I<H;I++){a=a.concat([{input:"\\"+J[I],tag:"mo",output:K[I],ttype:o}])}w()},parseMath:function(L,K,I,H){if(L===null){return null}var M=k(L.replace(/^\s+/g,""),false,false)[0];var J=(M.firstChild.nodeName=="mstyle")?M.firstChild:C("mstyle",M);if(K){m(J).attr({displaystyle:"true"})}m(J).attr({mathcolor:H||MSVG.mathColor,fontsize:I||MSVG.mathFontSize,fontfamily:MSVG.mathFontFamily});J=C("math",J);if(MSVG.showFormulaOnMouseOver){m(J).attr({title:L.replace(/\s+/g," ")})}return J},parseMathExternal:function(M,L,I,H){if(M===null){return null}var K=MSVG.createElementXHTML("img");var J=MSVG.latexConverter+M;m(K).attr({src:J});if(MSVG.showFormulaOnMouseOver){m(K).attr({title:M.replace(/\s+/g," ")})}return K},generic:function(){if(MSVG.latexImages||!n()){MSVG.parseMath=MSVG.parseMathExternal}else{w()}if(!(window.SVGElement||m.browser.opera||m.browser.safari)){ASVG.drawPictures=ASVG.removePictures}}}}(jQuery);var ASVG=function($){var SVG;var collection=[];var chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";var markerChars="o*sSx+<>|";function createSVGElement(elType){return document.createElementNS("http://www.w3.org/2000/svg",elType)}function getSVGElement(id,el){var node,res={node:null,newEl:false};if(id){id=SVG.id+"_"+id;res.node=$("#"+id)[0]}if(!res.node){res.node=createSVGElement(el);if(id){res.node.id=id}res.newEl=true}return res}function appendSVG(elmt){if(elmt.newEl){$(SVG.canvas).append(elmt.node)}}function setButton(text,title,func){var node=MSVG.createElementXHTML("span",null,"svgButton");node.title=title;node.onclick=func;$(node).append(text);$(node).css({paddingRight:"0.5em",paddingLeft:"0.5em",fontSize:"1em",fontFamily:"monospace",background:"blue",color:"yellow",cursor:"pointer"});$(node).mouseover(function(){$(this).css({background:"yellow",color:"blue"})});$(node).mouseout(function(){$(this).css({background:"blue",color:"yellow"})});node.setAttribute("owner",SVG.id);return node}function pictureAttributes(){this.stroke="blue";this.strokewidth=1;this.strokeopacity=1;this.strokedasharray="none";this.fill="none";this.fillopacity=1;this.fontstyle="normal";this.fontfamily="serif";this.fontweight="normal";this.fontsize=12;this.fontstroke="none";this.fontfill="black";this.largearc=0;this.sweep=0;this.rx=0;this.ry=0;this.closed=false;this.curve="";this.marker="o";this.markerstrokewidth=1;this.markerstroke="blue";this.markerfill=null;this.markersize=8;this.markeropacity=1;this.direction=[1,0];this.ticklabels="";this.pos="";this.points=200;this.axesstroke="black";this.axesstrokewidth=0.5;this.gridstroke="grey";this.gridstrokewidth=0.25;this.backgroundcolor="white";this.backgroundopacity=1}function pictureObject(){this.id=null;this.src="";this.borderstroke="black";this.borderwidth=0;this.canvas=null;this.width=300;this.height=200;this.factor=1;this.xmin=-5;this.xmax=5;this.ymin=null;this.ymax=null;this.xunitlength=null;this.yunitlength=null;this.origin=[0,0];this.coords="cartesian";this.mouse=[null,null];this.drag=null;this.pan=true;this.attr=new pictureAttributes()}function refresh(){translateAndEval(SVG.id)}function translateAndEval(id){var errstr;var src=SVG.src;$("#"+SVG.id+"Canvas").empty();$("#"+SVG.id+"mml").empty();ASVG.dynamic[id]={};src=src.replace(/dynamic\./g,"ASVG.dynamic."+id+".");SVG.attr=new pictureAttributes();try{with(Math){eval(src)}}catch(err){if(typeof err=="object"){errstr=err.name+" "+err.message+" "+err.number+" "+err.description}else{errstr=err}alert(errstr+"\n"+src)}collection[SVG.id]=SVG}function setOptions(atr){for(i in atr){SVG.attr[i]=atr[i]}}function getOption(opt,options){return(opt in options)?options[opt]:SVG.attr[opt]}function setAction(evt,fn,id){if(!$.isFunction(fn)){return}var node=(id)?$("#"+SVG.id+"_"+id):$("#"+SVG.id);$(node).bind(evt,fn)}function getPosition(evt){var obj=evt.currentTarget;var posX=(evt.pageX-obj.parentNode.offsetLeft-SVG.origin[0])/SVG.xunitlength;var posY=(SVG.height-SVG.origin[1]-(evt.pageY-obj.parentNode.offsetTop))/SVG.yunitlength;return[posX,posY]}function getAngle(p){p=p||[0,0];var res=Math.atan2(SVG.mouse[1]-p[1],SVG.mouse[0]-p[0]);res=(res<0)?res+2*Math.PI:res;return res}function getDistance(p){p=p||[0,0];return Math.sqrt(Math.pow(SVG.mouse[0]-p[0],2)+Math.pow(SVG.mouse[1]-p[1],2))}function updateButton(obj){var id=$(obj).attr("owner");var node=$("#"+id+"src");if(obj.firstChild.nodeValue=="Edit"){obj.firstChild.nodeValue="Update";obj.title="Update picture";node.val(SVG.src).css("display","block");return}else{SVG.src=node.val();translateAndEval(id)}}function switchTo(evt){var name=evt.currentTarget.id;if(SVG.id==name){return}SVG=collection[name]}function onWheel(evt){evt=evt||window.event;var factor=1;if(evt.wheelDelta){factor=(evt.wheelDelta>0)?0.8:1.25}else{if(evt.detail){factor=(evt.detail<0)?0.8:1.25}}if(evt.shiftKey){changeSize(factor)}else{changeScales(factor)}evt.preventDefault();evt.stopPropagation();return false}function onClick(evt){if(evt.button===0){if(evt.shiftKey){$("#"+SVG.id+"toolbar").slideToggle();$("#"+SVG.id+"src").val(SVG.src);evt.stopImmediatePropagation()}else{if(SVG.pan){SVG.drag=[evt.clientX,evt.clientY]}}}return false}function onDrop(evt){if(SVG.drag==null){return false}var xlen=(SVG.drag[0]-evt.clientX)/SVG.xunitlength;var ylen=(-SVG.drag[1]+evt.clientY)/SVG.yunitlength;SVG.drag=null;if(xlen==0&&ylen==0){return false}changeScales(1,[SVG.xmin+xlen,SVG.xmax+xlen,SVG.ymin+ylen,SVG.ymax+ylen]);return false}function setScales(){SVG.xunitlength=SVG.width/(SVG.xmax-SVG.xmin);SVG.yunitlength=SVG.height/(SVG.ymax-SVG.ymin);SVG.origin=[-SVG.xmin*SVG.xunitlength,-SVG.ymin*SVG.yunitlength]}function setSize(){var picture=$("#"+SVG.id)[0];picture.setAttribute("width",SVG.width);picture.setAttribute("height",SVG.height);picture.parentNode.style.width=SVG.width+"px";picture.parentNode.style.height=SVG.height+"px";var border=SVG.borderwidth*0.5;var node=$("#"+SVG.id+"ClipPath")[0];node.firstChild.setAttribute("d","M"+border+","+border+" "+(SVG.width-border)+","+border+" "+(SVG.width-border)+","+(SVG.height-border)+" "+border+","+(SVG.height-border));node=$("#"+SVG.id+"Coords")[0];if(node){node.setAttribute("x",SVG.width-border-2);node.setAttribute("y",SVG.height-border-5)}}function changeSize(factor){SVG.factor*=factor;SVG.width/=factor;SVG.height/=factor;setSize();setScales();translateAndEval(SVG.id)}function changeScales(factor,trans){trans=trans||[SVG.xmin,SVG.xmax,SVG.ymin,SVG.ymax];SVG.factor*=factor;var dx=(SVG.xmax-SVG.xmin)*(1-factor)*0.5;var dy=(SVG.ymax-SVG.ymin)*(1-factor)*0.5;SVG.xmin=trans[0]+dx;SVG.xmax=trans[1]-dx;SVG.ymin=trans[2]+dy;SVG.ymax=trans[3]-dy;setScales();translateAndEval(SVG.id)}function updateCoord(evt){if($.browser.opera){switchTo(evt)}SVG.mouse=getPosition(evt);if(SVG.coords!="none"){var coords;if(SVG.coords=="cartesian"){coords="C: ("+SVG.mouse[0].toFixed(2)+", "+SVG.mouse[1].toFixed(2)+")"}else{coords="P: ("+getDistance().toFixed(2)+", "+getAngle().toFixed(2)+")"}$("#"+SVG.id+"Coords").text(coords)}return false}function removeCoord(){$("#"+SVG.id+"Coords").text("")}function exportSVG(obj){var name=$(obj).attr("owner");var pic=$("#"+name)[0].parentNode.innerHTML;var pos=pic.indexOf("</svg")+6;pic=pic.substr(0,pos);var svg="<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n";if(pic.indexOf("svgCoords")>-1){pos=pic.lastIndexOf("<text");svg+=pic.substr(0,pos);pos=pic.lastIndexOf("</text")+7;svg+=pic.substr(pos)}else{svg+=pic}svg=svg.replace(/ /g,"");svg=svg.replace(/><(?!\/)/g,">\n<");obj.previousSibling.firstChild.nodeValue="Edit";$("#"+name+"src").val(svg).css("display","block")}function toSVG(p){var x=p[0]*SVG.xunitlength+SVG.origin[0];var y=SVG.height-p[1]*SVG.yunitlength-SVG.origin[1];return[x,y]}function toSVGPair(p){p=toSVG(p);return p[0]+" "+p[1]}function setStrokeAndFill(node,options){node.setAttribute("stroke",getOption("stroke",options));node.setAttribute("stroke-width",getOption("strokewidth",options)/SVG.factor);node.setAttribute("stroke-dasharray",getOption("strokedasharray",options));node.setAttribute("stroke-opacity",getOption("strokeopacity",options));node.setAttribute("fill",getOption("fill",options));node.setAttribute("fill-opacity",getOption("fillopacity",options))}function setText(st,id){$("#"+id).text(st)}function setMarkers(obj,options){if(!options.marker){return}var markersize=getOption("markersize",options)/SVG.factor;var markerstroke=getOption("markerstroke",options);var markeropacity=getOption("markeropacity",options);var markerfill=getOption("markerfill",options);if(!markerfill){markerfill=SVG.attr.backgroundcolor}var markerstrokewidth=getOption("markerstrokewidth",options)/SVG.factor;var node,node2,i,id,pos=["marker-start","marker-mid","marker-end"];var lim=options.marker.length;for(i=0;i<lim;i++){var type=options.marker.charAt(i);if(type=="-"){continue}id=((options.id)?options.id+"_":"")+"Marker_"+markerChars.indexOf(type);node=$("#"+SVG.id+"_"+id)[0];if(!node){node=getSVGElement(id,"marker").node;node.setAttribute("viewBox","0 0 10 10");node.setAttribute("refX",5);node.setAttribute("refY",5);node.setAttribute("orient","auto");node.setAttribute("stroke",markerstroke);node.setAttribute("stroke-width",markerstrokewidth);node.setAttribute("fill",markerfill);node.setAttribute("stroke-opacity",markeropacity);node.setAttribute("fill-opacity",markeropacity);switch(type){case"*":node.setAttribute("fill",markerstroke);case"o":node2=createSVGElement("circle");node2.setAttribute("cx",5);node2.setAttribute("cy",5);node2.setAttribute("r",4);break;case">":node2=createSVGElement("path");node2.setAttribute("d","M 0 0 L 10 5 L 0 10 z");node.setAttribute("fill",markerstroke);node.setAttribute("refX",10);break;case"<":node2=createSVGElement("path");node2.setAttribute("d","M 10 0 L 10 10 L 0 5 z");node.setAttribute("fill",markerstroke);node.setAttribute("refX",0);break;case"x":node2=createSVGElement("path");node2.setAttribute("d","M 0 0 L 10 10 M 0 10 L 10 0");break;case"+":node2=createSVGElement("path");node2.setAttribute("d","M 5 0 L 5 10 M 0 5 L 10 5");break;case"|":node2=createSVGElement("path");node2.setAttribute("d","M 5 0 L 5 10");break;case"S":node.setAttribute("fill",markerstroke);case"s":node2=createSVGElement("rect");node2.setAttribute("x",0);node2.setAttribute("y",0);node2.setAttribute("width",10);node2.setAttribute("height",10)}$(node).append(node2);$("#"+SVG.id+"_Defs:first").append(node)}node.setAttribute("markerWidth",markersize);node.setAttribute("markerHeight",markersize);obj.setAttribute(pos[i],"url(#"+SVG.id+"_"+id+")")}}function setLabels(p,options){if(!options.label){return}var i,point,pos;var label=(typeof options.label=="string")?[options.label]:options.label;var labelpos=getOption("pos",options);labelpos=(typeof labelpos=="string")?[labelpos]:labelpos;var poslen=labelpos.length;var markersize=getOption("markersize",options)/SVG.factor;var dx=(0.5*markersize/SVG.xunitlength)/SVG.factor;var dy=(0.5*markersize/SVG.yunitlength)/SVG.factor;for(i=0;i<label.length;i++){options.isLabel="_label"+i;point=p[i];pos=(poslen>i)?labelpos[i].toUpperCase():pos;if(/E/.test(pos)){point[0]+=dx}if(/W/.test(pos)){point[0]-=dx}if(/N/.test(pos)){point[1]+=dy}if(/S/.test(pos)){point[1]-=dy}options.pos=pos;text(point,label[i],options)}}function line(p,q,options){options=options||{};options.closed=false;options.curve="";path([p,q],options)}function dot(p,options){options=options||{};var direction=getOption("direction",options);var q=[p[0]+direction[0]/SVG.xunitlength,p[1]+direction[1]/SVG.yunitlength];options.marker=getOption("marker",options).charAt(0);var elmt=getSVGElement(options.id,"path");var st="M"+toSVGPair(p)+" "+toSVGPair(q);elmt.node.setAttribute("d",st);elmt.node.setAttribute("stroke","none");setMarkers(elmt.node,options);setLabels([p,q],options);appendSVG(elmt)}function path(list,options){options=options||{};var st,i,elmt=getSVGElement(options.id,"path");var curve=getOption("curve",options);var closed=getOption("closed",options);if(typeof plist=="string"){st=list}else{var len=list.length;if(len===0){return}st="M"+toSVGPair(list[0])+" "+curve;for(i=1;i<len;i++){st+=toSVGPair(list[i])+" "}if(closed){st+="Z"}}elmt.node.setAttribute("d",st);setStrokeAndFill(elmt.node,options);setMarkers(elmt.node,options);setLabels(list,options);appendSVG(elmt)}function rotate(id,angle,options){if(!id||!angle){return}var node=$("#"+SVG.id+"_"+id)[0];if(node){options=options||{};var center=options.center?toSVG(options.center):SVG.origin;angle=-angle*180/Math.PI;var transform=node.getAttribute("transform")||"";transform="rotate("+angle+" "+center+") "+(options.replace?"":transform);node.setAttribute("transform",transform)}}function translate(id,delta,options){if(!id||!delta){return}var node=$("#"+SVG.id+"_"+id)[0];if(node){options=options||{};delta=toSVG(delta);var transform=node.getAttribute("transform")||"";transform="translate("+(delta[0]-SVG.origin[0])+" "+(SVG.origin[1]+delta[1]-SVG.height)+") "+(options.replace?"":transform);node.setAttribute("transform",transform)}}function curve(list,options){options=options||{};options.curve=options.curve||"T";path(list,options)}function circle(center,radius,options){ellipse(center,radius,radius,options)}function loop(p,options){options=options||{};var d=options.direction||[1,0];options.curve="C";options.closed=false;path([p,[p[0]+d[0],p[1]+d[1]],[p[0]-d[1],p[1]+d[0]],p],options)}function arc(options){options=options||{};var start=options.start;var end=options.end;var center=options.center;var startangle=options.startangle;var endangle=options.endangle;var st="M",elmt=getSVGElement(options.id,"path");var largearc=getOption("largearc",options);var sweep=getOption("sweep",options);var closed=getOption("closed",options);var radius=options.radius;if(center!=null&&startangle!=null&&endangle!=null&&radius!=null){end=[radius*Math.cos(startangle)+center[0],radius*Math.sin(startangle)+center[1]];start=[radius*Math.cos(endangle)+center[0],radius*Math.sin(endangle)+center[1]]}if(start==null||end==null){return}if(!radius){var v=[end[0]-start[0],end[1]-start[1]];radius=Math.sqrt(v[0]*v[0]+v[1]*v[1])}if(closed&¢er!=null){st+=toSVGPair(center)+" "}st+=toSVGPair(start)+" A"+radius*SVG.xunitlength+","+radius*SVG.yunitlength+" 0 "+largearc+","+sweep+" "+toSVGPair(end);if(closed&¢er!=null){st+=" z"}elmt.node.setAttribute("d",st);setStrokeAndFill(elmt.node,options);setMarkers(elmt.node,options);setLabels([start,end],options);appendSVG(elmt)}function ellipse(center,rx,ry,options){options=options||{};var elmt=getSVGElement(options.id,"ellipse");center=toSVG(center);elmt.node.setAttribute("cx",center[0]);elmt.node.setAttribute("cy",center[1]);elmt.node.setAttribute("rx",rx*SVG.xunitlength);elmt.node.setAttribute("ry",ry*SVG.yunitlength);setStrokeAndFill(elmt.node,options);appendSVG(elmt)}function polygon(list,options){options=options||{};options.closed=true;path(list,options)}function rect(p,q,options){options=options||{};var elmt=getSVGElement(options.id,"rect");elmt.node.setAttribute("x",toSVG(p)[0]);elmt.node.setAttribute("y",toSVG(q)[1]);elmt.node.setAttribute("width",(q[0]-p[0])*SVG.xunitlength);elmt.node.setAttribute("height",(q[1]-p[1])*SVG.yunitlength);elmt.node.setAttribute("rx",getOption("rx",options)*SVG.xunitlength);elmt.node.setAttribute("ry",getOption("ry",options)*SVG.yunitlength);setStrokeAndFill(elmt.node,options);appendSVG(elmt)}function text(p,st,options){options=options||{};options.fill=options.fill||SVG.attr.fontfill;var id=options.id;var factor=(options.fixed)?1:SVG.factor;if(id&&options.isLabel){id+=options.isLabel}var pos=getOption("pos",options).toUpperCase();var fontsize=getOption("fontsize",options)/factor;var node,dx=0,dy=0,str=st.toString();var q=toSVG(p);if(/\$/.test(str)){var dnode=$("#"+SVG.id+"mml:first");if(id){node=$("#"+id)[0]}if(!node){node=MSVG.createElementXHTML("div",id);node.style.position="absolute";dnode.append(node)}else{$(node).empty()}str=$.trim(str);str=str.substr(1,str.length-2);$(node).append(MSVG.parseMath(str,true,fontsize+"px",options.fill));dx=-node.offsetWidth/2;dy=-node.offsetHeight/2;if(/N/.test(pos)){dy=-node.offsetHeight}if(/S/.test(pos)){dy=0}if(/E/.test(pos)){dx=0}if(/W/.test(pos)){dx=-node.offsetWidth}node.style.left=(q[0]+dx)+"px";node.style.top=(q[1]+dy)+"px"}else{var baseline="middle",textanchor="middle";if(/E/.test(pos)){textanchor="start"}if(/W/.test(pos)){textanchor="end"}if(/N/.test(pos)){baseline="text-after-edge"}if(/S/.test(pos)){baseline="text-before-edge"}var elmt=getSVGElement(id,"text");$(elmt.node).empty().text(str);elmt.node.setAttribute("x",q[0]);elmt.node.setAttribute("y",q[1]);elmt.node.setAttribute("font-style",getOption("fontstyle",options));elmt.node.setAttribute("font-family",getOption("fontfamily",options));elmt.node.setAttribute("font-weight",getOption("fontweight",options));elmt.node.setAttribute("font-size",fontsize);elmt.node.setAttribute("text-anchor",textanchor);elmt.node.setAttribute("dominant-baseline",baseline);options.stroke=getOption("fontstroke",options);setStrokeAndFill(elmt.node,options);appendSVG(elmt)}}function image(url,options){options=options||{};var elmt=getSVGElement(options.id,"image");var height=options.height||SVG.height;var width=options.width||SVG.width;var point=toSVG(options.point||[SVG.xmin,SVG.ymin]);var pos=(options.pos||"").toUpperCase();var x=point[0]-width*0.5;var y=point[1]-height*0.5;if(/N/.test(pos)){y-=height*0.5}if(/S/.test(pos)){y+=height*0.5}if(/E/.test(pos)){x+=width*0.5}if(/W/.test(pos)){x-=width*0.5}elmt.node.setAttribute("x",x);elmt.node.setAttribute("y",y);elmt.node.setAttribute("width",width);elmt.node.setAttribute("height",height);elmt.node.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",url);appendSVG(elmt)}function grid(options){options=options||{};var dx,dy,x,y,k,st="",start,stop,limit;var stroke=options.stroke||SVG.attr.gridstroke;var strokewidth=(options.strokewidth||SVG.attr.gridstrokewidth)/SVG.factor;var strokedasharray=getOption("strokedasharray",options);var strokeopacity=getOption("strokeopacity",options);if(SVG.coords=="polar"){dx=options.dx||1;dy=options.dy||3;var lim=Math.max(Math.abs(SVG.xmax),Math.abs(SVG.xmin),Math.abs(SVG.ymax),Math.abs(SVG.ymin));for(x=dx;x<lim;x+=dx){circle([0,0],x,{stroke:stroke,strokewidth:strokewidth,strokedasharray:strokedasharray,strokeopacity:strokeopacity})}if(dy>1){for(y=1;y<dy;y++){k=Math.tan(y*Math.PI/(2*dy));line([SVG.xmin,SVG.xmin*k],[SVG.xmax,SVG.xmax*k],{stroke:stroke,strokewidth:strokewidth,strokedasharray:strokedasharray,strokeopacity:strokeopacity});line([SVG.xmin,-SVG.xmin*k],[SVG.xmax,-SVG.xmax*k],{stroke:stroke,strokewidth:strokewidth,strokedasharray:strokedasharray,strokeopacity:strokeopacity})}}}else{dx=options.dx||1;dy=options.dy||dx;var gdx=dx*SVG.xunitlength;var gdy=dy*SVG.yunitlength;var border=SVG.borderwidth*0.5;var node=createSVGElement("path");node.setAttribute("class","svgGrid");start=SVG.origin[0];stop=SVG.width-border;limit=SVG.height-border;for(x=start;x<stop;x+=gdx){st+=" M"+x+","+border+" "+x+","+limit}start=SVG.origin[0]-gdx;for(x=start;x>border;x-=gdx){st+=" M"+x+","+border+" "+x+","+limit}start=SVG.height-SVG.origin[1];stop=SVG.height-border;limit=SVG.width-border;for(y=start;y<stop;y+=gdy){st+=" M"+border+","+y+" "+limit+","+y}start=SVG.height-SVG.origin[1]-gdy;for(y=start;y>border;y-=gdy){st+=" M"+border+","+y+" "+limit+","+y}node.setAttribute("d",st);node.setAttribute("stroke-width",strokewidth);node.setAttribute("stroke",stroke);node.setAttribute("stroke-dasharray",strokedasharray);node.setAttribute("stroke-opacity",strokeopacity);$(SVG.canvas).append(node)}}function axes(options){options=options||{};var x,y,start,stop;var orig=options.origin||[0,0];var origin=toSVG(orig);var dx=options.dx||1;var dy=options.dy||dx;var fontsize=getOption("fontsize",options);var border=SVG.borderwidth*0.5;var ddx=Math.max(0,Math.floor(-Math.log(dx+1e-9)/Math.log(10))+1);var ddy=Math.max(0,Math.floor(-Math.log(dy+1e-9)/Math.log(10))+1);options.marker="-|"+(options.marker||"-");options.strokewidth=(options.strokewidth||SVG.attr.axesstrokewidth)/SVG.factor;options.stroke=options.stroke||SVG.attr.axesstroke;var temp=options.stroke;options.markerstroke=options.stroke;options.markersize=fontsize*SVG.factor;var list1=[],label1=[];start=orig[0]+dx;stop=SVG.xmax-0.25*dx;for(x=start;x<stop;x+=dx){list1.push([x,orig[1]]);label1.push(String(x.toFixed(ddx)))}list1.push([SVG.xmax-border/SVG.xunitlength,orig[1]]);label1.push("");var list2=[],label2=[];start=orig[0]-dx;stop=SVG.xmin+0.25*dx;for(x=start;x>stop;x-=dx){list2.push([x,orig[1]]);label2.push(String(x.toFixed(ddx)))}list2.push([SVG.xmin+border/SVG.xunitlength,orig[1]]);label2.push("");list2.reverse();list2=list2.concat(list1);if(options.ticklabels!=false){label2.reverse();options.label=label2.concat(label1);options.pos=(SVG.height-origin[1]>2*fontsize)?"S":"N"}var group=getSVGElement("Axes","g");$(group.node).empty();var tempNode=SVG.canvas;SVG.canvas=group.node;path(list2,options);list1=[],label1=[];start=orig[1]+dy;stop=SVG.ymax-0.25*dy;for(y=start;y<stop;y+=dy){list1.push([orig[0],y]);label1.push(String(y.toFixed(ddy)))}list1.push([orig[0],SVG.ymax-border/SVG.yunitlength]);label1.push("");list2=[];label2=[];start=orig[1]-dy;stop=SVG.ymin+0.25*dy;for(y=start;y>stop;y-=dy){list2.push([orig[0],y]);label2.push(String(y.toFixed(ddy)))}list2.push([orig[0],SVG.ymin+border/SVG.yunitlength]);label2.push("");list2.reverse();list2=list2.concat(list1);if(options.ticklabels!=false){label2.reverse();options.label=label2.concat(label1);options.pos=(origin[0]>2*fontsize)?"W":"E"}options.stroke=temp;path(list2,options);SVG.canvas=tempNode;appendSVG(group)}function list(fun,tmin,tmax,points){var inc=(tmax-tmin)/points;if(inc<=0||fun.length==0){return}var t,pth,g=[],xt,yt;for(t=1;t>=0;t--){if($.isFunction(fun[t])){g[t]=fun[t]}else{if(typeof fun[t]=="string"){with(Math){eval("g["+t+"] = function(x){return "+fun[t]+"}")}}else{return}}}if(g.length<2){return}pth=[];for(t=tmin;t<=tmax;t+=inc){xt=g[0](t);yt=g[1](t);if(isFinite(xt)&&isFinite(yt)){pth[pth.length]=[xt,yt]}}return pth}function plot(fun,options){options=options||{};var i,steps=options.steps||[];var leftMarkers=options.leftMarkers||"-";var rightMarkers=options.rightMarkers||"-";if(steps.length===0){plotter(fun,options)}else{var n_steps=steps.length-1;options.max=steps[0];options.marker="--"+leftMarkers.charAt(0);plotter(fun,options);for(i=0;i<n_steps;i++){options.max=steps[i+1];options.min=steps[i];options.marker=rightMarkers.charAt((rightMarkers.length>i)?i:0)+"-"+leftMarkers.charAt((leftMarkers.length>i+1)?i+1:0);plotter(fun,options)}options.max=null;options.min=steps[n_steps];options.marker=rightMarkers.charAt((rightMarkers.length==n_steps)?n_steps-1:0)+"--";plotter(fun,options)}}function plotter(fun,options){options=options||{};options.closed=false;options.curve="";var xmin=(options.min==null)?SVG.xmin:options.min;var xmax=(options.max==null)?SVG.xmax:options.max;var points=getOption("points",options);var pth=list(["x",fun],xmin,xmax,points);if(pth){path(pth,options)}}function area(fun1,fun2,options){options=options||{};options.curve="";options.closed=true;var xmin=(options.min==null)?SVG.xmin:options.min;var xmax=(options.max==null)?SVG.xmax:options.max;var points=getOption("points",options);var pth1=list(["x",fun1],xmin,xmax,points);var pth2=list(["x",fun2],xmin,xmax,points);if(pth1&&pth2){pth2.reverse();pth1=pth1.concat(pth2);path(pth1,options)}}function polarPlot(fun,options){var g1,g2;if(typeof fun=="string"){with(Math){eval("g1 = function(x){return ("+fun+")*cos(x)}");eval("g2 = function(x){return ("+fun+")*sin(x)}")}}else{if($.isFunction(fun)){with(Math){eval("g1 = function(x){return fun(x)*cos(x)}");eval("g2 = function(x){return fun(x)*sin(x)}")}}}parametricPlot(g1,g2,options)}function parametricPlot(fun1,fun2,options){options=options||{};options.closed=false;options.curve="";var xmin=(options.min==null)?0:options.min;var xmax=(options.max==null)?2*Math.PI:options.max;var points=getOption("points",options);var pth=list([fun1,fun2],xmin,xmax,points);if(pth){path(pth,options)}}function slopeField(fun,options){options=options||{};var g=fun;if(typeof fun=="string"){with(Math){eval("g = function(x,y){return "+fun+"}")}}var gxy,x,y,u,v,dz;var dx=(options.dx==null)?1:options.dx;var dy=(options.dy==null)?1:options.dy;dz=Math.sqrt(dx*dx+dy*dy)/6;var xmin=Math.ceil(SVG.xmin/dx);var ymin=Math.ceil(SVG.ymin/dy);for(x=xmin;x<=SVG.xmax;x+=dx){for(y=ymin;y<=SVG.ymax;y+=dy){gxy=g(x,y);if(!isNaN(gxy)){if(Math.abs(gxy)=="Infinity"){u=0;v=dz}else{u=dz/Math.sqrt(1+gxy*gxy);v=gxy*u}line([x-u,y-v],[x+u,y+v],options)}}}}return{dynamic:{},removePictures:function(obj){var pictures=obj?[obj]:$(".svgGraph");$(pictures).each(function(){var target=this.parentNode;$(this).remove();$(target).css({color:"red",background:"yellow"});$(target).text("Missing picture: your browser does not support inline SVG");window.setTimeout(function(){$(target).remove()},10000)})},drawPictures:function(obj){var options,xmin,xmax,ymin,ymax;var pictures=obj?[obj]:$(".svgGraph");$(pictures).each(function(){SVG=new pictureObject();options=this.getAttribute("options");if(options!=""){with(Math){eval("options="+options)}setOptions(options)}else{options={}}SVG.width=options.width||SVG.width;SVG.height=options.height||SVG.height;SVG.coords=options.coords||SVG.coords;SVG.borderwidth=options.borderwidth||SVG.borderwidth;SVG.borderstroke=options.borderstroke||SVG.borderstroke;if(options.pan==false){SVG.pan=false}SVG.src=this.getAttribute("script");var container=this.parentNode;container.removeChild(this);options.scales=options.scales||[];switch(options.scales.length){case 0:xmin=SVG.xmin;xmax=SVG.xmax;ymin=null;ymax=null;break;case 2:xmin=options.scales[0];xmax=options.scales[1];ymin=null;ymax=null;break;case 4:xmin=options.scales[0];xmax=options.scales[1];ymin=options.scales[2];ymax=options.scales[3];break;default:return}if(xmin>=xmax){throw"Incorrect values: xmax<=xmin."}var xunitlength=SVG.width/(xmax-xmin);if(typeof ymin!="number"){ymin=-SVG.height/(2*xunitlength);ymax=-ymin}if(ymin>=ymax){throw"Incorrect values: ymax<=ymin."}SVG.xmin=xmin;SVG.xmax=xmax;SVG.ymin=ymin;SVG.ymax=ymax;setScales();SVG.id=Math.randomString(chars,20);var qnode=createSVGElement("svg");qnode.id=SVG.id;qnode.setAttribute("xmlns","http://www.w3.org/2000/svg");var node=createSVGElement("clipPath");node.id=SVG.id+"ClipPath";var node2=createSVGElement("path");$(node).append(node2);node2=createSVGElement("defs");node2.id=SVG.id+"_Defs";$(node2).append(node);$(qnode).append(node2);node=createSVGElement("rect");node.setAttribute("class","svgBackground");node.setAttribute("x","0");node.setAttribute("y","0");node.setAttribute("width","100%");node.setAttribute("height","100%");node.setAttribute("stroke",SVG.borderstroke);node.setAttribute("stroke-width",SVG.borderwidth);node.setAttribute("fill",SVG.attr.backgroundcolor);node.setAttribute("fill-opacity",SVG.attr.backgroundopacity);$(qnode).append(node);node=createSVGElement("g");node.id=SVG.id+"Canvas";node.setAttribute("clip-path","url(#"+SVG.id+"ClipPath)");SVG.canvas=node;$(qnode).append(node);if(SVG.coords!="none"){node=createSVGElement("text");node.id=SVG.id+"Coords";node.setAttribute("class","svgCoords");node.setAttribute("text-anchor","end");node.setAttribute("font-size",(SVG.attr.fontsize*0.8));$(qnode).append(node)}$(container).append(qnode);container.style.position="relative";node=MSVG.createElementXHTML("span",SVG.id+"mml");$(container).append(node);node=MSVG.createElementXHTML("span",SVG.id+"toolbar");node.style.position="absolute";node.style.textAlign="left";node.style.zIndex=10;node2=setButton("Update","Edit script",function(){updateButton(this)});$(node).append(node2);node2=setButton("SVG","View SVG code",function(){exportSVG(this)});$(node).append(node2);node2=setButton("-","Zoom out",function(){changeScales(1.25)});$(node).append(node2);node2=setButton("+","Zoom in",function(){changeScales(0.8)});$(node).append(node2);node2=setButton("\u2191","Enlarge picture",function(){changeSize(0.8)});$(node).append(node2);node2=setButton("\u2193","Reduce picture",function(){changeSize(1.25)});$(node).append(node2);$(node).append("<br />");node2=MSVG.createElementXHTML("textarea",SVG.id+"src");$(node2).attr({rows:8,cols:80});$(node).append(node2);$(node).hide();$(container).append(node);setAction("mousemove",updateCoord);setAction("mouseout",removeCoord);setAction("mouseover",switchTo);setAction("mousedown",onClick);if(SVG.pan){setAction("mouseup",onDrop)}if(window.addEventListener){var evt=$.browser.mozilla?"DOMMouseScroll":"mousewheel";qnode.addEventListener(evt,onWheel,false)}setSize();translateAndEval(SVG.id)})}}}(jQuery);
//}}}
/***
!~TiddlyWiki formatters
***/
//{{{
if(!version.extensions.MathSVGPlugin) { //# ensure that the plugin is only installed once
version.extensions.MathSVGPlugin = {installed: true};
MSVG.generic();
config.formatterHelpers.MathSVGHelper = function(w) {
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch){
var eq = MSVG.parseMath(lookaheadMatch[1],this.displaystyle);
if(this.displaystyle){
var node = createTiddlyElement(w.output,"div");
node.style.textAlign='center';
node.appendChild(eq);
w.output.appendChild(node);
} else {w.output.appendChild(eq);}
w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length;
}
}
config.formatters.push( {
name: "clatex",
match: "\\$\\$",
lookaheadRegExp: /\$\$((?:.|\n)*?)\$\$/mg,
displaystyle: true,
handler: config.formatterHelpers.MathSVGHelper
})
config.formatters.push( {
name: "clatex2",
match: "\\\\\\\[",
lookaheadRegExp: /\\\[\s*(.*?)\s*\\\]/mg,
displaystyle: true,
handler: config.formatterHelpers.MathSVGHelper
})
config.formatters.push( {
name: "latex",
match: "\\$",
lookaheadRegExp: /\$((?:.|\n)*?)\$/mg,
displaystyle: false,
handler: config.formatterHelpers.MathSVGHelper
})
config.formatters.push( {
name: "graph",
match: "\\(:graph",
lookaheadRegExp: /\(:graph(\((.*?),?\s?(\{.+\})?\))?[\s]+((?:.|\n)*?)[\s]+:\)/mg,
handler: function(w){
this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source);
if(lookaheadMatch){
var element = (lookaheadMatch[2] == "inline") ? "span" : "div";
var eq = createTiddlyElement(w.output,element);
switch(lookaheadMatch[2]){
case "center":
eq.style.marginLeft = "auto";
eq.style.marginRight = "auto";
break;
case "left":
eq.style.cssFloat = "left";
break;
case "right":
eq.style.cssFloat = "right";
}
var svg = createTiddlyElement(eq,"embed");
svg.className="svgGraph";
svg.setAttribute('options',lookaheadMatch[3]||"");
svg.setAttribute('script',lookaheadMatch[4]);
ASVG.drawPictures(svg);
w.nextMatch = lookaheadMatch.index + lookaheadMatch[0].length;
}
}
})
}
//}}}
/***
|''Name:''|ProcessingPlugin|
|''Description:''|TiddlyWiki Bundle of John Ressig's processing.js|
|''Date:''|May 9, 2008|
|''Author:''|PaulDowney (psd (at) osmosoft (dot) com)|
|''CodeRepository:''|http://svn.tiddlywiki.org/Trunk/contributors/PaulDowney/plugins/ProcessingPlugin.js|
|''Version:''|0.2|
|''License:''|[[MIT license]]|
|''Comments:''|Please make comments at http://groups.google.co.uk/group/TiddlyWikiDev |
|''~CoreVersion:''|2.2|
With contributions from Simon Baird.
***/
//{{{
// Ensure Plugin is only installed once.
if(!version.extensions.Processingjs) {
version.extensions.Processingjs = {installed:true};
config.macros.Processing = {
counter: 0,
handler: function (place,macroName,params,wikifier,paramString,tiddler) {
var id = "processingcanvas"+this.counter;
var canvas = createTiddlyElement(place,"canvas",id);
// inlined code
var code = paramString;
// quick and dirty grab of code from a named tiddler
if (store.tiddlerExists(params[0])) {
code = store.getTiddlerText(params[0]);
}
// or with no params, grab code from this tiddler
if (paramString.trim() == '') {
code = tiddler.text;
}
createTiddlyElement(place,"br");
var restartBtn = createTiddlyButton(place,"restart","restart",function() {
story.refreshTiddler(tiddler.title,null,true);
return false;
},
'processingRestart' // it's a class so you can style the button
);
Processing(canvas,code);
}
};
// requires 2.4
merge(config.macros.view.views,{
processing: function(value,place,params,wikifier,paramString,tiddler) {
wikify("<<Processing\n"+value+"\n>>",place,highlightHack,tiddler);
}
});
/*
* inlined copy of Processing.js
* latest code at: http://ejohn.org/blog/processingjs/
*/
/*
* Processing.js - John Resig (http://ejohn.org/)
* MIT Licensed
* http://ejohn.org/blog/processingjs/
*
* This is a port of the Processing Visualization Language.
* More information: http://processing.org/
*/
(function(){
this.Processing = function Processing( aElement, aCode )
{
var p = buildProcessing( aElement );
p.init( aCode );
return p;
};
function log()
{
try
{
console.log.apply( console, arguments );
}
catch(e)
{
try
{
opera.postError.apply( opera, arguments );
}
catch(e){}
}
}
function parse( aCode, p )
{
// Angels weep at this parsing code :-(
// Remove end-of-line comments
aCode = aCode.replace(/\/\/ .*\n/g, "\n");
// Weird parsing errors with %
aCode = aCode.replace(/([^\s])%([^\s])/g, "$1 % $2");
// Simple convert a function-like thing to function
aCode = aCode.replace(/(?:static )?(\w+ )(\w+)\s*(\([^\)]*\)\s*{)/g, function(all, type, name, args)
{
if ( name == "if" || name == "for" || name == "while" )
{
return all;
}
else
{
return "Processing." + name + " = function " + name + args;
}
});
// Force .length() to be .length
aCode = aCode.replace(/\.length\(\)/g, ".length");
// foo( int foo, float bar )
aCode = aCode.replace(/([\(,]\s*)(\w+)((?:\[\])+| )\s*(\w+\s*[\),])/g, "$1$4");
aCode = aCode.replace(/([\(,]\s*)(\w+)((?:\[\])+| )\s*(\w+\s*[\),])/g, "$1$4");
// float[] foo = new float[5];
aCode = aCode.replace(/new (\w+)((?:\[([^\]]*)\])+)/g, function(all, name, args)
{
return "new ArrayList(" + args.slice(1,-1).split("][").join(", ") + ")";
});
aCode = aCode.replace(/(?:static )?\w+\[\]\s*(\w+)\[?\]?\s*=\s*{.*?};/g, function(all)
{
return all.replace(/{/g, "[").replace(/}/g, "]");
});
// int|float foo;
var intFloat = /(\n\s*(?:int|float)(?:\[\])?(?:\s*|[^\(]*?,\s*))([a-z]\w*)(;|,)/i;
while ( intFloat.test(aCode) )
{
aCode = aCode.replace(new RegExp(intFloat), function(all, type, name, sep)
{
return type + " " + name + " = 0" + sep;
});
}
// float foo = 5;
aCode = aCode.replace(/(?:static )?(\w+)((?:\[\])+| ) *(\w+)\[?\]?(\s*[=,;])/g, function(all, type, arr, name, sep)
{
if ( type == "return" )
return all;
else
return "var " + name + sep;
});
// Fix Array[] foo = {...} to [...]
aCode = aCode.replace(/=\s*{((.|\s)*?)};/g, function(all,data)
{
return "= [" + data.replace(/{/g, "[").replace(/}/g, "]") + "]";
});
// static { ... } blocks
aCode = aCode.replace(/static\s*{((.|\n)*?)}/g, function(all, init)
{
// Convert the static definitons to variable assignments
//return init.replace(/\((.*?)\)/g, " = $1");
return init;
});
// super() is a reserved word
aCode = aCode.replace(/super\(/g, "superMethod(");
var classes = ["int", "float", "boolean", "string"];
function ClassReplace(all, name, extend, vars, last)
{
classes.push( name );
var static = "";
vars = vars.replace(/final\s+var\s+(\w+\s*=\s*.*?;)/g, function(all,set)
{
static += " " + name + "." + set;
return "";
});
// Move arguments up from constructor and wrap contents with
// a with(this), and unwrap constructor
return "function " + name + "() {with(this){\n " +
(extend ? "var __self=this;function superMethod(){extendClass(__self,arguments," + extend + ");}\n" : "") +
// Replace var foo = 0; with this.foo = 0;
// and force var foo; to become this.foo = null;
vars
.replace(/,\s?/g, ";\n this.")
.replace(/\b(var |final |public )+\s*/g, "this.")
.replace(/this.(\w+);/g, "this.$1 = null;") +
(extend ? "extendClass(this, " + extend + ");\n" : "") +
"<CLASS " + name + " " + static + ">" + (typeof last == "string" ? last : name + "(");
}
var matchClasses = /(?:public |abstract |static )*class (\w+)\s*(?:extends\s*(\w+)\s*)?{\s*((?:.|\n)*?)\b\1\s*\(/g;
var matchNoCon = /(?:public |abstract |static )*class (\w+)\s*(?:extends\s*(\w+)\s*)?{\s*((?:.|\n)*?)(Processing)/g;
aCode = aCode.replace(matchClasses, ClassReplace);
aCode = aCode.replace(matchNoCon, ClassReplace);
var matchClass = /<CLASS (\w+) (.*?)>/, m;
while ( (m = aCode.match( matchClass )) )
{
var left = RegExp.leftContext,
allRest = RegExp.rightContext,
rest = nextBrace(allRest),
className = m[1],
staticVars = m[2] || "";
allRest = allRest.slice( rest.length + 1 );
rest = rest.replace(new RegExp("\\b" + className + "\\(([^\\)]*?)\\)\\s*{", "g"), function(all, args)
{
args = args.split(/,\s*?/);
if ( args[0].match(/^\s*$/) )
args.shift();
var fn = "if ( arguments.length == " + args.length + " ) {\n";
for ( var i = 0; i < args.length; i++ )
{
fn += " var " + args[i] + " = arguments[" + i + "];\n";
}
return fn;
});
// Fix class method names
// this.collide = function() { ... }
// and add closing } for with(this) ...
rest = rest.replace(/(?:public )?Processing.\w+ = function (\w+)\((.*?)\)/g, function(all, name, args)
{
return "ADDMETHOD(this, '" + name + "', function(" + args + ")";
});
var matchMethod = /ADDMETHOD([\s\S]*?{)/, mc;
var methods = "";
while ( (mc = rest.match( matchMethod )) )
{
var prev = RegExp.leftContext,
allNext = RegExp.rightContext,
next = nextBrace(allNext);
methods += "addMethod" + mc[1] + next + "});"
rest = prev + allNext.slice( next.length + 1 );
}
rest = methods + rest;
aCode = left + rest + "\n}}" + staticVars + allRest;
}
// Do some tidying up, where necessary
aCode = aCode.replace(/Processing.\w+ = function addMethod/g, "addMethod");
function nextBrace( right )
{
var rest = right;
var position = 0;
var leftCount = 1, rightCount = 0;
while ( leftCount != rightCount )
{
var nextLeft = rest.indexOf("{");
var nextRight = rest.indexOf("}");
if ( nextLeft < nextRight && nextLeft != -1 )
{
leftCount++;
rest = rest.slice( nextLeft + 1 );
position += nextLeft + 1;
}
else
{
rightCount++;
rest = rest.slice( nextRight + 1 );
position += nextRight + 1;
}
}
return right.slice(0, position - 1);
}
// Handle (int) Casting
aCode = aCode.replace(/\(int\)/g, "0|");
// Remove Casting
aCode = aCode.replace(new RegExp("\\((" + classes.join("|") + ")(\\[\\])?\\)", "g"), "");
// Convert 3.0f to just 3.0
aCode = aCode.replace(/(\d+)f/g, "$1");
// Force numbers to exist
//aCode = aCode.replace(/([^.])(\w+)\s*\+=/g, "$1$2 = ($2||0) +");
// Force characters-as-bytes to work
aCode = aCode.replace(/('[a-zA-Z0-9]')/g, "$1.charCodeAt(0)");
// Convert #aaaaaa into color
aCode = aCode.replace(/#([a-f0-9]{6})/ig, function(m, hex){
var num = toNumbers(hex);
return "color(" + num[0] + "," + num[1] + "," + num[2] + ")";
});
function toNumbers( str ){
var ret = [];
str.replace(/(..)/g, function(str){
ret.push( parseInt( str, 16 ) );
});
return ret;
}
//log(aCode);
return aCode;
}
function buildProcessing( curElement ){
var p = {};
// init
p.PI = Math.PI;
p.TWO_PI = 2 * p.PI;
p.HALF_PI = p.PI / 2;
p.P3D = 3;
p.CORNER = 0;
p.CENTER = 1;
p.CENTER_RADIUS = 2;
p.RADIUS = 2;
p.POLYGON = 1;
p.TRIANGLES = 6;
p.POINTS = 7;
p.LINES = 8;
p.TRIANGLE_STRIP = 9;
p.CORNERS = 10;
p.CLOSE = true;
p.RGB = 1;
p.HSB = 2;
// "Private" variables used to maintain state
var curContext = curElement.getContext("2d");
var doFill = true;
var doStroke = true;
var loopStarted = false;
var hasBackground = false;
var doLoop = true;
var curRectMode = p.CORNER;
var curEllipseMode = p.CENTER;
var inSetup = false;
var inDraw = false;
var curBackground = "rgba(204,204,204,1)";
var curFrameRate = 1000;
var curShape = p.POLYGON;
var curShapeCount = 0;
var opacityRange = 255;
var redRange = 255;
var greenRange = 255;
var blueRange = 255;
var pathOpen = false;
var mousePressed = false;
var keyPressed = false;
var firstX, firstY, prevX, prevY;
var curColorMode = p.RGB;
var curTint = -1;
var curTextSize = 12;
var curTextFont = "Arial";
var getLoaded = false;
var start = (new Date).getTime();
// Global vars for tracking mouse position
p.pmouseX = 0;
p.pmouseY = 0;
p.mouseX = 0;
p.mouseY = 0;
// Will be replaced by the user, most likely
p.mouseDragged = undefined;
p.mouseMoved = undefined;
p.mousePressed = undefined;
p.mouseReleased = undefined;
p.keyPressed = undefined;
p.keyReleased = undefined;
p.draw = undefined;
p.setup = undefined;
// The height/width of the canvas
p.width = curElement.width - 0;
p.height = curElement.height - 0;
// In case I ever need to do HSV conversion:
// http://srufaculty.sru.edu/david.dailey/javascript/js/5rml.js
p.color = function color( aValue1, aValue2, aValue3, aValue4 )
{
var aColor = "";
if ( arguments.length == 3 )
{
aColor = p.color( aValue1, aValue2, aValue3, opacityRange );
}
else if ( arguments.length == 4 )
{
var a = aValue4 / opacityRange;
a = isNaN(a) ? 1 : a;
if ( curColorMode == p.HSB )
{
var rgb = HSBtoRGB(aValue1, aValue2, aValue3);
var r = rgb[0], g = rgb[1], b = rgb[2];
}
else
{
var r = getColor(aValue1, redRange);
var g = getColor(aValue2, greenRange);
var b = getColor(aValue3, blueRange);
}
aColor = "rgba(" + r + "," + g + "," + b + "," + a + ")";
}
else if ( typeof aValue1 == "string" )
{
aColor = aValue1;
if ( arguments.length == 2 )
{
var c = aColor.split(",");
c[3] = (aValue2 / opacityRange) + ")";
aColor = c.join(",");
}
}
else if ( arguments.length == 2 )
{
aColor = p.color( aValue1, aValue1, aValue1, aValue2 );
}
else if ( typeof aValue1 == "number" )
{
aColor = p.color( aValue1, aValue1, aValue1, opacityRange );
}
else
{
aColor = p.color( redRange, greenRange, blueRange, opacityRange );
}
// HSB conversion function from Mootools, MIT Licensed
function HSBtoRGB(h, s, b)
{
h = (h / redRange) * 100;
s = (s / greenRange) * 100;
b = (b / blueRange) * 100;
if (s == 0){
return [b, b, b];
} else {
var hue = h % 360;
var f = hue % 60;
var br = Math.round(b / 100 * 255);
var p = Math.round((b * (100 - s)) / 10000 * 255);
var q = Math.round((b * (6000 - s * f)) / 600000 * 255);
var t = Math.round((b * (6000 - s * (60 - f))) / 600000 * 255);
switch (Math.floor(hue / 60)){
case 0: return [br, t, p];
case 1: return [q, br, p];
case 2: return [p, br, t];
case 3: return [p, q, br];
case 4: return [t, p, br];
case 5: return [br, p, q];
}
}
}
function getColor( aValue, range )
{
return Math.round(255 * (aValue / range));
}
return aColor;
}
p.nf = function( num, pad )
{
var str = "" + num;
while ( pad - str.length )
str = "0" + str;
return str;
};
p.AniSprite = function( prefix, frames )
{
this.images = [];
this.pos = 0;
for ( var i = 0; i < frames; i++ )
{
this.images.push( prefix + p.nf( i, ("" + frames).length ) + ".gif" );
}
this.display = function( x, y )
{
p.image( this.images[ this.pos ], x, y );
if ( ++this.pos >= frames )
this.pos = 0;
};
this.getWidth = function()
{
return getImage(this.images[0]).width;
};
this.getHeight = function()
{
return getImage(this.images[0]).height;
};
};
function buildImageObject( obj )
{
var pixels = obj.data;
var data = p.createImage( obj.width, obj.height );
if ( data.__defineGetter__ && data.__lookupGetter__ && !data.__lookupGetter__("pixels") )
{
var pixelsDone;
data.__defineGetter__("pixels", function()
{
if ( pixelsDone )
return pixelsDone;
pixelsDone = [];
for ( var i = 0; i < pixels.length; i += 4 )
{
pixelsDone.push( p.color(pixels[i], pixels[i+1], pixels[i+2], pixels[i+3]) );
}
return pixelsDone;
});
}
else
{
data.pixels = [];
for ( var i = 0; i < pixels.length; i += 4 )
{
data.pixels.push( p.color(pixels[i], pixels[i+1], pixels[i+2], pixels[i+3]) );
}
}
return data;
}
p.createImage = function createImage( w, h, mode )
{
var data = {
width: w,
height: h,
pixels: new Array( w * h ),
get: function(x,y)
{
return this.pixels[w*y+x];
},
_mask: null,
mask: function(img)
{
this._mask = img;
},
loadPixels: function()
{
},
updatePixels: function()
{
}
};
return data;
}
p.createGraphics = function createGraphics( w, h )
{
var canvas = document.createElement("canvas");
var ret = buildProcessing( canvas );
ret.size( w, h );
ret.canvas = canvas;
return ret;
}
p.beginDraw = function beginDraw()
{
}
p.endDraw = function endDraw()
{
}
p.tint = function tint( rgb, a )
{
curTint = a;
}
function getImage( img ) {
if ( typeof img == "string" )
{
return document.getElementById(img);
}
if ( img.img || img.canvas )
{
return img.img || img.canvas;
}
img.data = [];
for ( var i = 0, l = img.pixels.length; i < l; i++ )
{
var c = (img.pixels[i] || "rgba(0,0,0,1)").slice(5,-1).split(",");
img.data.push( parseInt(c[0]), parseInt(c[1]), parseInt(c[2]), parseFloat(c[3]) * 100 );
}
var canvas = document.createElement("canvas")
canvas.width = img.width;
canvas.height = img.height;
var context = canvas.getContext("2d");
context.putImageData( img, 0, 0 );
img.canvas = canvas;
return canvas;
}
p.image = function image( img, x, y, w, h )
{
x = x || 0;
y = y || 0;
var obj = getImage(img);
if ( curTint >= 0 )
{
var oldAlpha = curContext.globalAlpha;
curContext.globalAlpha = curTint / opacityRange;
}
if ( arguments.length == 3 )
{
curContext.drawImage( obj, x, y );
}
else
{
curContext.drawImage( obj, x, y, w, h );
}
if ( curTint >= 0 )
{
curContext.globalAlpha = oldAlpha;
}
if ( img._mask )
{
var oldComposite = curContext.globalCompositeOperation;
curContext.globalCompositeOperation = "darker";
p.image( img._mask, x, y );
curContext.globalCompositeOperation = oldComposite;
}
}
p.exit = function exit()
{
}
p.save = function save( file )
{
}
p.loadImage = function loadImage( file )
{
var img = document.getElementById(file);
if ( !img )
return;
var h = img.height, w = img.width;
var canvas = document.createElement("canvas");
canvas.width = w;
canvas.height = h;
var context = canvas.getContext("2d");
context.drawImage( img, 0, 0 );
var data = buildImageObject( context.getImageData( 0, 0, w, h ) );
data.img = img;
return data;
}
p.loadFont = function loadFont( name )
{
return {
name: name,
width: function( str )
{
if ( curContext.mozMeasureText )
return curContext.mozMeasureText( typeof str == "number" ?
String.fromCharCode( str ) :
str) / curTextSize;
else
return 0;
}
};
}
p.textFont = function textFont( name, size )
{
curTextFont = name;
p.textSize( size );
}
p.textSize = function textSize( size )
{
if ( size )
{
curTextSize = size;
}
}
p.textAlign = function textAlign()
{
}
p.text = function text( str, x, y )
{
if ( str && curContext.mozDrawText )
{
curContext.save();
curContext.mozTextStyle = curTextSize + "px " + curTextFont.name;
curContext.translate(x, y);
curContext.mozDrawText( typeof str == "number" ?
String.fromCharCode( str ) :
str );
curContext.restore();
}
}
p.char = function char( key )
{
//return String.fromCharCode( key );
return key;
}
p.println = function println()
{
}
p.map = function map( value, istart, istop, ostart, ostop )
{
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
};
String.prototype.replaceAll = function(re, replace)
{
return this.replace(new RegExp(re, "g"), replace);
};
p.Point = function Point( x, y )
{
this.x = x;
this.y = y;
this.copy = function()
{
return new Point( x, y );
}
}
p.Random = function()
{
var haveNextNextGaussian = false;
var nextNextGaussian;
this.nextGaussian = function()
{
if (haveNextNextGaussian) {
haveNextNextGaussian = false;
return nextNextGaussian;
} else {
var v1, v2, s;
do {
v1 = 2 * p.random(1) - 1; // between -1.0 and 1.0
v2 = 2 * p.random(1) - 1; // between -1.0 and 1.0
s = v1 * v1 + v2 * v2;
} while (s >= 1 || s == 0);
var multiplier = Math.sqrt(-2 * Math.log(s)/s);
nextNextGaussian = v2 * multiplier;
haveNextNextGaussian = true;
return v1 * multiplier;
}
};
}
p.ArrayList = function ArrayList( size, size2, size3 )
{
var array = new Array( 0 | size );
if ( size2 )
{
for ( var i = 0; i < size; i++ )
{
array[i] = [];
for ( var j = 0; j < size2; j++ )
{
var a = array[i][j] = size3 ? new Array( size3 ) : 0;
for ( var k = 0; k < size3; k++ )
{
a[k] = 0;
}
}
}
}
else
{
for ( var i = 0; i < size; i++ )
{
array[i] = 0;
}
}
array.size = function()
{
return this.length;
};
array.get = function( i )
{
return this[ i ];
};
array.remove = function( i )
{
return this.splice( i, 1 );
};
array.add = function( item )
{
for ( var i = 0; this[ i ] != undefined; i++ ) {}
this[ i ] = item;
};
array.clone = function()
{
var a = new ArrayList( size );
for ( var i = 0; i < size; i++ )
{
a[ i ] = this[ i ];
}
return a;
};
array.isEmpty = function()
{
return !this.length;
};
array.clear = function()
{
this.length = 0;
};
return array;
}
p.colorMode = function colorMode( mode, range1, range2, range3, range4 )
{
curColorMode = mode;
if ( arguments.length >= 4 )
{
redRange = range1;
greenRange = range2;
blueRange = range3;
}
if ( arguments.length == 5 )
{
opacityRange = range4;
}
if ( arguments.length == 2 )
{
p.colorMode( mode, range1, range1, range1, range1 );
}
}
p.beginShape = function beginShape( type )
{
curShape = type;
curShapeCount = 0;
}
p.endShape = function endShape( close )
{
if ( curShapeCount != 0 )
{
curContext.lineTo( firstX, firstY );
if ( doFill )
curContext.fill();
if ( doStroke )
curContext.stroke();
curContext.closePath();
curShapeCount = 0;
pathOpen = false;
}
if ( pathOpen )
{
curContext.closePath();
}
}
p.vertex = function vertex( x, y, x2, y2, x3, y3 )
{
if ( curShapeCount == 0 && curShape != p.POINTS )
{
pathOpen = true;
curContext.beginPath();
curContext.moveTo( x, y );
}
else
{
if ( curShape == p.POINTS )
{
p.point( x, y );
}
else if ( arguments.length == 2 )
{
if ( curShape == p.TRIANGLE_STRIP && curShapeCount == 2 )
{
curContext.moveTo( prevX, prevY );
curContext.lineTo( firstX, firstY );
}
curContext.lineTo( x, y );
}
else if ( arguments.length == 4 )
{
if ( curShapeCount > 1 )
{
curContext.moveTo( prevX, prevY );
curContext.quadraticCurveTo( firstX, firstY, x, y );
curShapeCount = 1;
}
}
else if ( arguments.length == 6 )
{
curContext.bezierCurveTo( x, y, x2, y2, x3, y3 );
curShapeCount = -1;
}
}
prevX = firstX;
prevY = firstY;
firstX = x;
firstY = y;
curShapeCount++;
if ( curShape == p.LINES && curShapeCount == 2 ||
(curShape == p.TRIANGLES || curShape == p.TRIANGLE_STRIP) && curShapeCount == 3 )
{
p.endShape();
}
if ( curShape == p.TRIANGLE_STRIP && curShapeCount == 3 )
{
curShapeCount = 2;
}
}
p.curveTightness = function()
{
}
// Unimplmented - not really possible with the Canvas API
p.curveVertex = function( x, y, x2, y2 )
{
p.vertex( x, y, x2, y2 );
}
p.bezierVertex = p.vertex
p.rectMode = function rectMode( aRectMode )
{
curRectMode = aRectMode;
}
p.imageMode = function()
{
}
p.ellipseMode = function ellipseMode( aEllipseMode )
{
curEllipseMode = aEllipseMode;
}
p.dist = function dist( x1, y1, x2, y2 )
{
return Math.sqrt( Math.pow( x2 - x1, 2 ) + Math.pow( y2 - y1, 2 ) );
}
p.year = function year()
{
return (new Date).getYear() + 1900;
}
p.month = function month()
{
return (new Date).getMonth();
}
p.day = function day()
{
return (new Date).getDay();
}
p.hour = function hour()
{
return (new Date).getHours();
}
p.minute = function minute()
{
return (new Date).getMinutes();
}
p.second = function second()
{
return (new Date).getSeconds();
}
p.millis = function millis()
{
return (new Date).getTime() - start;
}
p.ortho = function ortho()
{
}
p.translate = function translate( x, y )
{
curContext.translate( x, y );
}
p.scale = function scale( x, y )
{
curContext.scale( x, y || x );
}
p.rotate = function rotate( aAngle )
{
curContext.rotate( aAngle );
}
p.pushMatrix = function pushMatrix()
{
curContext.save();
}
p.popMatrix = function popMatrix()
{
curContext.restore();
}
p.redraw = function redraw()
{
if ( hasBackground )
{
p.background();
}
inDraw = true;
p.pushMatrix();
p.draw();
p.popMatrix();
inDraw = false;
}
p.loop = function loop()
{
if ( loopStarted )
return;
var looping = setInterval(function()
{
try
{
p.redraw();
}
catch(e)
{
clearInterval( looping );
throw e;
}
}, 1000 / curFrameRate );
loopStarted = true;
}
p.frameRate = function frameRate( aRate )
{
curFrameRate = aRate;
}
p.background = function background( img )
{
if ( arguments.length )
{
if ( img && img.img )
{
curBackground = img;
}
else
{
curBackground = p.color.apply( this, arguments );
}
}
if ( curBackground.img )
{
p.image( curBackground, 0, 0 );
}
else
{
var oldFill = curContext.fillStyle;
curContext.fillStyle = curBackground + "";
curContext.fillRect( 0, 0, p.width, p.height );
curContext.fillStyle = oldFill;
}
}
p.sq = function sq( aNumber )
{
return aNumber * aNumber;
}
p.sqrt = function sqrt( aNumber )
{
return Math.sqrt( aNumber );
}
p.int = function int( aNumber )
{
return Math.floor( aNumber );
}
p.min = function min( aNumber, aNumber2 )
{
return Math.min( aNumber, aNumber2 );
}
p.max = function max( aNumber, aNumber2 )
{
return Math.max( aNumber, aNumber2 );
}
p.ceil = function ceil( aNumber )
{
return Math.ceil( aNumber );
}
p.floor = function floor( aNumber )
{
return Math.floor( aNumber );
}
p.float = function float( aNumber )
{
return typeof aNumber == "string" ?
p.float( aNumber.charCodeAt(0) ) :
parseFloat( aNumber );
}
p.byte = function byte( aNumber )
{
return aNumber || 0;
}
p.random = function random( aMin, aMax )
{
return arguments.length == 2 ?
aMin + (Math.random() * (aMax - aMin)) :
Math.random() * aMin;
}
// From: http://freespace.virgin.net/hugo.elias/models/m_perlin.htm
p.noise = function( x, y, z )
{
return arguments.length >= 2 ?
PerlinNoise_2D( x, y ) :
PerlinNoise_2D( x, x );
}
function Noise(x, y)
{
var n = x + y * 57;
n = (n<<13) ^ n;
return Math.abs(1.0 - (((n * ((n * n * 15731) + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0));
}
function SmoothedNoise(x, y)
{
var corners = ( Noise(x-1, y-1)+Noise(x+1, y-1)+Noise(x-1, y+1)+Noise(x+1, y+1) ) / 16;
var sides = ( Noise(x-1, y) +Noise(x+1, y) +Noise(x, y-1) +Noise(x, y+1) ) / 8;
var center = Noise(x, y) / 4;
return corners + sides + center;
}
function InterpolatedNoise(x, y)
{
var integer_X = Math.floor(x);
var fractional_X = x - integer_X;
var integer_Y = Math.floor(y);
var fractional_Y = y - integer_Y;
var v1 = SmoothedNoise(integer_X, integer_Y);
var v2 = SmoothedNoise(integer_X + 1, integer_Y);
var v3 = SmoothedNoise(integer_X, integer_Y + 1);
var v4 = SmoothedNoise(integer_X + 1, integer_Y + 1);
var i1 = Interpolate(v1 , v2 , fractional_X);
var i2 = Interpolate(v3 , v4 , fractional_X);
return Interpolate(i1 , i2 , fractional_Y);
}
function PerlinNoise_2D(x, y)
{
var total = 0;
var p = 0.25;
var n = 3;
for ( var i = 0; i <= n; i++ )
{
var frequency = Math.pow(2, i);
var amplitude = Math.pow(p, i);
total = total + InterpolatedNoise(x * frequency, y * frequency) * amplitude;
}
return total;
}
function Interpolate(a, b, x)
{
var ft = x * p.PI;
var f = (1 - p.cos(ft)) * .5;
return a*(1-f) + b*f;
}
p.red = function( aColor )
{
return parseInt(aColor.slice(5));
}
p.green = function( aColor )
{
return parseInt(aColor.split(",")[1]);
}
p.blue = function( aColor )
{
return parseInt(aColor.split(",")[2]);
}
p.alpha = function( aColor )
{
return parseInt(aColor.split(",")[3]);
}
p.abs = function abs( aNumber )
{
return Math.abs( aNumber );
}
p.cos = function cos( aNumber )
{
return Math.cos( aNumber );
}
p.sin = function sin( aNumber )
{
return Math.sin( aNumber );
}
p.pow = function pow( aNumber, aExponent )
{
return Math.pow( aNumber, aExponent );
}
p.constrain = function constrain( aNumber, aMin, aMax )
{
return Math.min( Math.max( aNumber, aMin ), aMax );
}
p.sqrt = function sqrt( aNumber )
{
return Math.sqrt( aNumber );
}
p.atan2 = function atan2( aNumber, aNumber2 )
{
return Math.atan2( aNumber, aNumber2 );
}
p.radians = function radians( aAngle )
{
return ( aAngle / 180 ) * p.PI;
}
p.size = function size( aWidth, aHeight )
{
var fillStyle = curContext.fillStyle;
var strokeStyle = curContext.strokeStyle;
curElement.width = p.width = aWidth;
curElement.height = p.height = aHeight;
curContext.fillStyle = fillStyle;
curContext.strokeStyle = strokeStyle;
}
p.noStroke = function noStroke()
{
doStroke = false;
}
p.noFill = function noFill()
{
doFill = false;
}
p.smooth = function smooth()
{
}
p.noLoop = function noLoop()
{
doLoop = false;
}
p.fill = function fill()
{
doFill = true;
curContext.fillStyle = p.color.apply( this, arguments );
}
p.stroke = function stroke()
{
doStroke = true;
curContext.strokeStyle = p.color.apply( this, arguments );
}
p.strokeWeight = function strokeWeight( w )
{
curContext.lineWidth = w;
}
p.point = function point( x, y )
{
var oldFill = curContext.fillStyle;
curContext.fillStyle = curContext.strokeStyle;
curContext.fillRect( Math.round( x ), Math.round( y ), 1, 1 );
curContext.fillStyle = oldFill;
}
p.get = function get( x, y )
{
if ( arguments.length == 0 )
{
var c = p.createGraphics( p.width, p.height );
c.image( curContext, 0, 0 );
return c;
}
if ( !getLoaded )
{
getLoaded = buildImageObject( curContext.getImageData(0, 0, p.width, p.height) );
}
return getLoaded.get( x, y );
}
p.set = function set( x, y, color )
{
var oldFill = curContext.fillStyle;
curContext.fillStyle = color;
curContext.fillRect( Math.round( x ), Math.round( y ), 1, 1 );
curContext.fillStyle = oldFill;
}
p.arc = function arc( x, y, width, height, start, stop )
{
if ( width <= 0 )
return;
if ( curEllipseMode == p.CORNER )
{
x += width / 2;
y += height / 2;
}
curContext.beginPath();
curContext.moveTo( x, y );
curContext.arc( x, y, curEllipseMode == p.CENTER_RADIUS ? width : width/2, start, stop, false );
if ( doFill )
curContext.fill();
if ( doStroke )
curContext.stroke();
curContext.closePath();
}
p.line = function line( x1, y1, x2, y2 )
{
curContext.lineCap = "round";
curContext.beginPath();
curContext.moveTo( x1 || 0, y1 || 0 );
curContext.lineTo( x2 || 0, y2 || 0 );
curContext.stroke();
curContext.closePath();
}
p.bezier = function bezier( x1, y1, x2, y2, x3, y3, x4, y4 )
{
curContext.lineCap = "butt";
curContext.beginPath();
curContext.moveTo( x1, y1 );
curContext.bezierCurveTo( x2, y2, x3, y3, x4, y4 );
curContext.stroke();
curContext.closePath();
}
p.triangle = function triangle( x1, y1, x2, y2, x3, y3 )
{
p.beginShape();
p.vertex( x1, y1 );
p.vertex( x2, y2 );
p.vertex( x3, y3 );
p.endShape();
}
p.quad = function quad( x1, y1, x2, y2, x3, y3, x4, y4 )
{
p.beginShape();
p.vertex( x1, y1 );
p.vertex( x2, y2 );
p.vertex( x3, y3 );
p.vertex( x4, y4 );
p.endShape();
}
p.rect = function rect( x, y, width, height )
{
if ( width == 0 && height == 0 )
return;
curContext.beginPath();
var offsetStart = 0;
var offsetEnd = 0;
if ( curRectMode == p.CORNERS )
{
width -= x;
height -= y;
}
if ( curRectMode == p.RADIUS )
{
width *= 2;
height *= 2;
}
if ( curRectMode == p.CENTER || curRectMode == p.RADIUS )
{
x -= width / 2;
y -= height / 2;
}
curContext.rect(
Math.round( x ) - offsetStart,
Math.round( y ) - offsetStart,
Math.round( width ) + offsetEnd,
Math.round( height ) + offsetEnd
);
if ( doFill )
curContext.fill();
if ( doStroke )
curContext.stroke();
curContext.closePath();
}
p.ellipse = function ellipse( x, y, width, height )
{
x = x || 0;
y = y || 0;
if ( width <= 0 && height <= 0 )
return;
curContext.beginPath();
if ( curEllipseMode == p.RADIUS )
{
width *= 2;
height *= 2;
}
var offsetStart = 0;
// Shortcut for drawing a circle
if ( width == height )
curContext.arc( x - offsetStart, y - offsetStart, width / 2, 0, Math.PI * 2, false );
if ( doFill )
curContext.fill();
if ( doStroke )
curContext.stroke();
curContext.closePath();
}
p.link = function( href, target )
{
window.location = href;
}
p.loadPixels = function()
{
p.pixels = buildImageObject( curContext.getImageData(0, 0, p.width, p.height) ).pixels;
}
p.updatePixels = function()
{
var colors = /(\d+),(\d+),(\d+),(\d+)/;
var pixels = {};
var data = pixels.data = [];
pixels.width = p.width;
pixels.height = p.height;
var pos = 0;
for ( var i = 0, l = p.pixels.length; i < l; i++ ) {
var c = (p.pixels[i] || "rgba(0,0,0,1)").match(colors);
data[pos] = parseInt(c[1]);
data[pos+1] = parseInt(c[2]);
data[pos+2] = parseInt(c[3]);
data[pos+3] = parseFloat(c[4]) * 100;
pos += 4;
}
curContext.putImageData(pixels, 0, 0);
}
p.extendClass = function extendClass( obj, args, fn )
{
if ( arguments.length == 3 )
{
fn.apply( obj, args );
}
else
{
args.call( obj );
}
}
p.addMethod = function addMethod( object, name, fn )
{
if ( object[ name ] )
{
var args = fn.length;
var oldfn = object[ name ];
object[ name ] = function()
{
if ( arguments.length == args )
return fn.apply( this, arguments );
else
return oldfn.apply( this, arguments );
};
}
else
{
object[ name ] = fn;
}
}
p.init = function init(code){
p.stroke( 0 );
p.fill( 255 );
// Canvas has trouble rendering single pixel stuff on whole-pixel
// counts, so we slightly offset it (this is super lame).
curContext.translate( 0.5, 0.5 );
if ( code )
{
(function(Processing){with (p){
eval(parse(code, p));
}})(p);
}
if ( p.setup )
{
inSetup = true;
p.setup();
}
inSetup = false;
if ( p.draw )
{
if ( !doLoop )
{
p.redraw();
}
else
{
p.loop();
}
}
attach( curElement, "mousemove", function(e)
{
p.pmouseX = p.mouseX;
p.pmouseY = p.mouseY;
p.mouseX = e.clientX - curElement.offsetLeft;
p.mouseY = e.clientY - curElement.offsetTop;
if ( p.mouseMoved )
{
p.mouseMoved();
}
if ( mousePressed && p.mouseDragged )
{
p.mouseDragged();
}
});
attach( curElement, "mousedown", function(e)
{
mousePressed = true;
if ( typeof p.mousePressed == "function" )
{
p.mousePressed();
}
else
{
p.mousePressed = true;
}
});
attach( curElement, "mouseup", function(e)
{
mousePressed = false;
if ( typeof p.mousePressed != "function" )
{
p.mousePressed = false;
}
if ( p.mouseReleased )
{
p.mouseReleased();
}
});
attach( document, "keydown", function(e)
{
keyPressed = true;
p.key = e.keyCode + 32;
if ( e.shiftKey )
{
p.key = String.fromCharCode(p.key).toUpperCase().charCodeAt(0);
}
if ( typeof p.keyPressed == "function" )
{
p.keyPressed();
}
else
{
p.keyPressed = true;
}
});
attach( document, "keyup", function(e)
{
keyPressed = false;
if ( typeof p.keyPressed != "function" )
{
p.keyPressed = false;
}
if ( p.keyReleased )
{
p.keyReleased();
}
});
function attach(elem, type, fn)
{
if ( elem.addEventListener )
elem.addEventListener( type, fn, false );
else
elem.attachEvent( "on" + type, fn );
}
};
return p;
}
})();
} //# end of "install only once"
//}}}