From: Svjatoslav Agejenko Date: Sun, 27 Oct 2024 13:25:30 +0000 (+0200) Subject: Using AI to improve code readability X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=fe66a8a978f9a76e965851af3080cd0b8e4fb1a1;p=qbasicapps.git Using AI to improve code readability --- diff --git a/Graphics/3D/rocket.bas b/Graphics/3D/rocket.bas index 497f549..ef6029d 100755 --- a/Graphics/3D/rocket.bas +++ b/Graphics/3D/rocket.bas @@ -1,9 +1,14 @@ ' 3D rocket simulator. Rocket takes off from the surface of the planet. -' made by Svjatoslav Agejenko -' in 2001 -' H-Page: svjatoslav.eu -' E-Mail: svjatoslav@svjatoslav.eu - +' +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu + +' Changelog: +' 2001, Initial version +' 2024, Improved program readability using AI +' +' Usage: ' arrow keys - move around ' 2, 6, 4, 8 - look around ' - - fly up @@ -17,24 +22,24 @@ DECLARE SUB teemaa () DECLARE SUB start () DECLARE SUB n3d () -DIM SHARED px(1 TO 1500) -DIM SHARED py(1 TO 1500) -DIM SHARED pz(1 TO 1500) +DIM SHARED pointX(1 TO 1500) +DIM SHARED pointY(1 TO 1500) +DIM SHARED pointZ(1 TO 1500) -DIM SHARED l1(1 TO 3000) -DIM SHARED l2(1 TO 3000) +DIM SHARED linePoint1(1 TO 3000) +DIM SHARED linePoint2(1 TO 3000) DIM SHARED lc(1 TO 3000) -DIM SHARED rpx(1 TO 1900) -DIM SHARED rpy(1 TO 1900) +DIM SHARED onScreenPointX(1 TO 1900) +DIM SHARED onScreenPointY(1 TO 1900) DIM SHARED rkx(1 TO 200) DIM SHARED rky(1 TO 200) DIM SHARED rkz(1 TO 200) -DIM SHARED mitp, mitl -DIM SHARED myx, myy, myz -DIM SHARED myxp, myyp, myzp +DIM SHARED pointCount, lineCount +DIM SHARED cameraX, cameraY, cameraZ +DIM SHARED cameraXSpeed, cameraYSpeed, cameraZSpeed DIM SHARED my1, my2 DIM SHARED ox1(1 TO 2500) @@ -59,9 +64,9 @@ rx = 0 ry = mk / 2 + .009 rz = 0 -myx = 0 -myy = mk / 2 -myz = -.05 +cameraX = 0 +cameraY = mk / 2 +cameraZ = -.05 ts = 0 frm2 = 999999 @@ -72,7 +77,7 @@ frm2 = frm2 + 1 ' Display the current values of some variables LOCATE 1, 1 -PRINT mitp, mitl, mk, mks +PRINT pointCount, lineCount, mk, mks LOCATE 2, 1 PRINT rkb, rke, TIMER @@ -87,15 +92,15 @@ rxp = SIN(frm / 20) / 50 ' Update the points that make up the rocket FOR a = 1 TO rkm - px(a + rkb - 1) = rkx(a) + rx - py(a + rkb - 1) = rky(a) + ry - pz(a + rkb - 1) = rkz(a) + rz + pointX(a + rkb - 1) = rkx(a) + rx + pointY(a + rkb - 1) = rky(a) + ry + pointZ(a + rkb - 1) = rkz(a) + rz NEXT a ' Update the observer position and velocity -myx = myx + (myxp * ts) -myy = myy + (myyp * ts) -myz = myz + (myzp * ts) +cameraX = cameraX + (cameraXSpeed * ts) +cameraY = cameraY + (cameraYSpeed * ts) +cameraZ = cameraZ + (cameraZSpeed * ts) ' Draw the 3D scene n3d @@ -105,23 +110,23 @@ a$ = INKEY$ IF a$ <> "" THEN IF a$ = CHR$(0) + "H" THEN ' Move forward - myzp = myzp - SIN(my1) / 100 - myxp = myxp + COS(my1) / 100 + cameraZSpeed = cameraZSpeed - SIN(my1) / 100 + cameraXSpeed = cameraXSpeed + COS(my1) / 100 END IF IF a$ = CHR$(0) + "P" THEN ' Move backward - myzp = myzp + SIN(my1) / 100 - myxp = myxp - COS(my1) / 100 + cameraZSpeed = cameraZSpeed + SIN(my1) / 100 + cameraXSpeed = cameraXSpeed - COS(my1) / 100 END IF IF a$ = CHR$(0) + "M" THEN ' Move right - myzp = myzp + COS(my1) / 100 - myxp = myxp + SIN(my1) / 100 + cameraZSpeed = cameraZSpeed + COS(my1) / 100 + cameraXSpeed = cameraXSpeed + SIN(my1) / 100 END IF IF a$ = CHR$(0) + "K" THEN ' Move left - myzp = myzp - COS(my1) / 100 - myxp = myxp - SIN(my1) / 100 + cameraZSpeed = cameraZSpeed - COS(my1) / 100 + cameraXSpeed = cameraXSpeed - SIN(my1) / 100 END IF ' Change the viewing angle @@ -130,9 +135,9 @@ IF a$ <> "" THEN IF a$ = "6" THEN my1 = my1 - .1 IF a$ = "2" THEN my2 = my2 + .1 IF a$ = "8" THEN my2 = my2 - .1 - IF a$ = "-" THEN myyp = myyp + .01 - IF a$ = "+" THEN myyp = myyp - .01 - IF a$ = " " THEN myzp = myzp / 2: myxp = myxp / 2 + IF a$ = "-" THEN cameraYSpeed = cameraYSpeed + .01 + IF a$ = "+" THEN cameraYSpeed = cameraYSpeed - .01 + IF a$ = " " THEN cameraZSpeed = cameraZSpeed / 2: cameraXSpeed = cameraXSpeed / 2 END IF ' Calculate the speed and distance of the rocket @@ -160,52 +165,52 @@ END IF GOTO 1 SUB addl -mitp = mitp + 1 -px(mitp) = rx -py(mitp) = ry -pz(mitp) = rz +pointCount = pointCount + 1 +pointX(pointCount) = rx +pointY(pointCount) = ry +pointZ(pointCount) = rz IF ale > 0 THEN - mitl = mitl + 1 - l1(mitl) = ale - l2(mitl) = mitp - lc(mitl) = 13 + lineCount = lineCount + 1 + linePoint1(lineCount) = ale + linePoint2(lineCount) = pointCount + lc(lineCount) = 13 END IF -ale = mitp +ale = pointCount END SUB SUB addp ' Add new points to the scene -mitp = mitp + 1 -px(mitp) = rx -py(mitp) = ry -pz(mitp) = rz - -mitp = mitp + 1 -px(mitp) = rx - .001 -py(mitp) = ry - .001 -pz(mitp) = rz - -mitp = mitp + 1 -px(mitp) = rx + .001 -py(mitp) = ry - .001 -pz(mitp) = rz - -mitl = mitl + 1 -l1(mitl) = mitp -l2(mitl) = mitp - 1 -lc(mitl) = 14 - -mitl = mitl + 1 -l1(mitl) = mitp - 2 -l2(mitl) = mitp - 1 -lc(mitl) = 14 - -mitl = mitl + 1 -l1(mitl) = mitp -l2(mitl) = mitp - 2 -lc(mitl) = 14 +pointCount = pointCount + 1 +pointX(pointCount) = rx +pointY(pointCount) = ry +pointZ(pointCount) = rz + +pointCount = pointCount + 1 +pointX(pointCount) = rx - .001 +pointY(pointCount) = ry - .001 +pointZ(pointCount) = rz + +pointCount = pointCount + 1 +pointX(pointCount) = rx + .001 +pointY(pointCount) = ry - .001 +pointZ(pointCount) = rz + +lineCount = lineCount + 1 +linePoint1(lineCount) = pointCount +linePoint2(lineCount) = pointCount - 1 +lc(lineCount) = 14 + +lineCount = lineCount + 1 +linePoint1(lineCount) = pointCount - 2 +linePoint2(lineCount) = pointCount - 1 +lc(lineCount) = 14 + +lineCount = lineCount + 1 +linePoint1(lineCount) = pointCount +linePoint2(lineCount) = pointCount - 2 +lc(lineCount) = 14 END SUB @@ -217,10 +222,10 @@ c1 = COS(my1) s2 = SIN(my2) c2 = COS(my2) -FOR a = 1 TO mitp - x = px(a) - myx - y = py(a) - myy - z = pz(a) - myz +FOR a = 1 TO pointCount + x = pointX(a) - cameraX + y = pointY(a) - cameraY + z = pointZ(a) - cameraZ ' Apply the rotation transformations x1 = x * s1 + z * c1 @@ -231,26 +236,26 @@ FOR a = 1 TO mitp ' Project the 3D point to 2D IF z2 < .00001 THEN - rpx(a) = -1 + onScreenPointX(a) = -1 ELSE - rpx(a) = x1 / z2 * 200 + 320 - rpy(a) = 240 - y1 / z2 * 200 + onScreenPointX(a) = x1 / z2 * 200 + 320 + onScreenPointY(a) = 240 - y1 / z2 * 200 ' Check if the point is within the screen boundaries - IF rpx(a) < -50 OR rpx(a) > 1000 OR rpy(a) > 1000 THEN - rpx(a) = -1 + IF onScreenPointX(a) < -50 OR onScreenPointX(a) > 1000 OR onScreenPointY(a) > 1000 THEN + onScreenPointX(a) = -1 END IF END IF NEXT a ' Draw the lines that make up the rocket -FOR a = 1 TO mitl - p1 = l1(a) - p2 = l2(a) - x1 = rpx(p1) - y1 = rpy(p1) - x2 = rpx(p2) - y2 = rpy(p2) +FOR a = 1 TO lineCount + p1 = linePoint1(a) + p2 = linePoint2(a) + x1 = onScreenPointX(p1) + y1 = onScreenPointY(p1) + x2 = onScreenPointX(p2) + y2 = onScreenPointY(p2) ' Check if the line is within the screen boundaries. ' If so, erase line at old locations @@ -286,58 +291,58 @@ rs = .00002 frm2 = 0 ale = -1 -px(1) = -.001 -py(1) = mk / 2 -pz(1) = -.001 +pointX(1) = -.001 +pointY(1) = mk / 2 +pointZ(1) = -.001 -px(2) = .001 -py(2) = mk / 2 -pz(2) = -.001 +pointX(2) = .001 +pointY(2) = mk / 2 +pointZ(2) = -.001 -px(3) = .001 -py(3) = mk / 2 -pz(3) = .001 +pointX(3) = .001 +pointY(3) = mk / 2 +pointZ(3) = .001 -px(4) = -.001 -py(4) = mk / 2 -pz(4) = .001 +pointX(4) = -.001 +pointY(4) = mk / 2 +pointZ(4) = .001 -mitp = 4 +pointCount = 4 ' Set up the initial lines that make up the rocket -l1(1) = 1 -l2(1) = 2 +linePoint1(1) = 1 +linePoint2(1) = 2 lc(1) = 14 -l1(2) = 2 -l2(2) = 3 +linePoint1(2) = 2 +linePoint2(2) = 3 lc(2) = 14 -l1(3) = 3 -l2(3) = 4 +linePoint1(3) = 3 +linePoint2(3) = 4 lc(3) = 14 -l1(4) = 4 -l2(4) = 1 +linePoint1(4) = 4 +linePoint2(4) = 1 lc(4) = 14 -mitl = 4 +lineCount = 4 ' Initialize the observer position and velocity -myx = 0 -myy = mk * 2 -myz = -35 +cameraX = 0 +cameraY = mk * 2 +cameraZ = -35 teemaa -myxp = 0 -myyp = 0 -myzp = 0 +cameraXSpeed = 0 +cameraYSpeed = 0 +cameraZSpeed = 0 my1 = 0 -rkb = mitp + 1 +rkb = pointCount + 1 teerock -rke = mitp +rke = pointCount ' Calculate the number of points that make up the rocket rkm = rke - rkb + 1 @@ -345,16 +350,16 @@ rkm = rke - rkb + 1 ' Copy the initial points to the arrays for the rocket FOR a = 1 TO rkm p = rkb + a - 1 - rkx(a) = px(p) - rky(a) = py(p) - rkz(a) = pz(p) + rkx(a) = pointX(p) + rky(a) = pointY(p) + rkz(a) = pointZ(p) NEXT a END SUB SUB teemaa ' Generate the points that make up the earth -tmpp = mitp +tmpp = pointCount le2 = 0 FOR z = -(mk / 3) TO (mk / 3) STEP mks @@ -372,18 +377,18 @@ FOR z = -(mk / 3) TO (mk / 3) STEP mks xs = x / mks END IF - mitp = mitp + 1 - px(mitp) = x + pointCount = pointCount + 1 + pointX(pointCount) = x v = SQR(x * x + z * z) - py(mitp) = SQR((v + (mk / 2)) * ((mk / 2) - v)) - pz(mitp) = z + pointY(pointCount) = SQR((v + (mk / 2)) * ((mk / 2) - v)) + pointZ(pointCount) = z ' Add the line to the list of lines IF le > 1 THEN - mitl = mitl + 1 - l1(mitl) = mitp - l2(mitl) = mitp - 1 - lc(mitl) = 3 + lineCount = lineCount + 1 + linePoint1(lineCount) = pointCount + linePoint2(lineCount) = pointCount - 1 + lc(lineCount) = 3 END IF ' Add the line to the list of lines if it is part of a circle @@ -391,10 +396,10 @@ FOR z = -(mk / 3) TO (mk / 3) STEP mks IF xso > (x / mks) THEN GOTO 4 IF xso + leo <= (x / mks) THEN GOTO 4 - mitl = mitl + 1 - l1(mitl) = mitp - l2(mitl) = mitp - leo - xso + xs - lc(mitl) = 3 + lineCount = lineCount + 1 + linePoint1(lineCount) = pointCount + linePoint2(lineCount) = pointCount - leo - xso + xs + lc(lineCount) = 3 END IF 4 @@ -426,100 +431,100 @@ FOR y = -9 TO 10 STEP rst x1 = SIN(a) * s z1 = COS(a) * s - mitp = mitp + 1 - px(mitp) = x1 * rs - py(mitp) = y * 50 * rs - pz(mitp) = z1 * rs + pointCount = pointCount + 1 + pointX(pointCount) = x1 * rs + pointY(pointCount) = y * 50 * rs + pointZ(pointCount) = z1 * rs ' Add the line to the list of lines IF a > 0 THEN - mitl = mitl + 1 - l1(mitl) = mitp - l2(mitl) = mitp - 1 - lc(mitl) = 10 + lineCount = lineCount + 1 + linePoint1(lineCount) = pointCount + linePoint2(lineCount) = pointCount - 1 + lc(lineCount) = 10 END IF ' Add the line to the list of lines if it is part of a circle IF y > -9 THEN - mitl = mitl + 1 - l1(mitl) = mitp - l2(mitl) = mitp - 7 - lc(mitl) = 10 + lineCount = lineCount + 1 + linePoint1(lineCount) = pointCount + linePoint2(lineCount) = pointCount - 7 + lc(lineCount) = 10 END IF NEXT a NEXT y ' Add the points that make up the top of the rocket -mitp = mitp + 1 -px(mitp) = 0 -py(mitp) = 11 * 50 * rs -pz(mitp) = 0 +pointCount = pointCount + 1 +pointX(pointCount) = 0 +pointY(pointCount) = 11 * 50 * rs +pointZ(pointCount) = 0 FOR a = 1 TO 6 - mitl = mitl + 1 - l1(mitl) = mitp - l2(mitl) = mitp - a - lc(mitl) = 10 + lineCount = lineCount + 1 + linePoint1(lineCount) = pointCount + linePoint2(lineCount) = pointCount - a + lc(lineCount) = 10 NEXT a ' Add the points that make up the bottom of the rocket -mitp = mitp + 1 -px(mitp) = -100 * rs -py(mitp) = -450 * rs -pz(mitp) = 0 - -mitp = mitp + 1 -px(mitp) = 100 * rs -py(mitp) = -450 * rs -pz(mitp) = 0 - -mitp = mitp + 1 -px(mitp) = 0 -py(mitp) = -200 * rs -pz(mitp) = 0 - -mitl = mitl + 1 -l1(mitl) = mitp -l2(mitl) = mitp - 1 -lc(mitl) = 12 - -mitl = mitl + 1 -l1(mitl) = mitp - 2 -l2(mitl) = mitp - 1 -lc(mitl) = 12 - -mitl = mitl + 1 -l1(mitl) = mitp -l2(mitl) = mitp - 2 -lc(mitl) = 12 - - - -mitp = mitp + 1 -px(mitp) = 0 -py(mitp) = -450 * rs -pz(mitp) = -100 * rs - -mitp = mitp + 1 -px(mitp) = 0 -py(mitp) = -450 * rs -pz(mitp) = 100 * rs - - -mitl = mitl + 1 -l1(mitl) = mitp -l2(mitl) = mitp - 1 -lc(mitl) = 12 - -mitl = mitl + 1 -l1(mitl) = mitp - 2 -l2(mitl) = mitp - 1 -lc(mitl) = 12 - -mitl = mitl + 1 -l1(mitl) = mitp -l2(mitl) = mitp - 2 -lc(mitl) = 12 +pointCount = pointCount + 1 +pointX(pointCount) = -100 * rs +pointY(pointCount) = -450 * rs +pointZ(pointCount) = 0 + +pointCount = pointCount + 1 +pointX(pointCount) = 100 * rs +pointY(pointCount) = -450 * rs +pointZ(pointCount) = 0 + +pointCount = pointCount + 1 +pointX(pointCount) = 0 +pointY(pointCount) = -200 * rs +pointZ(pointCount) = 0 + +lineCount = lineCount + 1 +linePoint1(lineCount) = pointCount +linePoint2(lineCount) = pointCount - 1 +lc(lineCount) = 12 + +lineCount = lineCount + 1 +linePoint1(lineCount) = pointCount - 2 +linePoint2(lineCount) = pointCount - 1 +lc(lineCount) = 12 + +lineCount = lineCount + 1 +linePoint1(lineCount) = pointCount +linePoint2(lineCount) = pointCount - 2 +lc(lineCount) = 12 + + + +pointCount = pointCount + 1 +pointX(pointCount) = 0 +pointY(pointCount) = -450 * rs +pointZ(pointCount) = -100 * rs + +pointCount = pointCount + 1 +pointX(pointCount) = 0 +pointY(pointCount) = -450 * rs +pointZ(pointCount) = 100 * rs + + +lineCount = lineCount + 1 +linePoint1(lineCount) = pointCount +linePoint2(lineCount) = pointCount - 1 +lc(lineCount) = 12 + +lineCount = lineCount + 1 +linePoint1(lineCount) = pointCount - 2 +linePoint2(lineCount) = pointCount - 1 +lc(lineCount) = 12 + +lineCount = lineCount + 1 +linePoint1(lineCount) = pointCount +linePoint2(lineCount) = pointCount - 2 +lc(lineCount) = 12 END SUB