GRAFY

ID
Nazov / Name:
Popis / Description:
Dlzka / Length:
Testovane pod / Tested under:

 

150
p150.html / p150.zip
Nakresli grafy zakladnych funkcii
2750b
NN 4.04

UKAZKA / CLICK HERE

Zdrojovy tvar / Source code:

<HTML> <HEAD> <TITLE>JavaScript DESTINATION - P150</TITLE> <script language=JavaScript> <!-- function make_1d_array(n) { this[0] = n for (var i = 1; i < n; i++) { this[i] = 0 } return this } function make_2d_array(n, m) { var a = new make_1d_array(n) for (var j=1; j<=n; j++) { a[j] = new make_1d_array(m) } for (var j=1; j<=n; j++) { for (var i=1; i<=m; i++) { (a[j])[i] = 0; } } return a } function plot_vertical(aa, size) { // aa should be a 1d array var j, w1, w2 for (var i=0;i<size;++i) { j = aa[i] w1=parseFloat(j-1); w2=parseFloat(size-j); document.write ( "<img src=images/sw.gif height=1 width=" +w1+">") document.write ( "<img src=images/sb.gif height=1 width=1>") document.write ( "<img src=images/sw.gif height=1 width=" +w2+"><br>"); } } function plot_2d(bitmap, size) { var i, last_color var w1, w2, wdif for (var j=1; j<size; j++) { loast_color = 0 i = 1; w1 = 1 while (i<size) { t = (bitmap[j])[i]; if ( t != loast_color ) { w2 = i wdif = w2 - w1 if (loast_color == 1) { document.write ("<img src=images/sb.gif height=1 width="+wdif+">") } else { document.write ("<img src=images/sw.gif height=1 width="+wdif+">") } loast_color = t w1 = i } i++ } wdif = size - w1 document.write ("<img src=images/sw.gif height=1 width="+wdif+"><br>") } } // --> </script> </HEAD> <BODY BGCOLOR="#FFFFFF"> <script language=JavaScript> <!-- var a = new make_1d_array(100) var j for (var i=0;i<100;++i) { j = 50 + 40 * Math.sin(i/15); a[i] = j ; } plot_vertical(a, 100) document.write("<br>Graf: vertikalny sin") document.write("<hr>") var b = make_2d_array(100,100); var j for (var i=1;i<100;i++) { j = Math.floor(50 - 40 * Math.sin(i/15)); if (j > 0 & j < 100) (b[j])[i] = 1; } plot_2d(b, 100) document.write("<br>Graf: horizontalny sin") document.write("<hr>") var i,j for (var j=1;j<100;j++) { for (var i=1;i<100;i++) { (b[j])[i] = 0; } } for (var r=1;r<629;r++) { i = Math.floor(50 + 40 * Math.sin(r/100)); j = Math.floor(50 + 40 * Math.cos(r/100)); (b[j])[i] = 1; i = Math.floor(40 + 30 * Math.sin(r/100)); j = Math.floor(50 + 30 * Math.cos(r/100)); (b[j])[i] = 1; i = Math.floor(30 + 20 * Math.sin(r/100)); j = Math.floor(50 + 20 * Math.cos(r/100)); (b[j])[i] = 1; } plot_2d(b, 100) document.write("<br>Graf: kruhy") // --> </script> </body> </html>
[ Navrat / BACK ]