From 02c99dbbedf58109584aef53959a13761c9b4fc6 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Mon, 28 Oct 2024 21:33:12 +0200 Subject: [PATCH] Refactoring code for better readability --- Math/3D graph/3dgraph.bas | 192 +++++++++++++++++++------------------- 1 file changed, 96 insertions(+), 96 deletions(-) diff --git a/Math/3D graph/3dgraph.bas b/Math/3D graph/3dgraph.bas index a1645a6..528c62c 100644 --- a/Math/3D graph/3dgraph.bas +++ b/Math/3D graph/3dgraph.bas @@ -7,8 +7,8 @@ ' 2002, Initial version ' 2024.09, Improved program readability using AI -' use: -' cursor keys - move around +' Keyboard controls: +' Cursor keys - move around ' - - fly up ' + - fly down ' ESC - exit program @@ -34,14 +34,14 @@ DECLARE SUB getcor () DECLARE SUB mulcor () DECLARE SUB nait3d () DECLARE SUB calcsin () -DIM SHARED xn(4000), yn(4000), zn(4000) +DIM SHARED vertexX(4000), vertexY(4000), vertexZ(4000) DIM SHARED x(4000), y(4000), z(4000) DIM SHARED xo(4000), yo(4000), zo(4000) -DIM SHARED point1(4000), point2(4000) -DIM SHARED col(4000) -DIM SHARED nump, numl -DIM SHARED tmnump, tmnuml, tm +DIM SHARED linePoint1(4000), linePoint2(4000) +DIM SHARED lineColor(4000) +DIM SHARED vertexCount, lineCount +DIM SHARED tmvertexCount, tmlineCount, tm DIM SHARED myx, myy, myz, mye, myk myx = 520 @@ -65,46 +65,46 @@ SUB getcor mkgr2 0, 0, 500 mkgr3 0, -500, 0 - xn(nump + 1) = 0 - yn(nump + 1) = -500 - zn(nump + 1) = 0 + vertexX(vertexCount + 1) = 0 + vertexY(vertexCount + 1) = -500 + vertexZ(vertexCount + 1) = 0 - xn(nump + 2) = 0 - yn(nump + 2) = 500 - zn(nump + 2) = 0 + vertexX(vertexCount + 2) = 0 + vertexY(vertexCount + 2) = 500 + vertexZ(vertexCount + 2) = 0 - xn(nump + 3) = -500 - yn(nump + 3) = 0 - zn(nump + 3) = 0 + vertexX(vertexCount + 3) = -500 + vertexY(vertexCount + 3) = 0 + vertexZ(vertexCount + 3) = 0 - xn(nump + 4) = 500 - yn(nump + 4) = 0 - zn(nump + 4) = 0 + vertexX(vertexCount + 4) = 500 + vertexY(vertexCount + 4) = 0 + vertexZ(vertexCount + 4) = 0 - xn(nump + 5) = 0 - yn(nump + 5) = 0 - zn(nump + 5) = -500 + vertexX(vertexCount + 5) = 0 + vertexY(vertexCount + 5) = 0 + vertexZ(vertexCount + 5) = -500 - xn(nump + 6) = 0 - yn(nump + 6) = 0 - zn(nump + 6) = 500 + vertexX(vertexCount + 6) = 0 + vertexY(vertexCount + 6) = 0 + vertexZ(vertexCount + 6) = 500 - point1(numl + 1) = nump + 1 - point2(numl + 1) = nump + 2 - col(numl + 1) = c + linePoint1(lineCount + 1) = vertexCount + 1 + linePoint2(lineCount + 1) = vertexCount + 2 + lineColor(lineCount + 1) = c - point1(numl + 2) = nump + 3 - point2(numl + 2) = nump + 4 - col(numl + 2) = c + linePoint1(lineCount + 2) = vertexCount + 3 + linePoint2(lineCount + 2) = vertexCount + 4 + lineColor(lineCount + 2) = c - point1(numl + 3) = nump + 5 - point2(numl + 3) = nump + 6 - col(numl + 3) = c + linePoint1(lineCount + 3) = vertexCount + 5 + linePoint2(lineCount + 3) = vertexCount + 6 + lineColor(lineCount + 3) = c - nump = nump + 6 - numl = numl + 3 - tmnump = nump - tmnuml = numl + vertexCount = vertexCount + 6 + lineCount = lineCount + 3 + tmvertexCount = vertexCount + tmlineCount = lineCount END SUB SUB graaf @@ -116,30 +116,30 @@ SUB graaf FOR z = -500 TO 500 STEP 50 d = d + 1 - xn(nump + d) = x + vertexX(vertexCount + d) = x valem x / 50, z / 50, y - yn(nump + d) = y * 50 - zn(nump + d) = z + vertexY(vertexCount + d) = y * 50 + vertexZ(vertexCount + d) = z IF z > -500 THEN e = e + 1 - point1(numl + e) = nump + d - point2(numl + e) = nump + d - 1 - col(numl + e) = c + linePoint1(lineCount + e) = vertexCount + d + linePoint2(lineCount + e) = vertexCount + d - 1 + lineColor(lineCount + e) = c END IF IF x > -500 THEN e = e + 1 - point1(numl + e) = nump + d - point2(numl + e) = nump + d - 21 - col(numl + e) = c + linePoint1(lineCount + e) = vertexCount + d + linePoint2(lineCount + e) = vertexCount + d - 21 + lineColor(lineCount + e) = c END IF NEXT z NEXT x - nump = nump + d - numl = numl + e + vertexCount = vertexCount + d + lineCount = lineCount + e END SUB SUB mkgr (x1, y1, z1) @@ -151,29 +151,29 @@ SUB mkgr (x1, y1, z1) FOR y = -500 TO 500 STEP 100 d = d + 1 - xn(nump + d) = x1 - yn(nump + d) = y1 + y - zn(nump + d) = z1 + z + vertexX(vertexCount + d) = x1 + vertexY(vertexCount + d) = y1 + y + vertexZ(vertexCount + d) = z1 + z IF y > -500 THEN e = e + 1 - point1(numl + e) = nump + d - point2(numl + e) = nump + d - 1 - col(numl + e) = c + linePoint1(lineCount + e) = vertexCount + d + linePoint2(lineCount + e) = vertexCount + d - 1 + lineColor(lineCount + e) = c END IF IF z > -500 THEN e = e + 1 - point1(numl + e) = nump + d - point2(numl + e) = nump + d - 11 - col(numl + e) = c + linePoint1(lineCount + e) = vertexCount + d + linePoint2(lineCount + e) = vertexCount + d - 11 + lineColor(lineCount + e) = c END IF NEXT y NEXT z - nump = nump + d - numl = numl + e + vertexCount = vertexCount + d + lineCount = lineCount + e END SUB SUB mkgr2 (x1, y1, z1) @@ -185,29 +185,29 @@ SUB mkgr2 (x1, y1, z1) FOR y = -500 TO 500 STEP 100 d = d + 1 - xn(nump + d) = x1 + x - yn(nump + d) = y1 + y - zn(nump + d) = z1 + vertexX(vertexCount + d) = x1 + x + vertexY(vertexCount + d) = y1 + y + vertexZ(vertexCount + d) = z1 IF y > -500 THEN e = e + 1 - point1(numl + e) = nump + d - point2(numl + e) = nump + d - 1 - col(numl + e) = c + linePoint1(lineCount + e) = vertexCount + d + linePoint2(lineCount + e) = vertexCount + d - 1 + lineColor(lineCount + e) = c END IF IF x > -500 THEN e = e + 1 - point1(numl + e) = nump + d - point2(numl + e) = nump + d - 11 - col(numl + e) = c + linePoint1(lineCount + e) = vertexCount + d + linePoint2(lineCount + e) = vertexCount + d - 11 + lineColor(lineCount + e) = c END IF NEXT y NEXT x - nump = nump + d - numl = numl + e + vertexCount = vertexCount + d + lineCount = lineCount + e END SUB SUB mkgr3 (x1, y1, z1) @@ -219,36 +219,36 @@ SUB mkgr3 (x1, y1, z1) FOR z = -500 TO 500 STEP 100 d = d + 1 - xn(nump + d) = x1 + x - yn(nump + d) = y1 - zn(nump + d) = z + vertexX(vertexCount + d) = x1 + x + vertexY(vertexCount + d) = y1 + vertexZ(vertexCount + d) = z IF z > -500 THEN e = e + 1 - point1(numl + e) = nump + d - point2(numl + e) = nump + d - 1 - col(numl + e) = c + linePoint1(lineCount + e) = vertexCount + d + linePoint2(lineCount + e) = vertexCount + d - 1 + lineColor(lineCount + e) = c END IF IF x > -500 THEN e = e + 1 - point1(numl + e) = nump + d - point2(numl + e) = nump + d - 11 - col(numl + e) = c + linePoint1(lineCount + e) = vertexCount + d + linePoint2(lineCount + e) = vertexCount + d - 11 + lineColor(lineCount + e) = c END IF NEXT z NEXT x - nump = nump + d - numl = numl + e + vertexCount = vertexCount + d + lineCount = lineCount + e END SUB SUB nait3d 1 -nump = tmnump -numl = tmnuml +vertexCount = tmvertexCount +lineCount = tmlineCount tm = tm + 1 graaf @@ -266,11 +266,11 @@ Deg2 = Deg2 + d2 C1 = COS(deg1): S1 = SIN(deg1) C2 = COS(Deg2): S2 = SIN(Deg2) -FOR a = 1 TO nump +FOR a = 1 TO vertexCount - xo = xn(a) - myx - yo = -yn(a) - myy - zo = zn(a) - myz + xo = vertexX(a) - myx + yo = -vertexY(a) - myy + zo = vertexZ(a) - myz x1 = (xo * C1 - zo * S1) z1 = (xo * S1 + zo * C1) @@ -289,15 +289,15 @@ FOR a = 1 TO nump END IF NEXT -FOR a = 1 TO numl - p1 = point1(a) - p2 = point2(a) +FOR a = 1 TO lineCount + p1 = linePoint1(a) + p2 = linePoint2(a) IF xo(p1) = -1 OR xo(p2) = -1 THEN ' Do nothing ELSE LINE (xo(p1), yo(p1))-(xo(p2), yo(p2)), 0 - LINE (x(p1), y(p1))-(x(p2), y(p2)), col(a) + LINE (x(p1), y(p1))-(x(p2), y(p2)), lineColor(a) END IF NEXT @@ -354,7 +354,6 @@ IF K$ <> "" THEN END SELECT END IF -_LIMIT (30) GOTO 1 END SUB @@ -364,11 +363,11 @@ SCREEN 12 CLS FOR a = 1 TO 4000 - col(a) = 15 + lineColor(a) = 15 NEXT a -nump = 0 -numl = 0 +vertexCount = 0 +lineCount = 0 getcor @@ -394,3 +393,4 @@ z = z + (SQR((15 + v) * (15 - v)) - 10) ' top of the ball 'z = z + 3 * ((-INT((x - .3) / 20) * INT((23 + x - ABS(y * 1.2)) / 15)) + -INT(-y / 20) * -INT(-x / 20) * INT(-((x - 2) * (x - 2) + (y * 1.2 - 4) * (y * 1.2 - 4)) / 2000 + 1.01) + -INT(y / 20) * -INT(-x / 20) * INT(-((x - 2) * (x - 2) + (y * 1.2 + 4) * (y * 1.2 + 4)) / 2000 + 1.01)) ' heart END SUB + -- 2.20.1