From ddf49446e4b18f7b883f60747deca379afa48e2f Mon Sep 17 00:00:00 2001 From: nanochess Date: Mon, 15 Feb 2021 21:25:28 -0600 Subject: [PATCH 1/2] Ported 3D Plot and Bunny to Javascript --- 19 Bunny/javascript/bunny.html | 9 +++++ 19 Bunny/javascript/bunny.js | 58 ++++++++++++++++++++++++++++++ 87 3-D Plot/javascript/3dplot.html | 9 +++++ 87 3-D Plot/javascript/3dplot.js | 40 +++++++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 19 Bunny/javascript/bunny.html create mode 100644 19 Bunny/javascript/bunny.js create mode 100644 87 3-D Plot/javascript/3dplot.html create mode 100644 87 3-D Plot/javascript/3dplot.js diff --git a/19 Bunny/javascript/bunny.html b/19 Bunny/javascript/bunny.html new file mode 100644 index 000000000..3dca1a44e --- /dev/null +++ b/19 Bunny/javascript/bunny.html @@ -0,0 +1,9 @@ + + +BUNNY + + +

+
+
+
diff --git a/19 Bunny/javascript/bunny.js b/19 Bunny/javascript/bunny.js
new file mode 100644
index 000000000..11342d8b8
--- /dev/null
+++ b/19 Bunny/javascript/bunny.js	
@@ -0,0 +1,58 @@
+// BUNNY
+//
+// Converted from BASIC to Javascript by Oscar Toledo G. (nanochess)
+//
+function print(str)
+{
+	document.getElementById("output").appendChild(document.createTextNode(str));
+}
+
+function tab(space)
+{
+	var str = "";
+	while (space-- > 0)
+		str += " ";
+	return str;
+}
+
+var bunny_string = ["B","U","N","N","Y"];
+
+var bunny_data = [1,2,-1,0,2,45,50,-1,0,5,43,52,-1,0,7,41,52,-1,
+	1,9,37,50,-1,2,11,36,50,-1,3,13,34,49,-1,4,14,32,48,-1,
+	5,15,31,47,-1,6,16,30,45,-1,7,17,29,44,-1,8,19,28,43,-1,
+	9,20,27,41,-1,10,21,26,40,-1,11,22,25,38,-1,12,22,24,36,-1,
+	13,34,-1,14,33,-1,15,31,-1,17,29,-1,18,27,-1,
+	19,26,-1,16,28,-1,13,30,-1,11,31,-1,10,32,-1,
+	8,33,-1,7,34,-1,6,13,16,34,-1,5,12,16,35,-1,
+	4,12,16,35,-1,3,12,15,35,-1,2,35,-1,1,35,-1,
+	2,34,-1,3,34,-1,4,33,-1,6,33,-1,10,32,34,34,-1,
+	14,17,19,25,28,31,35,35,-1,15,19,23,30,36,36,-1,
+	14,18,21,21,24,30,37,37,-1,13,18,23,29,33,38,-1,
+	12,29,31,33,-1,11,13,17,17,19,19,22,22,24,31,-1,
+	10,11,17,18,22,22,24,24,29,29,-1,
+	22,23,26,29,-1,27,29,-1,28,29,-1,4096];
+
+print(tab(32) + "BUNNY\n");
+print(tab(15) + "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY\n");
+print("\n");
+print("\n");
+print("\n");
+
+var l = 64;	// ASCII letter code
+var pos = 0;
+
+print("\n");
+
+var str = "";
+for (var pos = 0; bunny_data[pos] < 128; pos++) {
+	if (bunny_data[pos] < 0) {
+		print(str + "\n");
+		str = "";
+		continue;
+	}
+	while (str.length < bunny_data[pos])
+		str += " ";
+	for (var i = bunny_data[pos]; i <= bunny_data[pos + 1]; i++) 
+		str += bunny_string[i % 5];
+	pos++;
+}
diff --git a/87 3-D Plot/javascript/3dplot.html b/87 3-D Plot/javascript/3dplot.html
new file mode 100644
index 000000000..003096bf7
--- /dev/null
+++ b/87 3-D Plot/javascript/3dplot.html	
@@ -0,0 +1,9 @@
+
+
+3D PLOT
+
+
+

+
+
+
diff --git a/87 3-D Plot/javascript/3dplot.js b/87 3-D Plot/javascript/3dplot.js
new file mode 100644
index 000000000..aac5b5e11
--- /dev/null
+++ b/87 3-D Plot/javascript/3dplot.js	
@@ -0,0 +1,40 @@
+// 3D PLOT
+//
+// Converted from BASIC to Javascript by Oscar Toledo G. (nanochess)
+//
+function print(str)
+{
+	document.getElementById("output").appendChild(document.createTextNode(str));
+}
+
+function tab(space)
+{
+	var str = "";
+	while (space-- > 0)
+		str += " ";
+	return str;
+}
+
+function equation(input)
+{
+	return 30 * Math.exp(-input * input / 100);
+}
+
+print(tab(32) + "3D PLOT\n");
+print(tab(15) + "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY\n");
+
+for (x = -30; x <= 30; x += 1.5) {
+	l = 0;
+	y1 = 5 * Math.floor(Math.sqrt(900 - x * x) / 5);
+	str = "";
+	for (y = y1; y >= -y1; y -= 5) {
+		z = Math.floor(25 + equation(Math.sqrt(x * x + y * y)) - .7 * y);
+		if (z > l) {
+			l = z;
+			while (str.length < z)
+				str += " ";
+			str += "*";
+		}
+	}
+	print(str + "\n");
+}

