From: Svjatoslav Agejenko Date: Thu, 28 Nov 2024 22:10:13 +0000 (+0200) Subject: Added screencasts for 3D graphics applications X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=161a6d4d1fff996bcf5301b52536bca1560d4a32;p=qbasicapps.git Added screencasts for 3D graphics applications --- diff --git a/Graphics/3D/!.webm b/Graphics/3D/!.webm new file mode 100644 index 0000000..1786991 Binary files /dev/null and b/Graphics/3D/!.webm differ diff --git a/Graphics/3D/3D ball.bas b/Graphics/3D/3D ball.bas new file mode 100755 index 0000000..714c7f0 --- /dev/null +++ b/Graphics/3D/3D ball.bas @@ -0,0 +1,181 @@ +' 3D animation of point-cloud ball bouncing around the screen +' +' by Svjatoslav Agejenko +' homepage: svjatoslav.eu +' email: svjatoslav@svjatoslav.eu +' +' 1999, Initial version. +' 2024.07, Used AI to enhance program readability. + +DECLARE SUB InitializeScene () +DECLARE SUB UpdateOrientation () +DECLARE SUB DisplayPoints (angle1 AS SINGLE, angle2 AS SINGLE, angle3 AS SINGLE) +RANDOMIZE TIMER +SCREEN 12 + +' Shared arrays to hold the positions of points in 3D space +DIM SHARED pointX(1 TO 1000) AS SINGLE +DIM SHARED pointY(1 TO 1000) AS SINGLE +DIM SHARED pointZ(1 TO 1000) AS SINGLE + +' Shared arrays to hold the previous on-screen positions of points +DIM SHARED prevX(1 TO 1000) AS INTEGER +DIM SHARED prevY(1 TO 1000) AS INTEGER + +' Shared variables for simulation control +DIM SHARED totalPoints AS INTEGER +DIM SHARED ballX +DIM SHARED ballY +DIM SHARED ballVelocityX +DIM SHARED ballVelocityY + +' Shared variables for rotation angles and their velocities +DIM SHARED rotationAngle1 +DIM SHARED rotationAngle2 +DIM SHARED rotationAngle3 +DIM SHARED angularVelocity1 +DIM SHARED angularVelocity2 +DIM SHARED angularVelocity3 + +' Initialize the total number of points to be displayed +totalPoints = 500 + +CALL InitializeScene + +' Initialization of rotation angles and ball position +rotationAngle1 = 0 +rotationAngle2 = 0 +rotationAngle3 = 0 + +' Main loop +DO + CALL DisplayPoints(rotationAngle1, rotationAngle2, rotationAngle3) + + ' Update the rotation angles based on their velocities + rotationAngle1 = rotationAngle1 + angularVelocity1 + rotationAngle2 = rotationAngle2 + angularVelocity2 + rotationAngle3 = rotationAngle3 + angularVelocity3 + + ' Add force of gravity + ballVelocityY = ballVelocityY + .1 + + ' Update the ball's position and velocity + ballY = ballY + ballVelocityY + ballX = ballX + ballVelocityX + + ' Check for ball bounce conditions + IF ballY > 160 THEN + ballVelocityY = -ballVelocityY + ballVelocityX = ballVelocityX + (RND * 2 - 1) + CALL UpdateOrientation + END IF + + IF ballX < -200 OR ballX > 200 THEN + ballVelocityX = -ballVelocityX + CALL UpdateOrientation + END IF + + ' Check for user input to exit the program + a$ = INKEY$ + IF a$ <> "" THEN + CLS + SYSTEM + END IF +LOOP + +' Subroutine to display the points on the screen +SUB DisplayPoints (angle1 AS SINGLE, angle2 AS SINGLE, angle3 AS SINGLE) + + ' Calculate the sine and cosine for rotation angles + s1 = SIN(angle1) + c1 = COS(angle1) + s2 = SIN(angle2) + c2 = COS(angle2) + s3 = SIN(angle3) + c3 = COS(angle3) + + ' For each point, apply rotation transformations and project to 2D + FOR a = 1 TO totalPoints + x = pointX(a) + y = pointY(a) + z = pointZ(a) + + x1 = x * s1 + y * c1 + y1 = x * c1 - y * s1 + + z1 = z * s2 + y1 * c2 + y2 = z * c2 - y1 * s2 + + z2 = z1 * s3 + x1 * c3 + x2 = z1 * c3 - x1 * s3 + + ' Perspective projection + z2 = z2 + 200 + + ' Convert to screen coordinates and apply ball offset + xScreen = x2 / z2 * 320 + 320 + ballX + yScreen = y2 / z2 * 300 + 240 + ballY + + ' Erase the previous point position and draw the new one + PSET (prevX(a), prevY(a)), 0 + PSET (xScreen, yScreen), 3 + + ' Update the previous on-screen positions + prevX(a) = xScreen + prevY(a) = yScreen + NEXT a +END SUB + +' Subroutine to initialize the 3D points and ball properties +SUB InitializeScene + PRINT "Calculating coordinates" + PRINT "Please wait....." + + ' Generate random 3D coordinates for each point + FOR a = 1 TO totalPoints + ang1 = RND * 100 + ang2 = RND * 100 + ang3 = RND * 100 + + s1 = SIN(ang1) + c1 = COS(ang1) + s2 = SIN(ang2) + c2 = COS(ang2) + s3 = SIN(ang3) + c3 = COS(ang3) + + ' Apply rotation transformations to the point + x = 50 + y = 0 + z = 0 + + x1 = x * s1 + y * c1 + y1 = x * c1 - y * s1 + + z1 = z * s2 + y1 * c2 + y2 = z * c2 - y1 * s2 + + z2 = z1 * s3 + x1 * c3 + x2 = z1 * c3 - x1 * s3 + + pointX(a) = x2 + pointY(a) = y2 + pointZ(a) = z2 + NEXT a + + ' Set the initial ball velocity + ballVelocityX = 2 + RND + ballY = -100 + + CALL UpdateOrientation + + CLS +END SUB + +' Subroutine to update the angular velocities for rotation +SUB UpdateOrientation + angularVelocity1 = (RND - .5) / 16 + angularVelocity2 = (RND - .5) / 16 + angularVelocity3 = (RND - .5) / 16 +END SUB + diff --git a/Graphics/3D/3D ball.webm b/Graphics/3D/3D ball.webm new file mode 100644 index 0000000..cd04bfc Binary files /dev/null and b/Graphics/3D/3D ball.webm differ diff --git a/Graphics/3D/3D land.bas b/Graphics/3D/3D land.bas new file mode 100755 index 0000000..5d6e4d2 --- /dev/null +++ b/Graphics/3D/3D land.bas @@ -0,0 +1,114 @@ +DECLARE SUB DrawBox (x1%, y1%, x2%, y2%, x3%, y3%, x4%, y4%, c1%) + +' Program to render 3D shaded landscape with perspective and distortion effects. +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 1999, Initial version +' 2024.08, Improved program readability using AI + +DECLARE SUB SetPalette () +DEFINT A-Z + +' Declare shared arrays for X and Y coordinates +DIM SHARED xCoordinates(1 TO 40, 1 TO 40) +DIM SHARED yCoordinates(1 TO 40, 1 TO 40) + +' Set screen mode to 12 +SCREEN 12 + +' Initialize color palette +SetPalette + +' Set initial scaling factor +scalingFactor = 1.5 + +' Main loop start +1 : +' Loop through each point in the grid +FOR rowIndex = 1 TO 40 + FOR colIndex = 1 TO 40 + ' Calculate the position with distortion + xPosition = 120 + (colIndex * 10) + yPosition = 200 + (rowIndex * 3) + + ' Apply a cosine distortion based on distance from center + yPosition = yPosition - COS(SQR((colIndex - 20) ^ 2 + (rowIndex - 20) ^ 2) / scalingFactor) * 20 + + ' Apply perspective transformation + xPosition = (xPosition - 320) * (rowIndex + 50) / 50 + 320 + yPosition = (yPosition - 240) * (rowIndex + 50) / 50 + 240 + + ' Store the transformed coordinates + xCoordinates(colIndex, rowIndex) = xPosition + yCoordinates(colIndex, rowIndex) = yPosition + NEXT colIndex +NEXT rowIndex + +' Draw boxes based on the stored coordinates +FOR rowIndex = 1 TO 39 + FOR colIndex = 1 TO 39 + ' Alternate colors for each box + IF (colIndex + rowIndex) \ 2 <> (colIndex + rowIndex + 1) \ 2 THEN colorIndex = 0 ELSE colorIndex = 5 + ' Calculate a brightness factor + brightnessFactor = rowIndex + (colIndex / 3) + + ' Draw the box with the calculated color and brightness + DrawBox xCoordinates(colIndex, rowIndex), yCoordinates(colIndex, rowIndex), xCoordinates(colIndex + 1, rowIndex), yCoordinates(colIndex + 1, rowIndex), xCoordinates(colIndex, rowIndex + 1), yCoordinates(colIndex, rowIndex + 1), xCoordinates( _ +colIndex + 1, rowIndex + 1), yCoordinates(colIndex + 1, rowIndex + 1), colorIndex + NEXT colIndex +NEXT rowIndex + +' Wait for user input and adjust the scaling factor +userInput$ = INPUT$(1) +scalingFactor = scalingFactor * 1.9 + +' Clear the screen for the next iteration +CLS + +' If the scaling factor is too large, exit the program +IF scalingFactor > 10 THEN SYSTEM + +' Jump back to the main loop start +GOTO 1 + +' Subroutine to draw a filled box using line drawing +SUB DrawBox (x1, y1, x2, y2, x3, y3, x4, y4, c1) + ' Adjust color index based on position and brightness factor + c1 = c1 + (y2 - y1) / 3.5 + (brightnessFactor / 8) + 4 + + ' Ensure the color index is within valid range + IF c1 < 0 THEN c1 = 0 + IF c1 > 15 THEN c1 = 15 + + ' Calculate the length of the longer side + a = SQR((x1 - x2) ^ 2 + (y1 - y2) ^ 2) + b = SQR((x3 - x4) ^ 2 + (y3 - y4) ^ 2) + IF b < a THEN b = a + + ' Draw the box using lines + FOR lineIndex = 1 TO b + x5 = (x2 - x1) * lineIndex / b + x1 + y5 = (y2 - y1) * lineIndex / b + y1 + x6 = (x4 - x3) * lineIndex / b + x3 + y6 = (y4 - y3) * lineIndex / b + y3 + + ' Draw two adjacent lines to create a filled effect + LINE (x5, y5)-(x6, y6), c1 + LINE (x5 + 1, y5)-(x6 + 1, y6), c1 + NEXT lineIndex +END SUB + +' Subroutine to initialize color palette +SUB SetPalette + FOR paletteIndex = 1 TO 16 + ' Set the color values for each palette entry + OUT &H3C8, paletteIndex + OUT &H3C9, paletteIndex * 4 + OUT &H3C9, paletteIndex * 4 + OUT &H3C9, paletteIndex * 3 + NEXT paletteIndex +END SUB + diff --git a/Graphics/3D/3D land.webm b/Graphics/3D/3D land.webm new file mode 100644 index 0000000..1e60d2d Binary files /dev/null and b/Graphics/3D/3D land.webm differ diff --git a/Graphics/3D/3D text.webm b/Graphics/3D/3D text.webm new file mode 100644 index 0000000..0846d14 Binary files /dev/null and b/Graphics/3D/3D text.webm differ diff --git a/Graphics/3D/3dball.bas b/Graphics/3D/3dball.bas deleted file mode 100755 index 714c7f0..0000000 --- a/Graphics/3D/3dball.bas +++ /dev/null @@ -1,181 +0,0 @@ -' 3D animation of point-cloud ball bouncing around the screen -' -' by Svjatoslav Agejenko -' homepage: svjatoslav.eu -' email: svjatoslav@svjatoslav.eu -' -' 1999, Initial version. -' 2024.07, Used AI to enhance program readability. - -DECLARE SUB InitializeScene () -DECLARE SUB UpdateOrientation () -DECLARE SUB DisplayPoints (angle1 AS SINGLE, angle2 AS SINGLE, angle3 AS SINGLE) -RANDOMIZE TIMER -SCREEN 12 - -' Shared arrays to hold the positions of points in 3D space -DIM SHARED pointX(1 TO 1000) AS SINGLE -DIM SHARED pointY(1 TO 1000) AS SINGLE -DIM SHARED pointZ(1 TO 1000) AS SINGLE - -' Shared arrays to hold the previous on-screen positions of points -DIM SHARED prevX(1 TO 1000) AS INTEGER -DIM SHARED prevY(1 TO 1000) AS INTEGER - -' Shared variables for simulation control -DIM SHARED totalPoints AS INTEGER -DIM SHARED ballX -DIM SHARED ballY -DIM SHARED ballVelocityX -DIM SHARED ballVelocityY - -' Shared variables for rotation angles and their velocities -DIM SHARED rotationAngle1 -DIM SHARED rotationAngle2 -DIM SHARED rotationAngle3 -DIM SHARED angularVelocity1 -DIM SHARED angularVelocity2 -DIM SHARED angularVelocity3 - -' Initialize the total number of points to be displayed -totalPoints = 500 - -CALL InitializeScene - -' Initialization of rotation angles and ball position -rotationAngle1 = 0 -rotationAngle2 = 0 -rotationAngle3 = 0 - -' Main loop -DO - CALL DisplayPoints(rotationAngle1, rotationAngle2, rotationAngle3) - - ' Update the rotation angles based on their velocities - rotationAngle1 = rotationAngle1 + angularVelocity1 - rotationAngle2 = rotationAngle2 + angularVelocity2 - rotationAngle3 = rotationAngle3 + angularVelocity3 - - ' Add force of gravity - ballVelocityY = ballVelocityY + .1 - - ' Update the ball's position and velocity - ballY = ballY + ballVelocityY - ballX = ballX + ballVelocityX - - ' Check for ball bounce conditions - IF ballY > 160 THEN - ballVelocityY = -ballVelocityY - ballVelocityX = ballVelocityX + (RND * 2 - 1) - CALL UpdateOrientation - END IF - - IF ballX < -200 OR ballX > 200 THEN - ballVelocityX = -ballVelocityX - CALL UpdateOrientation - END IF - - ' Check for user input to exit the program - a$ = INKEY$ - IF a$ <> "" THEN - CLS - SYSTEM - END IF -LOOP - -' Subroutine to display the points on the screen -SUB DisplayPoints (angle1 AS SINGLE, angle2 AS SINGLE, angle3 AS SINGLE) - - ' Calculate the sine and cosine for rotation angles - s1 = SIN(angle1) - c1 = COS(angle1) - s2 = SIN(angle2) - c2 = COS(angle2) - s3 = SIN(angle3) - c3 = COS(angle3) - - ' For each point, apply rotation transformations and project to 2D - FOR a = 1 TO totalPoints - x = pointX(a) - y = pointY(a) - z = pointZ(a) - - x1 = x * s1 + y * c1 - y1 = x * c1 - y * s1 - - z1 = z * s2 + y1 * c2 - y2 = z * c2 - y1 * s2 - - z2 = z1 * s3 + x1 * c3 - x2 = z1 * c3 - x1 * s3 - - ' Perspective projection - z2 = z2 + 200 - - ' Convert to screen coordinates and apply ball offset - xScreen = x2 / z2 * 320 + 320 + ballX - yScreen = y2 / z2 * 300 + 240 + ballY - - ' Erase the previous point position and draw the new one - PSET (prevX(a), prevY(a)), 0 - PSET (xScreen, yScreen), 3 - - ' Update the previous on-screen positions - prevX(a) = xScreen - prevY(a) = yScreen - NEXT a -END SUB - -' Subroutine to initialize the 3D points and ball properties -SUB InitializeScene - PRINT "Calculating coordinates" - PRINT "Please wait....." - - ' Generate random 3D coordinates for each point - FOR a = 1 TO totalPoints - ang1 = RND * 100 - ang2 = RND * 100 - ang3 = RND * 100 - - s1 = SIN(ang1) - c1 = COS(ang1) - s2 = SIN(ang2) - c2 = COS(ang2) - s3 = SIN(ang3) - c3 = COS(ang3) - - ' Apply rotation transformations to the point - x = 50 - y = 0 - z = 0 - - x1 = x * s1 + y * c1 - y1 = x * c1 - y * s1 - - z1 = z * s2 + y1 * c2 - y2 = z * c2 - y1 * s2 - - z2 = z1 * s3 + x1 * c3 - x2 = z1 * c3 - x1 * s3 - - pointX(a) = x2 - pointY(a) = y2 - pointZ(a) = z2 - NEXT a - - ' Set the initial ball velocity - ballVelocityX = 2 + RND - ballY = -100 - - CALL UpdateOrientation - - CLS -END SUB - -' Subroutine to update the angular velocities for rotation -SUB UpdateOrientation - angularVelocity1 = (RND - .5) / 16 - angularVelocity2 = (RND - .5) / 16 - angularVelocity3 = (RND - .5) / 16 -END SUB - diff --git a/Graphics/3D/3dland.bas b/Graphics/3D/3dland.bas deleted file mode 100755 index 5d6e4d2..0000000 --- a/Graphics/3D/3dland.bas +++ /dev/null @@ -1,114 +0,0 @@ -DECLARE SUB DrawBox (x1%, y1%, x2%, y2%, x3%, y3%, x4%, y4%, c1%) - -' Program to render 3D shaded landscape with perspective and distortion effects. -' By Svjatoslav Agejenko. -' Email: svjatoslav@svjatoslav.eu -' Homepage: http://www.svjatoslav.eu -' -' Changelog: -' 1999, Initial version -' 2024.08, Improved program readability using AI - -DECLARE SUB SetPalette () -DEFINT A-Z - -' Declare shared arrays for X and Y coordinates -DIM SHARED xCoordinates(1 TO 40, 1 TO 40) -DIM SHARED yCoordinates(1 TO 40, 1 TO 40) - -' Set screen mode to 12 -SCREEN 12 - -' Initialize color palette -SetPalette - -' Set initial scaling factor -scalingFactor = 1.5 - -' Main loop start -1 : -' Loop through each point in the grid -FOR rowIndex = 1 TO 40 - FOR colIndex = 1 TO 40 - ' Calculate the position with distortion - xPosition = 120 + (colIndex * 10) - yPosition = 200 + (rowIndex * 3) - - ' Apply a cosine distortion based on distance from center - yPosition = yPosition - COS(SQR((colIndex - 20) ^ 2 + (rowIndex - 20) ^ 2) / scalingFactor) * 20 - - ' Apply perspective transformation - xPosition = (xPosition - 320) * (rowIndex + 50) / 50 + 320 - yPosition = (yPosition - 240) * (rowIndex + 50) / 50 + 240 - - ' Store the transformed coordinates - xCoordinates(colIndex, rowIndex) = xPosition - yCoordinates(colIndex, rowIndex) = yPosition - NEXT colIndex -NEXT rowIndex - -' Draw boxes based on the stored coordinates -FOR rowIndex = 1 TO 39 - FOR colIndex = 1 TO 39 - ' Alternate colors for each box - IF (colIndex + rowIndex) \ 2 <> (colIndex + rowIndex + 1) \ 2 THEN colorIndex = 0 ELSE colorIndex = 5 - ' Calculate a brightness factor - brightnessFactor = rowIndex + (colIndex / 3) - - ' Draw the box with the calculated color and brightness - DrawBox xCoordinates(colIndex, rowIndex), yCoordinates(colIndex, rowIndex), xCoordinates(colIndex + 1, rowIndex), yCoordinates(colIndex + 1, rowIndex), xCoordinates(colIndex, rowIndex + 1), yCoordinates(colIndex, rowIndex + 1), xCoordinates( _ -colIndex + 1, rowIndex + 1), yCoordinates(colIndex + 1, rowIndex + 1), colorIndex - NEXT colIndex -NEXT rowIndex - -' Wait for user input and adjust the scaling factor -userInput$ = INPUT$(1) -scalingFactor = scalingFactor * 1.9 - -' Clear the screen for the next iteration -CLS - -' If the scaling factor is too large, exit the program -IF scalingFactor > 10 THEN SYSTEM - -' Jump back to the main loop start -GOTO 1 - -' Subroutine to draw a filled box using line drawing -SUB DrawBox (x1, y1, x2, y2, x3, y3, x4, y4, c1) - ' Adjust color index based on position and brightness factor - c1 = c1 + (y2 - y1) / 3.5 + (brightnessFactor / 8) + 4 - - ' Ensure the color index is within valid range - IF c1 < 0 THEN c1 = 0 - IF c1 > 15 THEN c1 = 15 - - ' Calculate the length of the longer side - a = SQR((x1 - x2) ^ 2 + (y1 - y2) ^ 2) - b = SQR((x3 - x4) ^ 2 + (y3 - y4) ^ 2) - IF b < a THEN b = a - - ' Draw the box using lines - FOR lineIndex = 1 TO b - x5 = (x2 - x1) * lineIndex / b + x1 - y5 = (y2 - y1) * lineIndex / b + y1 - x6 = (x4 - x3) * lineIndex / b + x3 - y6 = (y4 - y3) * lineIndex / b + y3 - - ' Draw two adjacent lines to create a filled effect - LINE (x5, y5)-(x6, y6), c1 - LINE (x5 + 1, y5)-(x6 + 1, y6), c1 - NEXT lineIndex -END SUB - -' Subroutine to initialize color palette -SUB SetPalette - FOR paletteIndex = 1 TO 16 - ' Set the color values for each palette entry - OUT &H3C8, paletteIndex - OUT &H3C9, paletteIndex * 4 - OUT &H3C9, paletteIndex * 4 - OUT &H3C9, paletteIndex * 3 - NEXT paletteIndex -END SUB -