function grapher




JavaScript Source Code 3000: Calculators: Function Grapher








































Function Grapher







Graphs any function you enter on the scale of your choice, assuming you use the correct JavaScript syntax. For example, to use Cos x, use Math.cos(x). Or, for x^2, use Math.pow(x, 2), etc.









Function (JavaScript syntax)


 
 




X min




X max











JavaScript Source Code 3000: Calculators: Function Grapher (Function Page)
Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s). The script is yours!!!





    





<!-- THREE STEPS TO INSTALL FUNCTION GRAPHER:

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document
3. Paste the final coding into a new file, drawGraph.html -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Stephane Gamondes (gamondes@hotmail.com) -->
<!-- Web Site: http://www.multimania.com/gamondes -->

<! >
<! >

<!-- Begin
function drawGraph(frm) {
gURL = "drawGraph.html?graph=" + escape(frm.graph.value) + "&minX=" + frm.minX.value + "&maxX=" + frm.maxX.value;
open(gURL, 'graphWdw', 'width=250,height=250');
}
// End -->
</script>
</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<center>
<form>
<table border=0 bgcolor="#E6E6E6" cellpadding=3 cellspacing=0>
<tr>
<td colspan=2>
<font face="Arial" size="2">Function (JavaScript syntax)<br>
<input type=text name=graph size=20 maxlength=40 value="Math.cos(x)">
<p>
<td rowspan=2 valign=middle align=center> 
<input type=button value="Plot" name=Plot onClick="drawGraph(this.form)">  
</td>
</tr>
<tr>
<td nowrap>
<font face="Arial" size="2">X min<br>
<input type=text name=minX size=4 maxlength=3 value="-10">
</font>
</td>
<td nowrap>
<font face="Arial" size="2">X max<br>
<input type=text name=maxX size=3 maxlength=3 value="10">
</font>
</td>
</tr>
</table>
</form>
</center>
<!-- Script Size: 4.67 KB -->

JavaScript Source Code 3000: Calculators: Function Grapher (Draw Graph Page)
Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s). The script is yours!!!


 





    





<!-- TWO STEPS TO INSTALL FUNCTION GRAPHER:

1. Paste this HTML code into a new file, name it drawGraph.html
2. Save the necessary images to your web site directory -->

<!-- STEP ONE: Paste this file into a new page, call it drawGraph.html -->

<html>
<head>
</head>
<style>
.point
{
position: absolute;
}
</style>

<script>
function getParams()
{
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1)
{
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++)
{
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
}
}
return params;
}

dotCode = '<div class="point" id="pdot_id"><img src="graph.gif" width="1" height="pic_height" alt="pic_alt"></div>\n';
xCode = '<div class="point" id="xAxis"><table border="0" width="x_width" cellspacing="0" cellpadding="0"><tr><td width="100%" bgcolor="#000000"><img src="espace.gif" width="1" height="1"></td></tr></table></div>\n';
yCode = '<div class="point" id="yAxis"><table border="0" height="y_height" cellspacing="0" cellpadding="0"><tr><td width="100%" bgcolor="#000000"><img src="espace.gif" width="1" height="1"></td></tr></table></div>\n';
backCode = '<div class="point" id="background"><table border="0" height="back_height" width="back_width" cellspacing="0" cellpadding="0"><tr><td width="100%" bgcolor="#EEEEEE"> </td></tr></table></div>\n';

if (navigator.appName == 'Netscape')
{
leftCode = 'document.obj_id.left = ';
topCode = 'document.obj_id.top = ';
}
else
{
leftCode = 'document.all.obj_id.style.left = ';
topCode = 'document.all.obj_id.style.top = ';
}

params = getParams();
fct = unescape(params["graph"]);
xMin = parseFloat(params["minX"]); xMax = parseFloat(params["maxX"]);
nbXs =200; nbYs = 200;
maxYpos = 225; minXpos = 25;
x = xMin;
yZero = Math.abs(eval(fct));
yMax = yZero;
yMin = yZero;
datas = new Array();

deltaX = (xMax - xMin) / nbXs;

i = 0;
while (x <= xMax)
{
y = eval(fct);
datas[i] = x + ':' + y;
yMax = Math.max(y, yMax);
yMin = Math.min(y, yMin);
yZero = Math.min(yZero, Math.abs(y))
x+= deltaX; i++;
}

deltaY = nbYs / (yMax - yMin);

yPos = new Array();
for (i=0; i<datas.length; i++)
{
yPos[i] = maxYpos - (((datas[i].split(':'))[1] - yMin) * deltaY);
}

document.write(backCode.replace(/back_width/, nbXs).replace(/back_height/, nbYs));
eval(leftCode.replace(/obj_id/, 'background') + minXpos);
eval(topCode.replace(/obj_id/, 'background') + (maxYpos - nbYs));

if ((xMin * xMax) < 0)
{
document.write(yCode.replace(/y_height/, nbXs));
eval(leftCode.replace(/obj_id/, 'yAxis') + (minXpos - (xMin * (nbXs/(xMax - xMin)))));
eval(topCode.replace(/obj_id/, 'yAxis') + (maxYpos - nbYs));
}

if ((yMin * yMax) <= 0)
{
document.write(xCode.replace(/x_width/, nbYs));
eval(leftCode.replace(/obj_id/, 'xAxis') + minXpos);
eval(topCode.replace(/obj_id/, 'xAxis') + (maxYpos - ((yZero - yMin) * deltaY)));
}

for (i=1; i<(datas.length-1); i++)
{
picHeight = Math.abs((yPos[i-1] - yPos[i]) + (yPos[i] - yPos[i+1])) / 2;
YDPos = yPos[i] - (Math.round(picHeight) / 2);
document.write(dotCode.replace(/dot_id/, i).replace(/pic_height/, Math.ceil(picHeight)).replace(/pic_alt/, datas[i]));
eval(leftCode.replace(/obj_id/, 'p' + i) + (minXpos + i));
eval(topCode.replace(/obj_id/, 'p' + i) + YDPos);
}

</script>
<body bgcolor="#FFFFFF">
</body>
</html>



<!-- Script Size: 4.67 KB -->










Wyszukiwarka

Podobne podstrony:
function fdf next field name
function ccvs void
function mysql error
function mcal event set end
function mcrypt cbc
Functional Origins of Religious Concepts Ontological and Strategic Selection in Evolved Minds
function domnode get content
function mcrypt module get algo key size
function pdf execute image
function nl2br

więcej podobnych podstron