From 9201f2fb1b47f0f834ed63c0803973fcb48533a2 Mon Sep 17 00:00:00 2001
From: nanochess 
Date: Mon, 15 Feb 2021 21:49:44 -0600
Subject: [PATCH 2/2] Ported CALENDAR to Javascript. Solved bug in BASIC code

---
 21 Calendar/calendar.bas             |  2 +-
 21 Calendar/javascript/calendar.html |  9 +++
 21 Calendar/javascript/calendar.js   | 89 ++++++++++++++++++++++++++++
 3 files changed, 99 insertions(+), 1 deletion(-)
 create mode 100644 21 Calendar/javascript/calendar.html
 create mode 100644 21 Calendar/javascript/calendar.js

diff --git a/21 Calendar/calendar.bas b/21 Calendar/calendar.bas
index 674488e56..8a7703f9a 100644
--- a/21 Calendar/calendar.bas	
+++ b/21 Calendar/calendar.bas	
@@ -4,7 +4,7 @@
 100 REM     VALUES FOR 1979 - SEE NOTES
 110 DIM M(12)
 120 FOR I=1 TO 6: PRINT CHR$(10);: NEXT I
-130 D=1: REM 1979 STARTS ON MONDAY (0=SUN, -1=MON, -2=TUES...)
+130 D=-1: REM 1979 STARTS ON MONDAY (0=SUN, -1=MON, -2=TUES...)
 140 S=0
 150 REM     READ DAYS OF EACH MONTH
 160 FOR N=0 TO 12: READ M(N): NEXT N
diff --git a/21 Calendar/javascript/calendar.html b/21 Calendar/javascript/calendar.html
new file mode 100644
index 000000000..ff9a36037
--- /dev/null
+++ b/21 Calendar/javascript/calendar.html	
@@ -0,0 +1,9 @@
+
+
+CALENDAR
+
+
+

+
+
+
diff --git a/21 Calendar/javascript/calendar.js b/21 Calendar/javascript/calendar.js
new file mode 100644
index 000000000..288191986
--- /dev/null
+++ b/21 Calendar/javascript/calendar.js	
@@ -0,0 +1,89 @@
+// CALENDAR
+//
+// Converted from BASIC to Javascript by Oscar Toledo G. (nanochess)
+//
+function print(str)
+{
+	document.getElementById("output").appendChild(document.createTextNode(str));
+}
+
+function tab(space)
+{
+	var str = "";
+	while (space-- > 0)
+		str += " ";
+	return str;
+}
+
+print(tab(32) + "CALENDAR\n");
+print(tab(15) + "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY\n");
+print("\n");
+print("\n");
+print("\n");
+
+//       0, 31, 29  ON LEAP YEARS
+var m = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
+
+// VALUES FOR 1979 - SEE NOTES
+for (i = 1; i <= 6; i++)
+	print("\n");
+
+d = -1;	// 1979 starts on Monday (0 = Sun, -1 = Monday, -2 = Tuesday)
+s = 0;
+
+for (n = 1; n <= 12; n++) {
+	print("\n");
+	print("\n");
+	s = s + m[n - 1];
+	str = "**" + s;
+	while (str.length < 7)
+		str += " ";
+	for (i = 1; i <= 18; i++)
+		str += "*";
+	switch (n) {
+		case  1:	str += " JANUARY "; break;
+		case  2:	str += " FEBRUARY"; break;
+		case  3:	str += "  MARCH  "; break;
+		case  4:	str += "  APRIL  "; break;
+		case  5:	str += "   MAY   "; break;
+		case  6:	str += "   JUNE  "; break;
+		case  7:	str += "   JULY  "; break;
+		case  8:	str += "  AUGUST "; break;
+		case  9:	str += "SEPTEMBER"; break;
+		case 10:	str += " OCTOBER "; break;
+		case 11:	str += " NOVEMBER"; break;
+		case 12:	str += " DECEMBER"; break;
+	}
+	for (i = 1; i <= 18; i++)
+		str += "*";
+	str += (365 - s) + "**";
+	     // 366 - s on leap years
+	print(str + "\n");
+	print("     S       M       T       W       T       F       S\n");
+	print("\n");
+	str = "";
+	for (i = 1; i <= 59; i++)
+		str += "*";    
+	for (week = 1; week <= 6; week++) {
+		print(str + "\n");
+		str = "    ";
+		for (g = 1; g <= 7; g++) {
+			d++;
+			d2 = d - s;
+			if (d2 > m[n]) {
+				week = 6;
+				break;
+			}
+			if (d2 > 0)
+				str += d2;
+			while (str.length < 4 + 8 * g)
+				str += " ";
+		}
+		if (d2 == m[n]) {
+			d += g;
+			break;
+		}
+	} 
+	d -= g;
+	print(str + "\n");
+}