From: Svjatoslav Agejenko Date: Sat, 26 Oct 2024 19:18:07 +0000 (+0300) Subject: Better file names X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=5418d931615e297999f699999b957d14ec7fe6f9;p=qbasicapps.git Better file names --- diff --git a/Graphics/3D/04vann2.bas b/Graphics/3D/04vann2.bas deleted file mode 100755 index 45eeba2..0000000 --- a/Graphics/3D/04vann2.bas +++ /dev/null @@ -1,501 +0,0 @@ -' Program renders 3D room with various decorative tiles on the wall and on the floor. -' User can freely fly around and look at the room from different angles. -' -' By Svjatoslav Agejenko. -' Email: svjatoslav@svjatoslav.eu -' Homepage: http://www.svjatoslav.eu -' -' Changelog: -' ?, Initial version -' 2024, Improved program readability using AI -' -' Keyboard controls: -' , , , - move around -' 2, 6, 4, 8 - look around (number pad) -' - speed down -' q - quit -' + / - - move up / down -' - - -DECLARE SUB renderSquare2 (x!, y!, z!, s!) -DECLARE SUB renderSquare (x%, y%, z%, s%) -DECLARE SUB renderHexagon (x!, y!, z!, s!) -DECLARE SUB generateCube () - -DECLARE SUB start () -DECLARE SUB addSquare (x1%, y1%, z1%) -DECLARE SUB getCornerVertices () -DECLARE SUB multiplyCoordinates () -DECLARE SUB calculateSine () -DIM SHARED xVertex(4000), yVertex(4000), zVertex(4000) -DIM SHARED xCoordinate(4000), yCoordinate(4000), zCoordinate(4000) - -DIM SHARED xOriginal(4000), yOriginal(4000), zOriginal(4000) -DIM SHARED point1Vertex(4000), point2Vertex(4000) -DIM SHARED col(4000) -DIM SHARED vertexCount, edgeCount -DIM SHARED myx, myy, myz, mye, myk - -myx = 0 -myy = 0 -myz = -1000 - -start - -nait3d - -SUB addSquare (x1%, y1%, z1%) - c = 1 - - ' Define the vertices of a square in 3D space - xVertex(vertexCount + 1) = -100 + x1 - yVertex(vertexCount + 1) = y1 - zVertex(vertexCount + 1) = -100 + z1 - - xVertex(vertexCount + 2) = 100 + x1 - yVertex(vertexCount + 2) = y1 - zVertex(vertexCount + 2) = -100 + z1 - - xVertex(vertexCount + 3) = 100 + x1 - yVertex(vertexCount + 3) = y1 - zVertex(vertexCount + 3) = 100 + z1 - - xVertex(vertexCount + 4) = -100 + x1 - yVertex(vertexCount + 4) = y1 - zVertex(vertexCount + 4) = 100 + z1 - - ' Define the edges of the square - point1Vertex(edgeCount + 1) = vertexCount + 1 - point2Vertex(edgeCount + 1) = vertexCount + 2 - col(edgeCount + 1) = c - - point1Vertex(edgeCount + 2) = vertexCount + 2 - point2Vertex(edgeCount + 2) = vertexCount + 3 - col(edgeCount + 2) = c - - point1Vertex(edgeCount + 3) = vertexCount + 3 - point2Vertex(edgeCount + 3) = vertexCount + 4 - col(edgeCount + 3) = c - - point1Vertex(edgeCount + 4) = vertexCount + 4 - point2Vertex(edgeCount + 4) = vertexCount + 1 - col(edgeCount + 4) = c - - ' Update the counters for the next square - vertexCount = vertexCount + 4 - edgeCount = edgeCount + 4 - -END SUB - -SUB getCornerVertices - - ' Define the vertices of a square in 3D space - xVertex(vertexCount + 1) = -150 - yVertex(vertexCount + 1) = -125 - zVertex(vertexCount + 1) = -200 - - xVertex(vertexCount + 2) = 150 - yVertex(vertexCount + 2) = -125 - zVertex(vertexCount + 2) = -200 - - xVertex(vertexCount + 3) = 150 - yVertex(vertexCount + 3) = 125 - zVertex(vertexCount + 3) = -200 - - xVertex(vertexCount + 4) = -150 - yVertex(vertexCount + 4) = 125 - zVertex(vertexCount + 4) = -200 - - ' Define the edges of the square - point1Vertex(edgeCount + 1) = vertexCount + 1 - point2Vertex(edgeCount + 1) = vertexCount + 2 - - point1Vertex(edgeCount + 2) = vertexCount + 2 - point2Vertex(edgeCount + 2) = vertexCount + 3 - - point1Vertex(edgeCount + 3) = vertexCount + 3 - point2Vertex(edgeCount + 3) = vertexCount + 4 - - point1Vertex(edgeCount + 4) = vertexCount + 4 - point2Vertex(edgeCount + 4) = vertexCount + 1 - - ' Define the vertices of another square in 3D space - xVertex(vertexCount + 5) = -150 - yVertex(vertexCount + 5) = -125 - zVertex(vertexCount + 5) = 200 - - xVertex(vertexCount + 6) = 150 - yVertex(vertexCount + 6) = -125 - zVertex(vertexCount + 6) = 200 - - xVertex(vertexCount + 7) = 150 - yVertex(vertexCount + 7) = 125 - zVertex(vertexCount + 7) = 200 - - xVertex(vertexCount + 8) = -150 - yVertex(vertexCount + 8) = 125 - zVertex(vertexCount + 8) = 200 - - ' Define the edges of the second square - point1Vertex(edgeCount + 5) = vertexCount + 5 - point2Vertex(edgeCount + 5) = vertexCount + 6 - - point1Vertex(edgeCount + 6) = vertexCount + 6 - point2Vertex(edgeCount + 6) = vertexCount + 7 - - point1Vertex(edgeCount + 7) = vertexCount + 7 - point2Vertex(edgeCount + 7) = vertexCount + 8 - - point1Vertex(edgeCount + 8) = vertexCount + 8 - point2Vertex(edgeCount + 8) = vertexCount + 5 - - ' Define the edges connecting the two squares into cube - point1Vertex(edgeCount + 9) = vertexCount + 5 - point2Vertex(edgeCount + 9) = vertexCount + 1 - - point1Vertex(edgeCount + 10) = vertexCount + 6 - point2Vertex(edgeCount + 10) = vertexCount + 2 - - point1Vertex(edgeCount + 11) = vertexCount + 7 - point2Vertex(edgeCount + 11) = vertexCount + 3 - - point1Vertex(edgeCount + 12) = vertexCount + 8 - point2Vertex(edgeCount + 12) = vertexCount + 4 - - ' Update the counters for the next set of vertices and edges - vertexCount = vertexCount + 8 - edgeCount = edgeCount + 12 - - ' Define a pyramid in 3D space - xVertex(vertexCount + 1) = -150 - yVertex(vertexCount + 1) = -125 + 201 - zVertex(vertexCount + 1) = 0 - - xVertex(vertexCount + 2) = -150 - yVertex(vertexCount + 2) = -125 + 201 - zVertex(vertexCount + 2) = 89 - - xVertex(vertexCount + 3) = -150 - yVertex(vertexCount + 3) = -125 - zVertex(vertexCount + 3) = 89 - - xVertex(vertexCount + 4) = -150 - yVertex(vertexCount + 4) = -125 - zVertex(vertexCount + 4) = 0 - - ' Define the edges of the pyramid - point1Vertex(edgeCount + 1) = vertexCount + 1 - point2Vertex(edgeCount + 1) = vertexCount + 2 - - point1Vertex(edgeCount + 2) = vertexCount + 2 - point2Vertex(edgeCount + 2) = vertexCount + 3 - - point1Vertex(edgeCount + 3) = vertexCount + 3 - point2Vertex(edgeCount + 3) = vertexCount + 4 - - point1Vertex(edgeCount + 4) = vertexCount + 4 - point2Vertex(edgeCount + 4) = vertexCount + 1 - - ' Update the counters for the next set of vertices and edges - vertexCount = vertexCount + 4 - edgeCount = edgeCount + 4 - -porand - -END SUB - -SUB renderHexagon (x, y, z, s) - -b = 0 -f = .3925 -' Calculate the vertices of a hexagon in 3D space -FOR a = 0 + f TO 6 + f STEP 6.28 / 8 - x1 = SIN(a) * s - y1 = COS(a) * s - b = b + 1 - - xVertex(vertexCount + b) = x + x1 - yVertex(vertexCount + b) = y - zVertex(vertexCount + b) = z + y1 - -NEXT a - -' Define the edges of the hexagon -point1Vertex(edgeCount + 1) = vertexCount + 1 -point2Vertex(edgeCount + 1) = vertexCount + 2 -col(edgeCount + 1) = 12 - -point1Vertex(edgeCount + 2) = vertexCount + 2 -point2Vertex(edgeCount + 2) = vertexCount + 3 -col(edgeCount + 2) = 12 - -point1Vertex(edgeCount + 3) = vertexCount + 3 -point2Vertex(edgeCount + 3) = vertexCount + 4 -col(edgeCount + 3) = 12 - -point1Vertex(edgeCount + 4) = vertexCount + 4 -point2Vertex(edgeCount + 4) = vertexCount + 5 -col(edgeCount + 4) = 12 - -point1Vertex(edgeCount + 5) = vertexCount + 5 -point2Vertex(edgeCount + 5) = vertexCount + 6 -col(edgeCount + 5) = 12 - -point1Vertex(edgeCount + 6) = vertexCount + 6 -point2Vertex(edgeCount + 6) = vertexCount + 7 -col(edgeCount + 6) = 12 - -point1Vertex(edgeCount + 7) = vertexCount + 7 -point2Vertex(edgeCount + 7) = vertexCount + 8 -col(edgeCount + 7) = 12 - -point1Vertex(edgeCount + 8) = vertexCount + 8 -point2Vertex(edgeCount + 8) = vertexCount + 1 -col(edgeCount + 8) = 12 - -' Update the counters for the next set of vertices and edges -vertexCount = vertexCount + b -edgeCount = edgeCount + 8 - -END SUB - -SUB nait3d - - ' Main loop to render the 3D scene -1 - - ' Update the position based on rotation - myx = myx + SIN(deg1) * mye - myz = myz + COS(deg1) * mye - - myx = myx + COS(deg1) * myk - myz = myz - SIN(deg1) * myk - - ' Update the rotation angles - deg1 = deg1 + d1 - Deg2 = Deg2 + d2 - - ' Calculate the rotation matrices - C1 = COS(deg1): S1 = SIN(deg1) - C2 = COS(Deg2): S2 = SIN(Deg2) - - ' Apply the rotation to each vertex - FOR a = 1 TO vertexCount - xo = xVertex(a) - myx - yo = -yVertex(a) - myy - zo = zVertex(a) - myz - - x1 = (xo * C1 - zo * S1) - z1 = (xo * S1 + zo * C1) - - y1 = (yo * C2 - z1 * S2) - z2 = (yo * S2 + z1 * C2) - - ' Project the vertex onto the 2D screen - xOriginal(a) = xCoordinate(a) - yOriginal(a) = yCoordinate(a) - IF z2 < 20 THEN - xCoordinate(a) = -1 - ELSE - xCoordinate(a) = 320 + (x1 / z2 * 500) - yCoordinate(a) = 240 + (y1 / z2 * 500) - END IF - NEXT - - ' Draw the edges of each shape - FOR a = 1 TO edgeCount - p1 = point1Vertex(a) - p2 = point2Vertex(a) - IF xOriginal(p1) = -1 OR xOriginal(p2) = -1 THEN - ' Skip drawing if the vertex is off-screen - ELSE - ' erase edge on old coordinates - LINE (xOriginal(p1), yOriginal(p1))-(xOriginal(p2), yOriginal(p2)), 0 - END IF - - IF xCoordinate(p1) = -1 OR xCoordinate(p2) = -1 THEN - ' Skip drawing if the vertex is off-screen - ELSE - ' draw edge on new coordinates - LINE (xCoordinate(p1), yCoordinate(p1))-(xCoordinate(p2), yCoordinate(p2)), col(a) - END IF - NEXT - - ' Handle user input - K$ = INKEY$ - IF K$ <> "" THEN - - SELECT CASE K$ - - CASE CHR$(0) + "P" - mye = mye - 3 - - CASE CHR$(0) + "H" - mye = mye + 3 - - CASE CHR$(0) + "M" - myk = myk + 3 - - CASE CHR$(0) + "K" - myk = myk - 3 - - CASE "+" - myy = myy + 3 - - CASE "-" - myy = myy - 3 - - CASE "6" - d1 = d1 + .01 - - CASE "4" - d1 = d1 - .01 - - CASE "8" - d2 = d2 - .01 - - CASE "2" - d2 = d2 + .01 - - CASE " " - d1 = d1 / 2 - d2 = d2 / 2 - d3 = d3 / 2 - mye = mye / 2 - myk = myk / 2 - - CASE "q" - SYSTEM - - CASE CHR$(27) - SYSTEM - END SELECT - END IF - - ' Continue the main loop - GOTO 1 -END SUB - -SUB porand - - ' Generate a grid of shapes in 3D space - FOR x = -100 TO 0 STEP 12.067 + .3 - FOR z = -100 TO 0 STEP 12.067 + .3 - renderHexagon x, -125, z, 6.53 - renderSquare x + 6.033 + .15, -125, z + 6.033 + .15, 3.111 + .3 - NEXT z - NEXT x - - ' Generate another grid of shapes in 3D space - FOR y = -100 TO 0 STEP 20.3 - FOR x = -100 TO 0 STEP 20.3 - renderSquare2 x, y, 200, 10 - NEXT x - NEXT y - -END SUB - -SUB renderSquare (x%, y%, z%, s%) - - ' Define the vertices of a square in 3D space - xVertex(vertexCount + 1) = x% - yVertex(vertexCount + 1) = y% - zVertex(vertexCount + 1) = z% + s% - - xVertex(vertexCount + 2) = x% + s% - yVertex(vertexCount + 2) = y% - zVertex(vertexCount + 2) = z% - - xVertex(vertexCount + 3) = x% - yVertex(vertexCount + 3) = y% - zVertex(vertexCount + 3) = z% - s% - - xVertex(vertexCount + 4) = x% - s% - yVertex(vertexCount + 4) = y% - zVertex(vertexCount + 4) = z% - - ' Define the edges of the square - point1Vertex(edgeCount + 1) = vertexCount + 1 - point2Vertex(edgeCount + 1) = vertexCount + 2 - col(edgeCount + 1) = 10 - - point1Vertex(edgeCount + 2) = vertexCount + 2 - point2Vertex(edgeCount + 2) = vertexCount + 3 - col(edgeCount + 2) = 10 - - point1Vertex(edgeCount + 3) = vertexCount + 3 - point2Vertex(edgeCount + 3) = vertexCount + 4 - col(edgeCount + 3) = 10 - - point1Vertex(edgeCount + 4) = vertexCount + 4 - point2Vertex(edgeCount + 4) = vertexCount + 1 - col(edgeCount + 4) = 10 - - ' Update the counters for the next square - vertexCount = vertexCount + 4 - edgeCount = edgeCount + 4 - -END SUB - -SUB renderSquare2 (x, y, z, s) - - ' Define the vertices of a square in 3D space - xVertex(vertexCount + 1) = x - s - yVertex(vertexCount + 1) = y - s - zVertex(vertexCount + 1) = z - - xVertex(vertexCount + 2) = x + s - yVertex(vertexCount + 2) = y - s - zVertex(vertexCount + 2) = z - - xVertex(vertexCount + 3) = x + s - yVertex(vertexCount + 3) = y + s - zVertex(vertexCount + 3) = z - - xVertex(vertexCount + 4) = x - s - yVertex(vertexCount + 4) = y + s - zVertex(vertexCount + 4) = z - - ' Define the edges of the square - point1Vertex(edgeCount + 1) = vertexCount + 1 - point2Vertex(edgeCount + 1) = vertexCount + 2 - col(edgeCount + 1) = 14 - - point1Vertex(edgeCount + 2) = vertexCount + 2 - point2Vertex(edgeCount + 2) = vertexCount + 3 - col(edgeCount + 2) = 14 - - point1Vertex(edgeCount + 3) = vertexCount + 3 - point2Vertex(edgeCount + 3) = vertexCount + 4 - col(edgeCount + 3) = 14 - - point1Vertex(edgeCount + 4) = vertexCount + 4 - point2Vertex(edgeCount + 4) = vertexCount + 1 - col(edgeCount + 4) = 14 - - ' Update the counters for the next square - vertexCount = vertexCount + 4 - edgeCount = edgeCount + 4 - -END SUB - -SUB start - - ' Initialize the screen and clear it - SCREEN 12 - CLS - - ' Set the initial color of all shapes - FOR a = 1 TO 4000 - col(a) = 15 - NEXT a - - ' Initialize counters for vertices and edges - vertexCount = 0 - edgeCount = 0 - - ' Generate the initial set of shapes - getCornerVertices - -END SUB diff --git a/Graphics/3D/3D game of life/3d life.bas b/Graphics/3D/3D game of life/3d life.bas new file mode 100755 index 0000000..e7f8bef --- /dev/null +++ b/Graphics/3D/3D game of life/3d life.bas @@ -0,0 +1,360 @@ +' Program renders rotating 3D animation from cubes. +' Cubes appear and disappear according to Conway's Game of Life rules. +' +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' ?, Initial version +' 2024, Improved program readability using AI + +DECLARE SUB PlaceCube (x!, y!, z!) +DECLARE SUB DrawCube (x!, y!, z!) + +DECLARE SUB CreateCollisionData () +DECLARE SUB UpdateCollisionData () +DECLARE SUB RenderScene () +DECLARE SUB InitializeEnvironment () +DECLARE SUB StartGame () + +DIM SHARED numPoints, numLines, pointCount, lineCount +DIM SHARED pointsX(1 TO 3000), pointsY(1 TO 3000), pointsZ(1 TO 3000) +DIM SHARED renderedPointsX(1 TO 7000), renderedPointsY(1 TO 7000) +DIM SHARED originalRenderedPointsX(0 TO 9000), originalRenderedPointsY(0 TO 9000) +DIM SHARED oldPointCount, oldLineCount +DIM SHARED lineVertices1(1 TO 3800), lineVertices2(1 TO 3800), lineColors(1 TO 3800) +DIM SHARED originalLineVertices1(1 TO 3800), originalLineVertices2(1 TO 3800) +DIM SHARED myPositionX, myPositionY, myPositionZ +DIM SHARED myPreviousPositionX, myPreviousPositionY, myPreviousPositionZ +DIM SHARED angle1, angle2 +DIM SHARED angle1Str, angle2Str +DIM SHARED frameCount + +DIM SHARED gameOfLifeGrid(1 TO 50, 1 TO 50) +DIM SHARED nextGameOfLifeGrid(1 TO 50, 1 TO 50) + +StartGame + +angle1 = 1.5 +10 +frameCount = frameCount + 1 + +CreateCollisionData +RenderScene + +myPositionX = SIN(frameCount / 20) * 12 +myPositionY = SIN(frameCount / 50) * 10 + 15 +myPositionZ = COS(frameCount / 20) * 12 + +angle1 = angle1 - .05 +angle2 = 2.2 + SIN(frameCount / 50) / 2 + +inputKey$ = INKEY$ +IF inputKey$ <> "" THEN SYSTEM +GOTO 10 + +SUB CreateCollisionData +pointCount = numPoints +lineCount = numLines + +FOR y = 1 TO 50 + FOR x = 1 TO 50 + IF gameOfLifeGrid(x, y) = 1 THEN + v = ABS(x - 26) + ABS(y - 26) + frameCount + PlaceCube x - 25, SIN(v / 5) * 5, y - 25 + END IF + NEXT x +NEXT y + +IF frameCount \ 10 = frameCount / 10 THEN + +FOR y = 2 TO 49 +FOR x = 2 TO 49 +c = gameOfLifeGrid(x - 1, y - 1) +c = c + gameOfLifeGrid(x, y - 1) +c = c + gameOfLifeGrid(x + 1, y - 1) +c = c + gameOfLifeGrid(x - 1, y) +c = c + gameOfLifeGrid(x + 1, y) +c = c + gameOfLifeGrid(x - 1, y + 1) +c = c + gameOfLifeGrid(x, y + 1) +c = c + gameOfLifeGrid(x + 1, y + 1) + +IF gameOfLifeGrid(x, y) = 1 THEN + IF (c > 3) OR (c < 2) THEN nextGameOfLifeGrid(x, y) = 0 ELSE nextGameOfLifeGrid(x, y) = 1 +ELSE + IF c = 3 THEN nextGameOfLifeGrid(x, y) = 1 ELSE nextGameOfLifeGrid(x, y) = 0 +END IF +NEXT x +NEXT y + +FOR y = 1 TO 50 +FOR x = 1 TO 50 + gameOfLifeGrid(x, y) = nextGameOfLifeGrid(x, y) +NEXT x +NEXT y +END IF + +END SUB + +SUB InitializeEnvironment +FOR z = -5 TO 5 +FOR x = -5 TO 5 +pointCount = pointCount + 1 +pointsX(pointCount) = x +pointsY(pointCount) = 0 +pointsZ(pointCount) = z +IF x > -5 THEN +lineCount = lineCount + 1 +lineVertices1(lineCount) = pointCount +lineVertices2(lineCount) = pointCount - 1 +lineColors(lineCount) = 1 +END IF +IF z > -5 THEN +lineCount = lineCount + 1 +lineVertices1(lineCount) = pointCount +lineVertices2(lineCount) = pointCount - 10 +lineColors(lineCount) = 1 +END IF +NEXT x +NEXT z + +numPoints = pointCount +numLines = lineCount + +END SUB + +SUB InitializeEnvironment1 +pointCount = 1 +pointsX(pointCount) = -2 +pointsY(pointCount) = 0 +pointsZ(pointCount) = 0 +pointCount = pointCount + 1 +pointsX(pointCount) = 2 +pointsY(pointCount) = 0 +pointsZ(pointCount) = 0 + +lineCount = 1 +lineVertices1(lineCount) = 1 +lineVertices2(lineCount) = 2 +lineColors(lineCount) = 14 + +END SUB + +SUB PlaceCube (x, y, z) + +v = 3 + +lineCount = lineCount + 1 +lineVertices1(lineCount) = pointCount + 1 +lineVertices2(lineCount) = pointCount + 2 +lineColors(lineCount) = v + +lineCount = lineCount + 1 +lineVertices1(lineCount) = pointCount + 2 +lineVertices2(lineCount) = pointCount + 3 +lineColors(lineCount) = v + +lineCount = lineCount + 1 +lineVertices1(lineCount) = pointCount + 3 +lineVertices2(lineCount) = pointCount + 4 +lineColors(lineCount) = v + +lineCount = lineCount + 1 +lineVertices1(lineCount) = pointCount + 4 +lineVertices2(lineCount) = pointCount + 1 +lineColors(lineCount) = v + +lineCount = lineCount + 1 +lineVertices1(lineCount) = pointCount + 5 +lineVertices2(lineCount) = pointCount + 6 +lineColors(lineCount) = v + +lineCount = lineCount + 1 +lineVertices1(lineCount) = pointCount + 6 +lineVertices2(lineCount) = pointCount + 7 +lineColors(lineCount) = v + +lineCount = lineCount + 1 +lineVertices1(lineCount) = pointCount + 7 +lineVertices2(lineCount) = pointCount + 8 +lineColors(lineCount) = v + +lineCount = lineCount + 1 +lineVertices1(lineCount) = pointCount + 8 +lineVertices2(lineCount) = pointCount + 5 +lineColors(lineCount) = v + +lineCount = lineCount + 1 +lineVertices1(lineCount) = pointCount + 1 +lineVertices2(lineCount) = pointCount + 5 +lineColors(lineCount) = v + +lineCount = lineCount + 1 +lineVertices1(lineCount) = pointCount + 2 +lineVertices2(lineCount) = pointCount + 6 +lineColors(lineCount) = v + +lineCount = lineCount + 1 +lineVertices1(lineCount) = pointCount + 3 +lineVertices2(lineCount) = pointCount + 7 +lineColors(lineCount) = v + +lineCount = lineCount + 1 +lineVertices1(lineCount) = pointCount + 4 +lineVertices2(lineCount) = pointCount + 8 +lineColors(lineCount) = v + +pointCount = pointCount + 1 +pointsX(pointCount) = x - .5 +pointsY(pointCount) = y +pointsZ(pointCount) = z - .5 + +pointCount = pointCount + 1 +pointsX(pointCount) = x + .5 +pointsY(pointCount) = y +pointsZ(pointCount) = z - .5 + +pointCount = pointCount + 1 +pointsX(pointCount) = x + .5 +pointsY(pointCount) = y +pointsZ(pointCount) = z + .5 + +pointCount = pointCount + 1 +pointsX(pointCount) = x - .5 +pointsY(pointCount) = y +pointsZ(pointCount) = z + .5 + +pointCount = pointCount + 1 +pointsX(pointCount) = x - .5 +pointsY(pointCount) = y + 1 +pointsZ(pointCount) = z - .5 + +pointCount = pointCount + 1 +pointsX(pointCount) = x + .5 +pointsY(pointCount) = y + 1 +pointsZ(pointCount) = z - .5 + +pointCount = pointCount + 1 +pointsX(pointCount) = x + .5 +pointsY(pointCount) = y + 1 +pointsZ(pointCount) = z + .5 + +pointCount = pointCount + 1 +pointsX(pointCount) = x - .5 +pointsY(pointCount) = y + 1 +pointsZ(pointCount) = z + .5 + +END SUB + +SUB RenderScene + +sineAngle1 = SIN(angle1) +cosineAngle1 = COS(angle1) +sineAngle2 = SIN(angle2) +cosineAngle2 = COS(angle2) + +FOR a = 1 TO pointCount +x = pointsX(a) + myPositionX +y = pointsY(a) - myPositionY +z = pointsZ(a) + myPositionZ + +x1 = x * sineAngle1 - z * cosineAngle1 +z1 = x * cosineAngle1 + z * sineAngle1 +y1 = y * sineAngle2 - z1 * cosineAngle2 +z2 = y * cosineAngle2 + z1 * sineAngle2 + +IF z2 < .5 THEN +renderedPointsX(a) = -1 +ELSE +renderedPointsX(a) = 320 + (x1 / z2 * 400) +renderedPointsY(a) = 240 - (y1 / z2 * 400) +END IF +NEXT a + +FOR a = 1 TO lineCount +l1 = originalLineVertices1(a) +l2 = originalLineVertices2(a) + +IF originalRenderedPointsX(l1) = -1 OR originalRenderedPointsX(l2) = -1 THEN +ELSE +LINE (originalRenderedPointsX(l1), originalRenderedPointsY(l1))-(originalRenderedPointsX(l2), originalRenderedPointsY(l2)), 0 +END IF + +l1 = lineVertices1(a) +l2 = lineVertices2(a) +IF renderedPointsX(l1) = -1 OR renderedPointsX(l2) = -1 THEN +ELSE +LINE (renderedPointsX(l1), renderedPointsY(l1))-(renderedPointsX(l2), renderedPointsY(l2)), lineColors(a) +END IF +NEXT a + +IF lineCount < oldLineCount THEN +FOR a = lineCount + 1 TO oldLineCount +l1 = originalLineVertices1(a) +l2 = originalLineVertices2(a) +IF originalRenderedPointsX(l1) = -1 OR originalRenderedPointsX(l2) = -1 THEN +ELSE +LINE (originalRenderedPointsX(l1), originalRenderedPointsY(l1))-(originalRenderedPointsX(l2), originalRenderedPointsY(l2)), 0 +END IF +NEXT a +END IF + +FOR a = 1 TO pointCount +originalRenderedPointsX(a) = renderedPointsX(a) +originalRenderedPointsY(a) = renderedPointsY(a) +NEXT a + +oldPointCount = pointCount + +FOR a = 1 TO lineCount +originalLineVertices1(a) = lineVertices1(a) +originalLineVertices2(a) = lineVertices2(a) +NEXT a + +oldLineCount = lineCount + +END SUB + +SUB StartGame +SCREEN 12 +numPoints = 0 +numLines = 0 +pointCount = numPoints +lineCount = numLines +gridSize = 50 + +myPositionX = 4 +myPositionY = 15 +myPositionZ = 17 +angle1 = ATN(1) / 2 - .29 +angle2 = angle1 + 1 + +FOR a = 1 TO 1000 +lineColors(a) = 4 +NEXT a + +FOR a = 1 TO 1000 +originalLineVertices1(a) = 1 +originalLineVertices2(a) = 1 +NEXT a + +OPEN "3dlife.dat" FOR INPUT AS #1 +y = 20 +20 +IF EOF(1) <> 0 THEN GOTO 30 +x = 20 + +LINE INPUT #1, inputLine$ +FOR b = 1 TO LEN(inputLine$) + c$ = RIGHT$(LEFT$(inputLine$, b), 1) + IF c$ = "#" THEN gameOfLifeGrid(x, y) = 1 + x = x + 1 +NEXT b + +y = y + 1 +GOTO 20 +30 +CLOSE #1 + +END SUB diff --git a/Graphics/3D/3D game of life/3dlife.dat b/Graphics/3D/3D game of life/3dlife.dat new file mode 100644 index 0000000..17b0e10 --- /dev/null +++ b/Graphics/3D/3D game of life/3dlife.dat @@ -0,0 +1,13 @@ +.....#.#..... +...##...##... +..#.......#.. +.#..##.##..#. +.#.#.....#.#. +#..#.###.#..# +.....#.#..... +#..#.###.#..# +.#.#.....#.#. +.#..##.##..#. +..#.......#.. +...##...##... +.....#.#..... diff --git a/Graphics/3D/3D text.bas b/Graphics/3D/3D text.bas new file mode 100755 index 0000000..945be4f --- /dev/null +++ b/Graphics/3D/3D text.bas @@ -0,0 +1,567 @@ +' Renders 3D text within 3D room. +' User can freely fly around the room and observe the text from different angles. +' +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 2003, Initial version +' 2024, Improved program readability using AI +' +' Keyboard controls: +' cursor keys and to z, w - rotate +' - slow down +' q and - quit program +' + / - - move up / down + + + +DECLARE SUB prn (x!, y!, a$) +DECLARE SUB pch (x!, y!, a$) +DECLARE SUB readfnt () +DECLARE SUB ruut2 (x!, y!, z!, s!) +DECLARE SUB ruut (x!, y!, z!, s!) +DECLARE SUB kuus (x, y, z, s) +DECLARE SUB porand () +DECLARE SUB addp (x, y, z) + +DECLARE SUB start () +DECLARE SUB addsq (x1%, y1%, z1%) +DECLARE SUB getcor () +DECLARE SUB mulcor () +DECLARE SUB nait3d () +DECLARE SUB calcsin () +DIM SHARED xn(4000), yn(4000), zn(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 myx, myy, myz, mye, myk +DIM SHARED tpx(0 TO 10, 0 TO 255) +DIM SHARED tpy(0 TO 10, 0 TO 255) +DIM SHARED tl1(0 TO 10, 0 TO 255) +DIM SHARED tl2(0 TO 10, 0 TO 255) + +myx = 0 +myy = 0 +myz = -100 + +start + +nait3d + +SUB getcor + +' Define the corners of a cube +xn(nump + 1) = -150 +yn(nump + 1) = -125 +zn(nump + 1) = -200 + +xn(nump + 2) = 150 +yn(nump + 2) = -125 +zn(nump + 2) = -200 + +xn(nump + 3) = 150 +yn(nump + 3) = 125 +zn(nump + 3) = -200 + +xn(nump + 4) = -150 +yn(nump + 4) = 125 +zn(nump + 4) = -200 + +xn(nump + 5) = -150 +yn(nump + 5) = -125 +zn(nump + 5) = 200 + +xn(nump + 6) = 150 +yn(nump + 6) = -125 +zn(nump + 6) = 200 + +xn(nump + 7) = 150 +yn(nump + 7) = 125 +zn(nump + 7) = 200 + +xn(nump + 8) = -150 +yn(nump + 8) = 125 +zn(nump + 8) = 200 + +' Define the lines connecting the corners +point1(numl + 1) = nump + 1 +point2(numl + 1) = nump + 2 + +point1(numl + 2) = nump + 2 +point2(numl + 2) = nump + 3 + +point1(numl + 3) = nump + 3 +point2(numl + 3) = nump + 4 + +point1(numl + 4) = nump + 4 +point2(numl + 4) = nump + 1 + +point1(numl + 5) = nump + 5 +point2(numl + 5) = nump + 6 + +point1(numl + 6) = nump + 6 +point2(numl + 6) = nump + 7 + +point1(numl + 7) = nump + 7 +point2(numl + 7) = nump + 8 + +point1(numl + 8) = nump + 8 +point2(numl + 8) = nump + 5 + +point1(numl + 9) = nump + 5 +point2(numl + 9) = nump + 1 + +point1(numl + 10) = nump + 6 +point2(numl + 10) = nump + 2 + +point1(numl + 11) = nump + 7 +point2(numl + 11) = nump + 3 + +point1(numl + 12) = nump + 8 +point2(numl + 12) = nump + 4 + +nump = nump + 8 +numl = numl + 12 + +' Define the corners of rectangle +xn(nump + 1) = -150 +yn(nump + 1) = -125 + 201 +zn(nump + 1) = 0 + +xn(nump + 2) = -150 +yn(nump + 2) = -125 + 201 +zn(nump + 2) = 89 + +xn(nump + 3) = -150 +yn(nump + 3) = -125 +zn(nump + 3) = 89 + +xn(nump + 4) = -150 +yn(nump + 4) = -125 +zn(nump + 4) = 0 + +' Define the lines connecting these corners +point1(numl + 1) = nump + 1 +point2(numl + 1) = nump + 2 + +point1(numl + 2) = nump + 2 +point2(numl + 2) = nump + 3 + +point1(numl + 3) = nump + 3 +point2(numl + 3) = nump + 4 + +point1(numl + 4) = nump + 4 +point2(numl + 4) = nump + 1 + +nump = nump + 4 +numl = numl + 4 + +prn 0, 0, "three dimensional " +prn 0, -3, "text example" +prn 0, -6, "etc etc etc" + +END SUB + +SUB kuus (x, y, z, s) + +' Initialize variables +b = 0 +f = .3925 + +' Loop to create points of the octagon +FOR a = 0 + f TO 6 + f STEP 6.28 / 8 + x1 = SIN(a) * s + y1 = COS(a) * s + b = b + 1 + + ' Store the points in the shared arrays + xn(nump + b) = x1 + x + yn(nump + b) = y + zn(nump + b) = y1 + z +NEXT a + +' Define the lines connecting these points +point1(numl + 1) = nump + 1 +point2(numl + 1) = nump + 2 +col(numl + 1) = 12 + +point1(numl + 2) = nump + 2 +point2(numl + 2) = nump + 3 +col(numl + 2) = 12 + +point1(numl + 3) = nump + 3 +point2(numl + 3) = nump + 4 +col(numl + 3) = 12 + +point1(numl + 4) = nump + 4 +point2(numl + 4) = nump + 5 +col(numl + 4) = 12 + +point1(numl + 5) = nump + 5 +point2(numl + 5) = nump + 6 +col(numl + 5) = 12 + +point1(numl + 6) = nump + 6 +point2(numl + 6) = nump + 7 +col(numl + 6) = 12 + +point1(numl + 7) = nump + 7 +point2(numl + 7) = nump + 8 +col(numl + 7) = 12 + +point1(numl + 8) = nump + 8 +point2(numl + 8) = nump + 1 +col(numl + 8) = 12 + +nump = nump + b +numl = numl + 8 + +'LOCATE 1, 1 +'PRINT b + +END SUB + +SUB nait3d + +' Main loop for the 3D rendering +1 + +myx = myx + SIN(deg1) * mye +myz = myz + COS(deg1) * mye + +myx = myx + COS(deg1) * myk +myz = myz - SIN(deg1) * myk + +deg1 = deg1 + d1 +Deg2 = Deg2 + d2 + +C1 = COS(deg1): S1 = SIN(deg1) +C2 = COS(Deg2): S2 = SIN(Deg2) + +' Transform the coordinates +FOR a = 1 TO nump + xo = xn(a) - myx + yo = -yn(a) - myy + zo = zn(a) - myz + + x1 = (xo * C1 - zo * S1) + z1 = (xo * S1 + zo * C1) + + y1 = (yo * C2 - z1 * S2) + z2 = (yo * S2 + z1 * C2) + + ' Store the transformed coordinates + xo(a) = x(a) + yo(a) = y(a) + + ' Check if the point is within the view + IF z2 < 20 THEN + x(a) = -1 + ELSE + ' Apply perspective transformation + x(a) = 320 + (x1 / z2 * 500) + y(a) = 240 + (y1 / z2 * 500) + END IF +NEXT + +' Draw the lines +FOR a = 1 TO numl + p1 = point1(a) + p2 = point2(a) + + ' Check if the points are within the view + IF xo(p1) = -1 OR xo(p2) = -1 THEN + ' Do nothing + ELSE + ' erase line at old coordinates + LINE (xo(p1), yo(p1))-(xo(p2), yo(p2)), 0 + END IF + + IF x(p1) = -1 OR x(p2) = -1 THEN + ' Do nothing + ELSE + ' draw line at new coordinates + LINE (x(p1), y(p1))-(x(p2), y(p2)), col(a) + END IF +NEXT + +' Handle user input +K$ = INKEY$ +IF K$ <> "" THEN + + SELECT CASE K$ + + CASE CHR$(0) + "P" + mye = mye - 1 + + CASE CHR$(0) + "H" + mye = mye + 1 + + CASE CHR$(0) + "M" + myk = myk + 1 + + CASE CHR$(0) + "K" + myk = myk - 1 + + CASE "+" + myy = myy + 3 + + CASE "-" + myy = myy - 3 + + CASE "6" + d1 = d1 + .01 + + CASE "4" + d1 = d1 - .01 + + CASE "8" + d2 = d2 - .01 + + CASE "2" + d2 = d2 + .01 + + CASE " " + d1 = d1 / 2 + d2 = d2 / 2 + d3 = d3 / 2 + mye = mye / 2 + myk = myk / 2 + + CASE "q" + SYSTEM + + CASE CHR$(27) + SYSTEM + + END SELECT +END IF + +GOTO 1 + +END SUB + +SUB pch (x, y, a$) + +' Initialize variables +b = ASC(a$) +up = 0 +ul = 0 + +' Loop to create points for the character +FOR c = 0 TO 100 + IF tpx(c, b) = 999 THEN GOTO 4 + up = up + 1 + xn(nump + up) = x + tpx(c, b) + yn(nump + up) = y - tpy(c, b) + zn(nump + up) = 0 +NEXT c +4 + +' Loop to define the lines for the character +FOR c = 0 TO 100 + IF tl1(c, b) = 999 THEN GOTO 5 + ul = ul + 1 + point1(numl + ul) = tl1(c, b) + nump + 1 + point2(numl + ul) = tl2(c, b) + nump + 1 + col(numl + ul) = 4 +NEXT c +5 + +' Update the counters +nump = nump + up +numl = numl + ul + +END SUB + +SUB porand +' do floor of the 3D room + +' Loop to create floor tiles made of hexagons and squares +FOR x = -100 TO 0 STEP 12.067 + .3 + FOR z = -100 TO 0 STEP 12.067 + .3 + kuus x, -125, z, 6.53 + ruut x + 6.033 + .15, -125, z + 6.033 + .15, 3.111 + .3 + NEXT z +NEXT x + +' Loop to create squares +FOR y = -100 TO 0 STEP 20.3 + FOR x = -100 TO 0 STEP 20.3 + ruut2 x, y, 200, 10 + NEXT x +NEXT y + +END SUB + +SUB prn (x, y, a$) + +' Loop to print each character +FOR b = 1 TO LEN(a$) + c$ = RIGHT$(LEFT$(a$, b), 1) + pch x + b * 3, y, c$ +NEXT b + +END SUB + +SUB readfnt + +' Open the font file +OPEN "font.dat" FOR INPUT AS #1 + +' Loop to read the font data +3 +IF EOF(1) <> 0 THEN GOTO 2 +LINE INPUT #1, a$ + +IF LEFT$(a$, 1) = "#" THEN + chr = ASC(RIGHT$(LEFT$(a$, 3), 1)) + + ' Initialize counters + pp = 0 + lp = 0 +END IF + +' read the points for the character +IF LEFT$(a$, 1) = "p" THEN + tpx(pp, chr) = VAL(RIGHT$(LEFT$(a$, 3), 1)) + tpy(pp, chr) = VAL(RIGHT$(LEFT$(a$, 5), 1)) + pp = pp + 1 +END IF + +' read the lines for the character +IF LEFT$(a$, 1) = "l" THEN + tl1(lp, chr) = VAL(RIGHT$(LEFT$(a$, 3), 1)) + tl2(lp, chr) = VAL(RIGHT$(LEFT$(a$, 5), 1)) + lp = lp + 1 +END IF + +GOTO 3 + +' Close the font file +2 +CLOSE #1 + +END SUB + +SUB ruut (x, y, z, s) + +' Define the corners of the rectangle +xn(nump + 1) = x +yn(nump + 1) = y +zn(nump + 1) = z + s + +xn(nump + 2) = x + s +yn(nump + 2) = y +zn(nump + 2) = z + +xn(nump + 3) = x +yn(nump + 3) = y +zn(nump + 3) = z - s + +xn(nump + 4) = x - s +yn(nump + 4) = y +zn(nump + 4) = z + +' Define the lines connecting these corners +point1(numl + 1) = nump + 1 +point2(numl + 1) = nump + 2 +col(numl + 1) = 10 + +point1(numl + 2) = nump + 2 +point2(numl + 2) = nump + 3 +col(numl + 2) = 10 + +point1(numl + 3) = nump + 3 +point2(numl + 3) = nump + 4 +col(numl + 3) = 10 + +point1(numl + 4) = nump + 4 +point2(numl + 4) = nump + 1 +col(numl + 4) = 10 + +' Update the counters +nump = nump + 4 +numl = numl + 4 + +END SUB + +SUB ruut2 (x, y, z, s) + +' Define the corners of the rectangle +xn(nump + 1) = x - s +yn(nump + 1) = y - s +zn(nump + 1) = z + +xn(nump + 2) = x + s +yn(nump + 2) = y - s +zn(nump + 2) = z + +xn(nump + 3) = x + s +yn(nump + 3) = y + s +zn(nump + 3) = z + +xn(nump + 4) = x - s +yn(nump + 4) = y + s +zn(nump + 4) = z + +' Define the lines connecting these corners +point1(numl + 1) = nump + 1 +point2(numl + 1) = nump + 2 +col(numl + 1) = 14 + +point1(numl + 2) = nump + 2 +point2(numl + 2) = nump + 3 +col(numl + 2) = 14 + +point1(numl + 3) = nump + 3 +point2(numl + 3) = nump + 4 +col(numl + 3) = 14 + +point1(numl + 4) = nump + 4 +point2(numl + 4) = nump + 1 +col(numl + 4) = 14 + +' Update the counters +nump = nump + 4 +numl = numl + 4 + +END SUB + +SUB start + +' Initialize the screen and clear it +SCREEN 12 +CLS + +' Set the default color for all points +FOR a = 1 TO 4000 + col(a) = 15 +NEXT a + +' Initialize counters +nump = 0 +numl = 0 + +' Initialize font data +FOR a = 0 TO 255 + FOR b = 0 TO 10 + tpx(b, a) = 999 + tpy(b, a) = 999 + tl1(b, a) = 999 + tl2(b, a) = 999 + NEXT b +NEXT a + +' Read the font data +readfnt + +' Define the corners of the cubes +getcor + +END SUB diff --git a/Graphics/3D/3dlife.bas b/Graphics/3D/3dlife.bas deleted file mode 100755 index 274a345..0000000 --- a/Graphics/3D/3dlife.bas +++ /dev/null @@ -1,352 +0,0 @@ -' Program renders rotating 3D animation from cubes. -' Cubes appear and disappear according to Conway's Game of Life rules. - -DECLARE SUB PlaceCube (x!, y!, z!) -DECLARE SUB DrawCube (x!, y!, z!) - -DECLARE SUB CreateCollisionData () -DECLARE SUB UpdateCollisionData () -DECLARE SUB RenderScene () -DECLARE SUB InitializeEnvironment () -DECLARE SUB StartGame () - -DIM SHARED numPoints, numLines, pointCount, lineCount -DIM SHARED pointsX(1 TO 3000), pointsY(1 TO 3000), pointsZ(1 TO 3000) -DIM SHARED renderedPointsX(1 TO 7000), renderedPointsY(1 TO 7000) -DIM SHARED originalRenderedPointsX(0 TO 9000), originalRenderedPointsY(0 TO 9000) -DIM SHARED oldPointCount, oldLineCount -DIM SHARED lineVertices1(1 TO 3800), lineVertices2(1 TO 3800), lineColors(1 TO 3800) -DIM SHARED originalLineVertices1(1 TO 3800), originalLineVertices2(1 TO 3800) -DIM SHARED myPositionX, myPositionY, myPositionZ -DIM SHARED myPreviousPositionX, myPreviousPositionY, myPreviousPositionZ -DIM SHARED angle1, angle2 -DIM SHARED angle1Str, angle2Str -DIM SHARED frameCount - -DIM SHARED gameOfLifeGrid(1 TO 50, 1 TO 50) -DIM SHARED nextGameOfLifeGrid(1 TO 50, 1 TO 50) - -StartGame - -angle1 = 1.5 -10 -frameCount = frameCount + 1 - -CreateCollisionData -RenderScene - -myPositionX = SIN(frameCount / 20) * 12 -myPositionY = SIN(frameCount / 50) * 10 + 15 -myPositionZ = COS(frameCount / 20) * 12 - -angle1 = angle1 - .05 -angle2 = 2.2 + SIN(frameCount / 50) / 2 - -inputKey$ = INKEY$ -IF inputKey$ <> "" THEN SYSTEM -GOTO 10 - -SUB CreateCollisionData -pointCount = numPoints -lineCount = numLines - -FOR y = 1 TO 50 - FOR x = 1 TO 50 - IF gameOfLifeGrid(x, y) = 1 THEN - v = ABS(x - 26) + ABS(y - 26) + frameCount - PlaceCube x - 25, SIN(v / 5) * 5, y - 25 - END IF - NEXT x -NEXT y - -IF frameCount \ 10 = frameCount / 10 THEN - -FOR y = 2 TO 49 -FOR x = 2 TO 49 -c = gameOfLifeGrid(x - 1, y - 1) -c = c + gameOfLifeGrid(x, y - 1) -c = c + gameOfLifeGrid(x + 1, y - 1) -c = c + gameOfLifeGrid(x - 1, y) -c = c + gameOfLifeGrid(x + 1, y) -c = c + gameOfLifeGrid(x - 1, y + 1) -c = c + gameOfLifeGrid(x, y + 1) -c = c + gameOfLifeGrid(x + 1, y + 1) - -IF gameOfLifeGrid(x, y) = 1 THEN - IF (c > 3) OR (c < 2) THEN nextGameOfLifeGrid(x, y) = 0 ELSE nextGameOfLifeGrid(x, y) = 1 -ELSE - IF c = 3 THEN nextGameOfLifeGrid(x, y) = 1 ELSE nextGameOfLifeGrid(x, y) = 0 -END IF -NEXT x -NEXT y - -FOR y = 1 TO 50 -FOR x = 1 TO 50 - gameOfLifeGrid(x, y) = nextGameOfLifeGrid(x, y) -NEXT x -NEXT y -END IF - -END SUB - -SUB InitializeEnvironment -FOR z = -5 TO 5 -FOR x = -5 TO 5 -pointCount = pointCount + 1 -pointsX(pointCount) = x -pointsY(pointCount) = 0 -pointsZ(pointCount) = z -IF x > -5 THEN -lineCount = lineCount + 1 -lineVertices1(lineCount) = pointCount -lineVertices2(lineCount) = pointCount - 1 -lineColors(lineCount) = 1 -END IF -IF z > -5 THEN -lineCount = lineCount + 1 -lineVertices1(lineCount) = pointCount -lineVertices2(lineCount) = pointCount - 10 -lineColors(lineCount) = 1 -END IF -NEXT x -NEXT z - -numPoints = pointCount -numLines = lineCount - -END SUB - -SUB InitializeEnvironment1 -pointCount = 1 -pointsX(pointCount) = -2 -pointsY(pointCount) = 0 -pointsZ(pointCount) = 0 -pointCount = pointCount + 1 -pointsX(pointCount) = 2 -pointsY(pointCount) = 0 -pointsZ(pointCount) = 0 - -lineCount = 1 -lineVertices1(lineCount) = 1 -lineVertices2(lineCount) = 2 -lineColors(lineCount) = 14 - -END SUB - -SUB PlaceCube (x, y, z) - -v = 3 - -lineCount = lineCount + 1 -lineVertices1(lineCount) = pointCount + 1 -lineVertices2(lineCount) = pointCount + 2 -lineColors(lineCount) = v - -lineCount = lineCount + 1 -lineVertices1(lineCount) = pointCount + 2 -lineVertices2(lineCount) = pointCount + 3 -lineColors(lineCount) = v - -lineCount = lineCount + 1 -lineVertices1(lineCount) = pointCount + 3 -lineVertices2(lineCount) = pointCount + 4 -lineColors(lineCount) = v - -lineCount = lineCount + 1 -lineVertices1(lineCount) = pointCount + 4 -lineVertices2(lineCount) = pointCount + 1 -lineColors(lineCount) = v - -lineCount = lineCount + 1 -lineVertices1(lineCount) = pointCount + 5 -lineVertices2(lineCount) = pointCount + 6 -lineColors(lineCount) = v - -lineCount = lineCount + 1 -lineVertices1(lineCount) = pointCount + 6 -lineVertices2(lineCount) = pointCount + 7 -lineColors(lineCount) = v - -lineCount = lineCount + 1 -lineVertices1(lineCount) = pointCount + 7 -lineVertices2(lineCount) = pointCount + 8 -lineColors(lineCount) = v - -lineCount = lineCount + 1 -lineVertices1(lineCount) = pointCount + 8 -lineVertices2(lineCount) = pointCount + 5 -lineColors(lineCount) = v - -lineCount = lineCount + 1 -lineVertices1(lineCount) = pointCount + 1 -lineVertices2(lineCount) = pointCount + 5 -lineColors(lineCount) = v - -lineCount = lineCount + 1 -lineVertices1(lineCount) = pointCount + 2 -lineVertices2(lineCount) = pointCount + 6 -lineColors(lineCount) = v - -lineCount = lineCount + 1 -lineVertices1(lineCount) = pointCount + 3 -lineVertices2(lineCount) = pointCount + 7 -lineColors(lineCount) = v - -lineCount = lineCount + 1 -lineVertices1(lineCount) = pointCount + 4 -lineVertices2(lineCount) = pointCount + 8 -lineColors(lineCount) = v - -pointCount = pointCount + 1 -pointsX(pointCount) = x - .5 -pointsY(pointCount) = y -pointsZ(pointCount) = z - .5 - -pointCount = pointCount + 1 -pointsX(pointCount) = x + .5 -pointsY(pointCount) = y -pointsZ(pointCount) = z - .5 - -pointCount = pointCount + 1 -pointsX(pointCount) = x + .5 -pointsY(pointCount) = y -pointsZ(pointCount) = z + .5 - -pointCount = pointCount + 1 -pointsX(pointCount) = x - .5 -pointsY(pointCount) = y -pointsZ(pointCount) = z + .5 - -pointCount = pointCount + 1 -pointsX(pointCount) = x - .5 -pointsY(pointCount) = y + 1 -pointsZ(pointCount) = z - .5 - -pointCount = pointCount + 1 -pointsX(pointCount) = x + .5 -pointsY(pointCount) = y + 1 -pointsZ(pointCount) = z - .5 - -pointCount = pointCount + 1 -pointsX(pointCount) = x + .5 -pointsY(pointCount) = y + 1 -pointsZ(pointCount) = z + .5 - -pointCount = pointCount + 1 -pointsX(pointCount) = x - .5 -pointsY(pointCount) = y + 1 -pointsZ(pointCount) = z + .5 - -END SUB - -SUB RenderScene - -sineAngle1 = SIN(angle1) -cosineAngle1 = COS(angle1) -sineAngle2 = SIN(angle2) -cosineAngle2 = COS(angle2) - -FOR a = 1 TO pointCount -x = pointsX(a) + myPositionX -y = pointsY(a) - myPositionY -z = pointsZ(a) + myPositionZ - -x1 = x * sineAngle1 - z * cosineAngle1 -z1 = x * cosineAngle1 + z * sineAngle1 -y1 = y * sineAngle2 - z1 * cosineAngle2 -z2 = y * cosineAngle2 + z1 * sineAngle2 - -IF z2 < .5 THEN -renderedPointsX(a) = -1 -ELSE -renderedPointsX(a) = 320 + (x1 / z2 * 400) -renderedPointsY(a) = 240 - (y1 / z2 * 400) -END IF -NEXT a - -FOR a = 1 TO lineCount -l1 = originalLineVertices1(a) -l2 = originalLineVertices2(a) - -IF originalRenderedPointsX(l1) = -1 OR originalRenderedPointsX(l2) = -1 THEN -ELSE -LINE (originalRenderedPointsX(l1), originalRenderedPointsY(l1))-(originalRenderedPointsX(l2), originalRenderedPointsY(l2)), 0 -END IF - -l1 = lineVertices1(a) -l2 = lineVertices2(a) -IF renderedPointsX(l1) = -1 OR renderedPointsX(l2) = -1 THEN -ELSE -LINE (renderedPointsX(l1), renderedPointsY(l1))-(renderedPointsX(l2), renderedPointsY(l2)), lineColors(a) -END IF -NEXT a - -IF lineCount < oldLineCount THEN -FOR a = lineCount + 1 TO oldLineCount -l1 = originalLineVertices1(a) -l2 = originalLineVertices2(a) -IF originalRenderedPointsX(l1) = -1 OR originalRenderedPointsX(l2) = -1 THEN -ELSE -LINE (originalRenderedPointsX(l1), originalRenderedPointsY(l1))-(originalRenderedPointsX(l2), originalRenderedPointsY(l2)), 0 -END IF -NEXT a -END IF - -FOR a = 1 TO pointCount -originalRenderedPointsX(a) = renderedPointsX(a) -originalRenderedPointsY(a) = renderedPointsY(a) -NEXT a - -oldPointCount = pointCount - -FOR a = 1 TO lineCount -originalLineVertices1(a) = lineVertices1(a) -originalLineVertices2(a) = lineVertices2(a) -NEXT a - -oldLineCount = lineCount - -END SUB - -SUB StartGame -SCREEN 12 -numPoints = 0 -numLines = 0 -pointCount = numPoints -lineCount = numLines -gridSize = 50 - -myPositionX = 4 -myPositionY = 15 -myPositionZ = 17 -angle1 = ATN(1) / 2 - .29 -angle2 = angle1 + 1 - -FOR a = 1 TO 1000 -lineColors(a) = 4 -NEXT a - -FOR a = 1 TO 1000 -originalLineVertices1(a) = 1 -originalLineVertices2(a) = 1 -NEXT a - -OPEN "3dlife.dat" FOR INPUT AS #1 -y = 20 -20 -IF EOF(1) <> 0 THEN GOTO 30 -x = 20 - -LINE INPUT #1, inputLine$ -FOR b = 1 TO LEN(inputLine$) - c$ = RIGHT$(LEFT$(inputLine$, b), 1) - IF c$ = "#" THEN gameOfLifeGrid(x, y) = 1 - x = x + 1 -NEXT b - -y = y + 1 -GOTO 20 -30 -CLOSE #1 - -END SUB diff --git a/Graphics/3D/3dlife.dat b/Graphics/3D/3dlife.dat deleted file mode 100644 index 17b0e10..0000000 --- a/Graphics/3D/3dlife.dat +++ /dev/null @@ -1,13 +0,0 @@ -.....#.#..... -...##...##... -..#.......#.. -.#..##.##..#. -.#.#.....#.#. -#..#.###.#..# -.....#.#..... -#..#.###.#..# -.#.#.....#.#. -.#..##.##..#. -..#.......#.. -...##...##... -.....#.#..... diff --git a/Graphics/3D/3dtext.bas b/Graphics/3D/3dtext.bas deleted file mode 100755 index 945be4f..0000000 --- a/Graphics/3D/3dtext.bas +++ /dev/null @@ -1,567 +0,0 @@ -' Renders 3D text within 3D room. -' User can freely fly around the room and observe the text from different angles. -' -' By Svjatoslav Agejenko. -' Email: svjatoslav@svjatoslav.eu -' Homepage: http://www.svjatoslav.eu -' -' Changelog: -' 2003, Initial version -' 2024, Improved program readability using AI -' -' Keyboard controls: -' cursor keys and to z, w - rotate -' - slow down -' q and - quit program -' + / - - move up / down - - - -DECLARE SUB prn (x!, y!, a$) -DECLARE SUB pch (x!, y!, a$) -DECLARE SUB readfnt () -DECLARE SUB ruut2 (x!, y!, z!, s!) -DECLARE SUB ruut (x!, y!, z!, s!) -DECLARE SUB kuus (x, y, z, s) -DECLARE SUB porand () -DECLARE SUB addp (x, y, z) - -DECLARE SUB start () -DECLARE SUB addsq (x1%, y1%, z1%) -DECLARE SUB getcor () -DECLARE SUB mulcor () -DECLARE SUB nait3d () -DECLARE SUB calcsin () -DIM SHARED xn(4000), yn(4000), zn(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 myx, myy, myz, mye, myk -DIM SHARED tpx(0 TO 10, 0 TO 255) -DIM SHARED tpy(0 TO 10, 0 TO 255) -DIM SHARED tl1(0 TO 10, 0 TO 255) -DIM SHARED tl2(0 TO 10, 0 TO 255) - -myx = 0 -myy = 0 -myz = -100 - -start - -nait3d - -SUB getcor - -' Define the corners of a cube -xn(nump + 1) = -150 -yn(nump + 1) = -125 -zn(nump + 1) = -200 - -xn(nump + 2) = 150 -yn(nump + 2) = -125 -zn(nump + 2) = -200 - -xn(nump + 3) = 150 -yn(nump + 3) = 125 -zn(nump + 3) = -200 - -xn(nump + 4) = -150 -yn(nump + 4) = 125 -zn(nump + 4) = -200 - -xn(nump + 5) = -150 -yn(nump + 5) = -125 -zn(nump + 5) = 200 - -xn(nump + 6) = 150 -yn(nump + 6) = -125 -zn(nump + 6) = 200 - -xn(nump + 7) = 150 -yn(nump + 7) = 125 -zn(nump + 7) = 200 - -xn(nump + 8) = -150 -yn(nump + 8) = 125 -zn(nump + 8) = 200 - -' Define the lines connecting the corners -point1(numl + 1) = nump + 1 -point2(numl + 1) = nump + 2 - -point1(numl + 2) = nump + 2 -point2(numl + 2) = nump + 3 - -point1(numl + 3) = nump + 3 -point2(numl + 3) = nump + 4 - -point1(numl + 4) = nump + 4 -point2(numl + 4) = nump + 1 - -point1(numl + 5) = nump + 5 -point2(numl + 5) = nump + 6 - -point1(numl + 6) = nump + 6 -point2(numl + 6) = nump + 7 - -point1(numl + 7) = nump + 7 -point2(numl + 7) = nump + 8 - -point1(numl + 8) = nump + 8 -point2(numl + 8) = nump + 5 - -point1(numl + 9) = nump + 5 -point2(numl + 9) = nump + 1 - -point1(numl + 10) = nump + 6 -point2(numl + 10) = nump + 2 - -point1(numl + 11) = nump + 7 -point2(numl + 11) = nump + 3 - -point1(numl + 12) = nump + 8 -point2(numl + 12) = nump + 4 - -nump = nump + 8 -numl = numl + 12 - -' Define the corners of rectangle -xn(nump + 1) = -150 -yn(nump + 1) = -125 + 201 -zn(nump + 1) = 0 - -xn(nump + 2) = -150 -yn(nump + 2) = -125 + 201 -zn(nump + 2) = 89 - -xn(nump + 3) = -150 -yn(nump + 3) = -125 -zn(nump + 3) = 89 - -xn(nump + 4) = -150 -yn(nump + 4) = -125 -zn(nump + 4) = 0 - -' Define the lines connecting these corners -point1(numl + 1) = nump + 1 -point2(numl + 1) = nump + 2 - -point1(numl + 2) = nump + 2 -point2(numl + 2) = nump + 3 - -point1(numl + 3) = nump + 3 -point2(numl + 3) = nump + 4 - -point1(numl + 4) = nump + 4 -point2(numl + 4) = nump + 1 - -nump = nump + 4 -numl = numl + 4 - -prn 0, 0, "three dimensional " -prn 0, -3, "text example" -prn 0, -6, "etc etc etc" - -END SUB - -SUB kuus (x, y, z, s) - -' Initialize variables -b = 0 -f = .3925 - -' Loop to create points of the octagon -FOR a = 0 + f TO 6 + f STEP 6.28 / 8 - x1 = SIN(a) * s - y1 = COS(a) * s - b = b + 1 - - ' Store the points in the shared arrays - xn(nump + b) = x1 + x - yn(nump + b) = y - zn(nump + b) = y1 + z -NEXT a - -' Define the lines connecting these points -point1(numl + 1) = nump + 1 -point2(numl + 1) = nump + 2 -col(numl + 1) = 12 - -point1(numl + 2) = nump + 2 -point2(numl + 2) = nump + 3 -col(numl + 2) = 12 - -point1(numl + 3) = nump + 3 -point2(numl + 3) = nump + 4 -col(numl + 3) = 12 - -point1(numl + 4) = nump + 4 -point2(numl + 4) = nump + 5 -col(numl + 4) = 12 - -point1(numl + 5) = nump + 5 -point2(numl + 5) = nump + 6 -col(numl + 5) = 12 - -point1(numl + 6) = nump + 6 -point2(numl + 6) = nump + 7 -col(numl + 6) = 12 - -point1(numl + 7) = nump + 7 -point2(numl + 7) = nump + 8 -col(numl + 7) = 12 - -point1(numl + 8) = nump + 8 -point2(numl + 8) = nump + 1 -col(numl + 8) = 12 - -nump = nump + b -numl = numl + 8 - -'LOCATE 1, 1 -'PRINT b - -END SUB - -SUB nait3d - -' Main loop for the 3D rendering -1 - -myx = myx + SIN(deg1) * mye -myz = myz + COS(deg1) * mye - -myx = myx + COS(deg1) * myk -myz = myz - SIN(deg1) * myk - -deg1 = deg1 + d1 -Deg2 = Deg2 + d2 - -C1 = COS(deg1): S1 = SIN(deg1) -C2 = COS(Deg2): S2 = SIN(Deg2) - -' Transform the coordinates -FOR a = 1 TO nump - xo = xn(a) - myx - yo = -yn(a) - myy - zo = zn(a) - myz - - x1 = (xo * C1 - zo * S1) - z1 = (xo * S1 + zo * C1) - - y1 = (yo * C2 - z1 * S2) - z2 = (yo * S2 + z1 * C2) - - ' Store the transformed coordinates - xo(a) = x(a) - yo(a) = y(a) - - ' Check if the point is within the view - IF z2 < 20 THEN - x(a) = -1 - ELSE - ' Apply perspective transformation - x(a) = 320 + (x1 / z2 * 500) - y(a) = 240 + (y1 / z2 * 500) - END IF -NEXT - -' Draw the lines -FOR a = 1 TO numl - p1 = point1(a) - p2 = point2(a) - - ' Check if the points are within the view - IF xo(p1) = -1 OR xo(p2) = -1 THEN - ' Do nothing - ELSE - ' erase line at old coordinates - LINE (xo(p1), yo(p1))-(xo(p2), yo(p2)), 0 - END IF - - IF x(p1) = -1 OR x(p2) = -1 THEN - ' Do nothing - ELSE - ' draw line at new coordinates - LINE (x(p1), y(p1))-(x(p2), y(p2)), col(a) - END IF -NEXT - -' Handle user input -K$ = INKEY$ -IF K$ <> "" THEN - - SELECT CASE K$ - - CASE CHR$(0) + "P" - mye = mye - 1 - - CASE CHR$(0) + "H" - mye = mye + 1 - - CASE CHR$(0) + "M" - myk = myk + 1 - - CASE CHR$(0) + "K" - myk = myk - 1 - - CASE "+" - myy = myy + 3 - - CASE "-" - myy = myy - 3 - - CASE "6" - d1 = d1 + .01 - - CASE "4" - d1 = d1 - .01 - - CASE "8" - d2 = d2 - .01 - - CASE "2" - d2 = d2 + .01 - - CASE " " - d1 = d1 / 2 - d2 = d2 / 2 - d3 = d3 / 2 - mye = mye / 2 - myk = myk / 2 - - CASE "q" - SYSTEM - - CASE CHR$(27) - SYSTEM - - END SELECT -END IF - -GOTO 1 - -END SUB - -SUB pch (x, y, a$) - -' Initialize variables -b = ASC(a$) -up = 0 -ul = 0 - -' Loop to create points for the character -FOR c = 0 TO 100 - IF tpx(c, b) = 999 THEN GOTO 4 - up = up + 1 - xn(nump + up) = x + tpx(c, b) - yn(nump + up) = y - tpy(c, b) - zn(nump + up) = 0 -NEXT c -4 - -' Loop to define the lines for the character -FOR c = 0 TO 100 - IF tl1(c, b) = 999 THEN GOTO 5 - ul = ul + 1 - point1(numl + ul) = tl1(c, b) + nump + 1 - point2(numl + ul) = tl2(c, b) + nump + 1 - col(numl + ul) = 4 -NEXT c -5 - -' Update the counters -nump = nump + up -numl = numl + ul - -END SUB - -SUB porand -' do floor of the 3D room - -' Loop to create floor tiles made of hexagons and squares -FOR x = -100 TO 0 STEP 12.067 + .3 - FOR z = -100 TO 0 STEP 12.067 + .3 - kuus x, -125, z, 6.53 - ruut x + 6.033 + .15, -125, z + 6.033 + .15, 3.111 + .3 - NEXT z -NEXT x - -' Loop to create squares -FOR y = -100 TO 0 STEP 20.3 - FOR x = -100 TO 0 STEP 20.3 - ruut2 x, y, 200, 10 - NEXT x -NEXT y - -END SUB - -SUB prn (x, y, a$) - -' Loop to print each character -FOR b = 1 TO LEN(a$) - c$ = RIGHT$(LEFT$(a$, b), 1) - pch x + b * 3, y, c$ -NEXT b - -END SUB - -SUB readfnt - -' Open the font file -OPEN "font.dat" FOR INPUT AS #1 - -' Loop to read the font data -3 -IF EOF(1) <> 0 THEN GOTO 2 -LINE INPUT #1, a$ - -IF LEFT$(a$, 1) = "#" THEN - chr = ASC(RIGHT$(LEFT$(a$, 3), 1)) - - ' Initialize counters - pp = 0 - lp = 0 -END IF - -' read the points for the character -IF LEFT$(a$, 1) = "p" THEN - tpx(pp, chr) = VAL(RIGHT$(LEFT$(a$, 3), 1)) - tpy(pp, chr) = VAL(RIGHT$(LEFT$(a$, 5), 1)) - pp = pp + 1 -END IF - -' read the lines for the character -IF LEFT$(a$, 1) = "l" THEN - tl1(lp, chr) = VAL(RIGHT$(LEFT$(a$, 3), 1)) - tl2(lp, chr) = VAL(RIGHT$(LEFT$(a$, 5), 1)) - lp = lp + 1 -END IF - -GOTO 3 - -' Close the font file -2 -CLOSE #1 - -END SUB - -SUB ruut (x, y, z, s) - -' Define the corners of the rectangle -xn(nump + 1) = x -yn(nump + 1) = y -zn(nump + 1) = z + s - -xn(nump + 2) = x + s -yn(nump + 2) = y -zn(nump + 2) = z - -xn(nump + 3) = x -yn(nump + 3) = y -zn(nump + 3) = z - s - -xn(nump + 4) = x - s -yn(nump + 4) = y -zn(nump + 4) = z - -' Define the lines connecting these corners -point1(numl + 1) = nump + 1 -point2(numl + 1) = nump + 2 -col(numl + 1) = 10 - -point1(numl + 2) = nump + 2 -point2(numl + 2) = nump + 3 -col(numl + 2) = 10 - -point1(numl + 3) = nump + 3 -point2(numl + 3) = nump + 4 -col(numl + 3) = 10 - -point1(numl + 4) = nump + 4 -point2(numl + 4) = nump + 1 -col(numl + 4) = 10 - -' Update the counters -nump = nump + 4 -numl = numl + 4 - -END SUB - -SUB ruut2 (x, y, z, s) - -' Define the corners of the rectangle -xn(nump + 1) = x - s -yn(nump + 1) = y - s -zn(nump + 1) = z - -xn(nump + 2) = x + s -yn(nump + 2) = y - s -zn(nump + 2) = z - -xn(nump + 3) = x + s -yn(nump + 3) = y + s -zn(nump + 3) = z - -xn(nump + 4) = x - s -yn(nump + 4) = y + s -zn(nump + 4) = z - -' Define the lines connecting these corners -point1(numl + 1) = nump + 1 -point2(numl + 1) = nump + 2 -col(numl + 1) = 14 - -point1(numl + 2) = nump + 2 -point2(numl + 2) = nump + 3 -col(numl + 2) = 14 - -point1(numl + 3) = nump + 3 -point2(numl + 3) = nump + 4 -col(numl + 3) = 14 - -point1(numl + 4) = nump + 4 -point2(numl + 4) = nump + 1 -col(numl + 4) = 14 - -' Update the counters -nump = nump + 4 -numl = numl + 4 - -END SUB - -SUB start - -' Initialize the screen and clear it -SCREEN 12 -CLS - -' Set the default color for all points -FOR a = 1 TO 4000 - col(a) = 15 -NEXT a - -' Initialize counters -nump = 0 -numl = 0 - -' Initialize font data -FOR a = 0 TO 255 - FOR b = 0 TO 10 - tpx(b, a) = 999 - tpy(b, a) = 999 - tl1(b, a) = 999 - tl2(b, a) = 999 - NEXT b -NEXT a - -' Read the font data -readfnt - -' Define the corners of the cubes -getcor - -END SUB diff --git a/Graphics/3D/tiled room.bas b/Graphics/3D/tiled room.bas new file mode 100755 index 0000000..45eeba2 --- /dev/null +++ b/Graphics/3D/tiled room.bas @@ -0,0 +1,501 @@ +' Program renders 3D room with various decorative tiles on the wall and on the floor. +' User can freely fly around and look at the room from different angles. +' +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' ?, Initial version +' 2024, Improved program readability using AI +' +' Keyboard controls: +' , , , - move around +' 2, 6, 4, 8 - look around (number pad) +' - speed down +' q - quit +' + / - - move up / down +' + + +DECLARE SUB renderSquare2 (x!, y!, z!, s!) +DECLARE SUB renderSquare (x%, y%, z%, s%) +DECLARE SUB renderHexagon (x!, y!, z!, s!) +DECLARE SUB generateCube () + +DECLARE SUB start () +DECLARE SUB addSquare (x1%, y1%, z1%) +DECLARE SUB getCornerVertices () +DECLARE SUB multiplyCoordinates () +DECLARE SUB calculateSine () +DIM SHARED xVertex(4000), yVertex(4000), zVertex(4000) +DIM SHARED xCoordinate(4000), yCoordinate(4000), zCoordinate(4000) + +DIM SHARED xOriginal(4000), yOriginal(4000), zOriginal(4000) +DIM SHARED point1Vertex(4000), point2Vertex(4000) +DIM SHARED col(4000) +DIM SHARED vertexCount, edgeCount +DIM SHARED myx, myy, myz, mye, myk + +myx = 0 +myy = 0 +myz = -1000 + +start + +nait3d + +SUB addSquare (x1%, y1%, z1%) + c = 1 + + ' Define the vertices of a square in 3D space + xVertex(vertexCount + 1) = -100 + x1 + yVertex(vertexCount + 1) = y1 + zVertex(vertexCount + 1) = -100 + z1 + + xVertex(vertexCount + 2) = 100 + x1 + yVertex(vertexCount + 2) = y1 + zVertex(vertexCount + 2) = -100 + z1 + + xVertex(vertexCount + 3) = 100 + x1 + yVertex(vertexCount + 3) = y1 + zVertex(vertexCount + 3) = 100 + z1 + + xVertex(vertexCount + 4) = -100 + x1 + yVertex(vertexCount + 4) = y1 + zVertex(vertexCount + 4) = 100 + z1 + + ' Define the edges of the square + point1Vertex(edgeCount + 1) = vertexCount + 1 + point2Vertex(edgeCount + 1) = vertexCount + 2 + col(edgeCount + 1) = c + + point1Vertex(edgeCount + 2) = vertexCount + 2 + point2Vertex(edgeCount + 2) = vertexCount + 3 + col(edgeCount + 2) = c + + point1Vertex(edgeCount + 3) = vertexCount + 3 + point2Vertex(edgeCount + 3) = vertexCount + 4 + col(edgeCount + 3) = c + + point1Vertex(edgeCount + 4) = vertexCount + 4 + point2Vertex(edgeCount + 4) = vertexCount + 1 + col(edgeCount + 4) = c + + ' Update the counters for the next square + vertexCount = vertexCount + 4 + edgeCount = edgeCount + 4 + +END SUB + +SUB getCornerVertices + + ' Define the vertices of a square in 3D space + xVertex(vertexCount + 1) = -150 + yVertex(vertexCount + 1) = -125 + zVertex(vertexCount + 1) = -200 + + xVertex(vertexCount + 2) = 150 + yVertex(vertexCount + 2) = -125 + zVertex(vertexCount + 2) = -200 + + xVertex(vertexCount + 3) = 150 + yVertex(vertexCount + 3) = 125 + zVertex(vertexCount + 3) = -200 + + xVertex(vertexCount + 4) = -150 + yVertex(vertexCount + 4) = 125 + zVertex(vertexCount + 4) = -200 + + ' Define the edges of the square + point1Vertex(edgeCount + 1) = vertexCount + 1 + point2Vertex(edgeCount + 1) = vertexCount + 2 + + point1Vertex(edgeCount + 2) = vertexCount + 2 + point2Vertex(edgeCount + 2) = vertexCount + 3 + + point1Vertex(edgeCount + 3) = vertexCount + 3 + point2Vertex(edgeCount + 3) = vertexCount + 4 + + point1Vertex(edgeCount + 4) = vertexCount + 4 + point2Vertex(edgeCount + 4) = vertexCount + 1 + + ' Define the vertices of another square in 3D space + xVertex(vertexCount + 5) = -150 + yVertex(vertexCount + 5) = -125 + zVertex(vertexCount + 5) = 200 + + xVertex(vertexCount + 6) = 150 + yVertex(vertexCount + 6) = -125 + zVertex(vertexCount + 6) = 200 + + xVertex(vertexCount + 7) = 150 + yVertex(vertexCount + 7) = 125 + zVertex(vertexCount + 7) = 200 + + xVertex(vertexCount + 8) = -150 + yVertex(vertexCount + 8) = 125 + zVertex(vertexCount + 8) = 200 + + ' Define the edges of the second square + point1Vertex(edgeCount + 5) = vertexCount + 5 + point2Vertex(edgeCount + 5) = vertexCount + 6 + + point1Vertex(edgeCount + 6) = vertexCount + 6 + point2Vertex(edgeCount + 6) = vertexCount + 7 + + point1Vertex(edgeCount + 7) = vertexCount + 7 + point2Vertex(edgeCount + 7) = vertexCount + 8 + + point1Vertex(edgeCount + 8) = vertexCount + 8 + point2Vertex(edgeCount + 8) = vertexCount + 5 + + ' Define the edges connecting the two squares into cube + point1Vertex(edgeCount + 9) = vertexCount + 5 + point2Vertex(edgeCount + 9) = vertexCount + 1 + + point1Vertex(edgeCount + 10) = vertexCount + 6 + point2Vertex(edgeCount + 10) = vertexCount + 2 + + point1Vertex(edgeCount + 11) = vertexCount + 7 + point2Vertex(edgeCount + 11) = vertexCount + 3 + + point1Vertex(edgeCount + 12) = vertexCount + 8 + point2Vertex(edgeCount + 12) = vertexCount + 4 + + ' Update the counters for the next set of vertices and edges + vertexCount = vertexCount + 8 + edgeCount = edgeCount + 12 + + ' Define a pyramid in 3D space + xVertex(vertexCount + 1) = -150 + yVertex(vertexCount + 1) = -125 + 201 + zVertex(vertexCount + 1) = 0 + + xVertex(vertexCount + 2) = -150 + yVertex(vertexCount + 2) = -125 + 201 + zVertex(vertexCount + 2) = 89 + + xVertex(vertexCount + 3) = -150 + yVertex(vertexCount + 3) = -125 + zVertex(vertexCount + 3) = 89 + + xVertex(vertexCount + 4) = -150 + yVertex(vertexCount + 4) = -125 + zVertex(vertexCount + 4) = 0 + + ' Define the edges of the pyramid + point1Vertex(edgeCount + 1) = vertexCount + 1 + point2Vertex(edgeCount + 1) = vertexCount + 2 + + point1Vertex(edgeCount + 2) = vertexCount + 2 + point2Vertex(edgeCount + 2) = vertexCount + 3 + + point1Vertex(edgeCount + 3) = vertexCount + 3 + point2Vertex(edgeCount + 3) = vertexCount + 4 + + point1Vertex(edgeCount + 4) = vertexCount + 4 + point2Vertex(edgeCount + 4) = vertexCount + 1 + + ' Update the counters for the next set of vertices and edges + vertexCount = vertexCount + 4 + edgeCount = edgeCount + 4 + +porand + +END SUB + +SUB renderHexagon (x, y, z, s) + +b = 0 +f = .3925 +' Calculate the vertices of a hexagon in 3D space +FOR a = 0 + f TO 6 + f STEP 6.28 / 8 + x1 = SIN(a) * s + y1 = COS(a) * s + b = b + 1 + + xVertex(vertexCount + b) = x + x1 + yVertex(vertexCount + b) = y + zVertex(vertexCount + b) = z + y1 + +NEXT a + +' Define the edges of the hexagon +point1Vertex(edgeCount + 1) = vertexCount + 1 +point2Vertex(edgeCount + 1) = vertexCount + 2 +col(edgeCount + 1) = 12 + +point1Vertex(edgeCount + 2) = vertexCount + 2 +point2Vertex(edgeCount + 2) = vertexCount + 3 +col(edgeCount + 2) = 12 + +point1Vertex(edgeCount + 3) = vertexCount + 3 +point2Vertex(edgeCount + 3) = vertexCount + 4 +col(edgeCount + 3) = 12 + +point1Vertex(edgeCount + 4) = vertexCount + 4 +point2Vertex(edgeCount + 4) = vertexCount + 5 +col(edgeCount + 4) = 12 + +point1Vertex(edgeCount + 5) = vertexCount + 5 +point2Vertex(edgeCount + 5) = vertexCount + 6 +col(edgeCount + 5) = 12 + +point1Vertex(edgeCount + 6) = vertexCount + 6 +point2Vertex(edgeCount + 6) = vertexCount + 7 +col(edgeCount + 6) = 12 + +point1Vertex(edgeCount + 7) = vertexCount + 7 +point2Vertex(edgeCount + 7) = vertexCount + 8 +col(edgeCount + 7) = 12 + +point1Vertex(edgeCount + 8) = vertexCount + 8 +point2Vertex(edgeCount + 8) = vertexCount + 1 +col(edgeCount + 8) = 12 + +' Update the counters for the next set of vertices and edges +vertexCount = vertexCount + b +edgeCount = edgeCount + 8 + +END SUB + +SUB nait3d + + ' Main loop to render the 3D scene +1 + + ' Update the position based on rotation + myx = myx + SIN(deg1) * mye + myz = myz + COS(deg1) * mye + + myx = myx + COS(deg1) * myk + myz = myz - SIN(deg1) * myk + + ' Update the rotation angles + deg1 = deg1 + d1 + Deg2 = Deg2 + d2 + + ' Calculate the rotation matrices + C1 = COS(deg1): S1 = SIN(deg1) + C2 = COS(Deg2): S2 = SIN(Deg2) + + ' Apply the rotation to each vertex + FOR a = 1 TO vertexCount + xo = xVertex(a) - myx + yo = -yVertex(a) - myy + zo = zVertex(a) - myz + + x1 = (xo * C1 - zo * S1) + z1 = (xo * S1 + zo * C1) + + y1 = (yo * C2 - z1 * S2) + z2 = (yo * S2 + z1 * C2) + + ' Project the vertex onto the 2D screen + xOriginal(a) = xCoordinate(a) + yOriginal(a) = yCoordinate(a) + IF z2 < 20 THEN + xCoordinate(a) = -1 + ELSE + xCoordinate(a) = 320 + (x1 / z2 * 500) + yCoordinate(a) = 240 + (y1 / z2 * 500) + END IF + NEXT + + ' Draw the edges of each shape + FOR a = 1 TO edgeCount + p1 = point1Vertex(a) + p2 = point2Vertex(a) + IF xOriginal(p1) = -1 OR xOriginal(p2) = -1 THEN + ' Skip drawing if the vertex is off-screen + ELSE + ' erase edge on old coordinates + LINE (xOriginal(p1), yOriginal(p1))-(xOriginal(p2), yOriginal(p2)), 0 + END IF + + IF xCoordinate(p1) = -1 OR xCoordinate(p2) = -1 THEN + ' Skip drawing if the vertex is off-screen + ELSE + ' draw edge on new coordinates + LINE (xCoordinate(p1), yCoordinate(p1))-(xCoordinate(p2), yCoordinate(p2)), col(a) + END IF + NEXT + + ' Handle user input + K$ = INKEY$ + IF K$ <> "" THEN + + SELECT CASE K$ + + CASE CHR$(0) + "P" + mye = mye - 3 + + CASE CHR$(0) + "H" + mye = mye + 3 + + CASE CHR$(0) + "M" + myk = myk + 3 + + CASE CHR$(0) + "K" + myk = myk - 3 + + CASE "+" + myy = myy + 3 + + CASE "-" + myy = myy - 3 + + CASE "6" + d1 = d1 + .01 + + CASE "4" + d1 = d1 - .01 + + CASE "8" + d2 = d2 - .01 + + CASE "2" + d2 = d2 + .01 + + CASE " " + d1 = d1 / 2 + d2 = d2 / 2 + d3 = d3 / 2 + mye = mye / 2 + myk = myk / 2 + + CASE "q" + SYSTEM + + CASE CHR$(27) + SYSTEM + END SELECT + END IF + + ' Continue the main loop + GOTO 1 +END SUB + +SUB porand + + ' Generate a grid of shapes in 3D space + FOR x = -100 TO 0 STEP 12.067 + .3 + FOR z = -100 TO 0 STEP 12.067 + .3 + renderHexagon x, -125, z, 6.53 + renderSquare x + 6.033 + .15, -125, z + 6.033 + .15, 3.111 + .3 + NEXT z + NEXT x + + ' Generate another grid of shapes in 3D space + FOR y = -100 TO 0 STEP 20.3 + FOR x = -100 TO 0 STEP 20.3 + renderSquare2 x, y, 200, 10 + NEXT x + NEXT y + +END SUB + +SUB renderSquare (x%, y%, z%, s%) + + ' Define the vertices of a square in 3D space + xVertex(vertexCount + 1) = x% + yVertex(vertexCount + 1) = y% + zVertex(vertexCount + 1) = z% + s% + + xVertex(vertexCount + 2) = x% + s% + yVertex(vertexCount + 2) = y% + zVertex(vertexCount + 2) = z% + + xVertex(vertexCount + 3) = x% + yVertex(vertexCount + 3) = y% + zVertex(vertexCount + 3) = z% - s% + + xVertex(vertexCount + 4) = x% - s% + yVertex(vertexCount + 4) = y% + zVertex(vertexCount + 4) = z% + + ' Define the edges of the square + point1Vertex(edgeCount + 1) = vertexCount + 1 + point2Vertex(edgeCount + 1) = vertexCount + 2 + col(edgeCount + 1) = 10 + + point1Vertex(edgeCount + 2) = vertexCount + 2 + point2Vertex(edgeCount + 2) = vertexCount + 3 + col(edgeCount + 2) = 10 + + point1Vertex(edgeCount + 3) = vertexCount + 3 + point2Vertex(edgeCount + 3) = vertexCount + 4 + col(edgeCount + 3) = 10 + + point1Vertex(edgeCount + 4) = vertexCount + 4 + point2Vertex(edgeCount + 4) = vertexCount + 1 + col(edgeCount + 4) = 10 + + ' Update the counters for the next square + vertexCount = vertexCount + 4 + edgeCount = edgeCount + 4 + +END SUB + +SUB renderSquare2 (x, y, z, s) + + ' Define the vertices of a square in 3D space + xVertex(vertexCount + 1) = x - s + yVertex(vertexCount + 1) = y - s + zVertex(vertexCount + 1) = z + + xVertex(vertexCount + 2) = x + s + yVertex(vertexCount + 2) = y - s + zVertex(vertexCount + 2) = z + + xVertex(vertexCount + 3) = x + s + yVertex(vertexCount + 3) = y + s + zVertex(vertexCount + 3) = z + + xVertex(vertexCount + 4) = x - s + yVertex(vertexCount + 4) = y + s + zVertex(vertexCount + 4) = z + + ' Define the edges of the square + point1Vertex(edgeCount + 1) = vertexCount + 1 + point2Vertex(edgeCount + 1) = vertexCount + 2 + col(edgeCount + 1) = 14 + + point1Vertex(edgeCount + 2) = vertexCount + 2 + point2Vertex(edgeCount + 2) = vertexCount + 3 + col(edgeCount + 2) = 14 + + point1Vertex(edgeCount + 3) = vertexCount + 3 + point2Vertex(edgeCount + 3) = vertexCount + 4 + col(edgeCount + 3) = 14 + + point1Vertex(edgeCount + 4) = vertexCount + 4 + point2Vertex(edgeCount + 4) = vertexCount + 1 + col(edgeCount + 4) = 14 + + ' Update the counters for the next square + vertexCount = vertexCount + 4 + edgeCount = edgeCount + 4 + +END SUB + +SUB start + + ' Initialize the screen and clear it + SCREEN 12 + CLS + + ' Set the initial color of all shapes + FOR a = 1 TO 4000 + col(a) = 15 + NEXT a + + ' Initialize counters for vertices and edges + vertexCount = 0 + edgeCount = 0 + + ' Generate the initial set of shapes + getCornerVertices + +END SUB