From 131dc4736e9381fef9f8cd55e87b5957ef533d42 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Tue, 10 Sep 2024 20:26:21 +0300 Subject: [PATCH] Using AI to improve code readability --- Math/tuletis.bas | 115 +++++++++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 49 deletions(-) diff --git a/Math/tuletis.bas b/Math/tuletis.bas index 61c2cb2..5f38c46 100755 --- a/Math/tuletis.bas +++ b/Math/tuletis.bas @@ -1,68 +1,85 @@ -DECLARE SUB init () -DECLARE SUB pp (x1, y1, x2, y2, c!) -DIM SHARED mul +' Program that computes and plots arbitrary mathematical function on a 2D graph. +' Also it computes and plots the derivative of the function. +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 200?, Initial version +' 2024.09, Improved program readability using AI -mul = 50 '<< scale -init -ox = -320 / mul -oy = 0 +DECLARE SUB Initialize () +DECLARE SUB PlotPoint (x, y, x1, y1, c!) +DIM SHARED scaleFactor -FOR x = -320 / mul TO 320 / mul STEP 1 / mul +scaleFactor = 50 ' Scale factor for the graph +Initialize +oldX = -320 / scaleFactor +oldY = 0 -t = x ^ 3 - (3 * x) '<< Type your formula there +FOR x = -320 / scaleFactor TO 320 / scaleFactor STEP 1 / scaleFactor + ' Calculate the function value (replace with your desired formula) + t = x ^ 3 - (3 * x) -pp x, t, ox, tol, 10 -y = (t - tol) * mul -tol = t + PlotPoint x, t, oldX, prevY, 10 + y = (t - prevY) * scaleFactor + prevY = t -pp x, y, ox, oy, 14 -ox = x -oy = y + PlotPoint x, y, oldX, oldY, 14 + oldX = x + oldY = y NEXT x -SUB init -SCREEN 12 +SUB Initialize + SCREEN 12 -FOR x = -320 TO 320 -IF x / mul = x \ mul THEN LINE (x + 320, 0)-(x + 320, 479), 1 -NEXT x + ' Draw vertical grid lines + FOR x = -320 TO 320 + IF x / scaleFactor = x \ scaleFactor THEN LINE (x + 320, 0)-(x + 320, 479), 1 + NEXT x -FOR y = -240 TO 240 -IF y / mul = y \ mul THEN LINE (0, y + 240)-(639, y + 240), 1 -NEXT y + ' Draw horizontal grid lines + FOR y = -240 TO 240 + IF y / scaleFactor = y \ scaleFactor THEN LINE (0, y + 240)-(639, y + 240), 1 + NEXT y -FOR x = -320 TO 320 -IF x / (mul * 5) = x \ (mul * 5) THEN LINE (x + 320, 0)-(x + 320, 479), 4 -NEXT x + ' Draw thicker vertical grid lines for every 5th unit + FOR x = -320 TO 320 + IF x / (scaleFactor * 5) = x \ (scaleFactor * 5) THEN LINE (x + 320, 0)-(x + 320, 479), 4 + NEXT x -FOR y = -240 TO 240 -IF y / (mul * 5) = y \ (mul * 5) THEN LINE (0, y + 240)-(639, y + 240), 4 -NEXT y + ' Draw thicker horizontal grid lines for every 5th unit + FOR y = -240 TO 240 + IF y / (scaleFactor * 5) = y \ (scaleFactor * 5) THEN LINE (0, y + 240)-(639, y + 240), 4 + NEXT y + ' Draw x-axis and y-axis + LINE (0, 240)-(639, 240), 3 + LINE (320, 0)-(320, 479), 3 +END SUB +SUB PlotPoint (x, y, x1, y1, c) -LINE (0, 240)-(639, 240), 3 -LINE (320, 0)-(320, 479), 3 -END SUB + x2 = (x * scaleFactor) + 320 + y2 = 240 - (y * scaleFactor) + x3 = (x1 * scaleFactor) + 320 + y3 = 240 - (y1 * scaleFactor) -SUB pp (x, y, x1, y1, c) - -x2 = (x * mul) + 320 -y2 = 240 - (y * mul) -x3 = (x1 * mul) + 320 -y3 = 240 - (y1 * mul) -IF x2 < 0 THEN GOTO 1 -IF y2 < 0 THEN GOTO 1 -IF x2 > 639 THEN GOTO 1 -IF y2 > 479 THEN GOTO 1 -IF x3 < 0 THEN GOTO 1 -IF y3 < 0 THEN GOTO 1 -IF x3 > 639 THEN GOTO 1 -IF y3 > 479 THEN GOTO 1 -LINE (x2, y2)-(x3, y3), c -1 -END SUB + ' Check if the points are within the screen boundaries + IF x2 < 0 THEN GOTO Skip + IF y2 < 0 THEN GOTO Skip + IF x2 > 639 THEN GOTO Skip + IF y2 > 479 THEN GOTO Skip + IF x3 < 0 THEN GOTO Skip + IF y3 < 0 THEN GOTO Skip + IF x3 > 639 THEN GOTO Skip + IF y3 > 479 THEN GOTO Skip + + ' Draw a line between the two points with the specified color + LINE (x2, y2)-(x3, y3), c +Skip: +END SUB -- 2.20.1