From db8ca2d8ed82e715c5ca76b13646d17ac6369f10 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 23 Dec 2020 19:40:45 +0900 Subject: [PATCH] basic: function plotter update --- assets/basic.js | 6 +++--- assets/sinc1.bas | 21 +++++++++++---------- assets/sinc2.bas | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 assets/sinc2.bas diff --git a/assets/basic.js b/assets/basic.js index 2dcf8f4..625354e 100644 --- a/assets/basic.js +++ b/assets/basic.js @@ -2617,8 +2617,8 @@ bF._troNOP = function(lnum, stmtnum) { return new SyntaxTreeReturnObj("null", un bF._executeSyntaxTree = function(lnum, stmtnum, syntaxTree, recDepth) { if (lnum === undefined || stmtnum === undefined) throw Error(`Line or statement number is undefined: (${lnum},${stmtnum})`); - let _debugExec = true; - let _debugPrintCurrentLine = true; + let _debugExec = false; + let _debugPrintCurrentLine = false; let recWedge = ">".repeat(recDepth) + " "; if (_debugExec || _debugPrintCurrentLine) serial.println(recWedge+"@@ EXECUTE @@"); @@ -2870,7 +2870,7 @@ bF._executeAndGet = function(lnum, stmtnum, syntaxTree) { try { var execResult = bF._executeSyntaxTree(lnum, stmtnum, syntaxTree, 0); - if (bF.parserDoDebugPrint) serial.println(`Line ${lnum} TRO: ${Object.entries(execResult)}`); + if (DBGON) serial.println(`Line ${lnum} TRO: ${Object.entries(execResult)}`); return execResult.troNextLine; } diff --git a/assets/sinc1.bas b/assets/sinc1.bas index 044d1b5..8f94b87 100644 --- a/assets/sinc1.bas +++ b/assets/sinc1.bas @@ -1,17 +1,18 @@ -1 GOTO 1000 +1 ZEROLINE=10 +2 AMP=20 +3 GOTO 1000 100 LABEL SINCQ:REM gets Sinc(Q) -110 Q=SIN(I)/I +110 Q=IF I==0 THEN 1.0 ELSE SIN(I)/I 120 RETURN -200 LABEL TOSPC -201 REM Converts 0-1 value into screen line -202 REM input is Q, results are stored to SQ -210 SQ="I":REM currently empty string literals can't be used because of bug -220 FOR X=1 TO 10 MAX 10+Q*20 -230 SQ=SQ+(IF X==FIX(10+Q*20) THEN "@" ELSE IF X==10 THEN ":" ELSE " ") +200 LABEL PLOTLINE:REM Converts 0-1 value into screen line +201 REM input is Q, results are stored to SQ +210 SQ=CHR(0) +220 FOR X=1 TO ZEROLINE+AMP +230 SQ=SQ+(IF X==ROUND(ZEROLINE+Q*AMP) THEN "@" ELSE IF X==10 THEN "|" ELSE CHR(250)) 240 NEXT 250 RETURN -1000 FOR I=1 TO 20 +1000 FOR I=0 TO 20 1010 GOSUB SINCQ -1020 GOSUB TOSPC +1020 GOSUB PLOTLINE 1030 PRINT(SQ) 1040 NEXT diff --git a/assets/sinc2.bas b/assets/sinc2.bas new file mode 100644 index 0000000..6973b12 --- /dev/null +++ b/assets/sinc2.bas @@ -0,0 +1,17 @@ +1 ZEROLINE=10 +2 AMP=20 +10 DEFUN SINC(P)=IF P==0 THEN 1.0 ELSE SIN(P)/P +20 DEFUN TOCHAR(P,X)=IF (X==ROUND(ZEROLINE+P*AMP)) THEN "@" ELSE IF (X==ZEROLINE) THEN "|" ELSE CHR(250) +30 DEFUN SCONCAT(ACC,S)=ACC+S +40 DEFUN PLOTLINE(X)=FOLD(SCONCAT,CHR(0),MAP(TOCHAR<~X,1 TO ZEROLINE+AMP)) + +100 FOR I=0 TO 20 +110 PRINT PLOTLINE(SINC(I)) +120 NEXT +999 END + +1000 REM Known bugs +1010 DEFUN PLOTLINE(F,X)=FOLD(SCONCAT,CHR(0),MAP(TOCHAR<~F(X),1 TO ZEROLINE+AMP)) +1011 REM calling user-defined function within DEFUN is not working + +1020 REM empty string literal "" is translated to number zero (another JS blunder)