From: Svjatoslav Agejenko Date: Wed, 30 Jul 2025 05:52:09 +0000 (+0300) Subject: Better documentation for 4D engine, Alarms and mouse driver. X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=29f2254bad2c0495e8906d7affafabd3d9b227e6;p=qbasicapps.git Better documentation for 4D engine, Alarms and mouse driver. --- diff --git a/2D GFX/Fractals/index.html b/2D GFX/Fractals/index.html index 8b2fd16..f435ae9 100644 --- a/2D GFX/Fractals/index.html +++ b/2D GFX/Fractals/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Fractals @@ -210,11 +210,11 @@

Table of Contents

@@ -236,8 +236,8 @@ -
-

1. Fractal circles

+
+

1. Fractal circles

This QBasic program generates a visually captivating spiral fractal @@ -247,7 +247,7 @@ geometry, recursive programming, and graphical design.

-
+

fractal%20circles.png

@@ -266,8 +266,8 @@ indefinitely.
-
-

2. Fractal circles animated

+
+

2. Fractal circles animated

This QBasic program creates an animated fractal composed of circles, @@ -287,29 +287,29 @@ system to control the animation's progression.

-
-

3. Fractal of squares

+
+

3. Fractal of squares

This QBasic program generates and displays a fractal pattern composed of squares.

-
+

fractal%20squares,%201.png

-
+

fractal%20squares,%202.png

-
-

4. Fractal of squares animated

+
+

4. Fractal of squares animated

This QBasic program generates an animated fractal pattern composed of @@ -331,8 +331,8 @@ resulting in a dynamic and ever-changing geometric pattern.

-
-

5. Fractal of trees

+
+

5. Fractal of trees

QBasic program that generates a visually appealing fractal tree @@ -355,7 +355,7 @@ resembles a tree, with branches that grow and change over time.

-

Created: 2025-07-29 ti 17:31

+

Created: 2025-07-30 ke 01:26

Validate

diff --git a/2D GFX/Spirals/index.html b/2D GFX/Spirals/index.html index 5c2726b..1fe8864 100644 --- a/2D GFX/Spirals/index.html +++ b/2D GFX/Spirals/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Spiral series @@ -210,12 +210,12 @@

Table of Contents

@@ -236,11 +236,11 @@ } -
-

1. Spiral with increasing density

+
+

1. Spiral with increasing density

-
+

spiral.png

@@ -320,11 +320,11 @@ userInput$ = INPUT$(1)
-
-

2. Spiral with varying height

+
+

2. Spiral with varying height

-
+

spiral, 2.png

@@ -391,11 +391,11 @@ a$ = INPUT$(1)
-
-

3. Shaded spiral

+
+

3. Shaded spiral

-
+

spiral, 3.png

@@ -497,8 +497,8 @@ a$ = INPUT$(1)
-
-

4. Sphere forming spiral

+
+

4. Sphere forming spiral

Similar to previous spiral, Line segments are connected between the @@ -507,7 +507,7 @@ multiple linked spherical shapes. Initially point cloud in shown:

-
+

spiral, 4, 1.png

@@ -517,7 +517,7 @@ In the next step, points are connected using lines:

-
+

spiral, 4, 2.png

@@ -622,11 +622,11 @@ a$ = INPUT$(1)
-
-

5. Textured spherical spiral

+
+

5. Textured spherical spiral

-
+

spiral, 5.png

@@ -749,11 +749,11 @@ a$ = INPUT$(1)
-
-

6. Textured and shaded spherical spiral

+
+

6. Textured and shaded spherical spiral

-
+

spiral, 6.png

@@ -937,7 +937,7 @@ yStep2 = (oppositePointY2 - oppositePointY1) / stepCount
-

Created: 2025-07-29 ti 17:31

+

Created: 2025-07-30 ke 01:26

Validate

diff --git a/2D GFX/Textures/index.html b/2D GFX/Textures/index.html index fff135e..5673da2 100644 --- a/2D GFX/Textures/index.html +++ b/2D GFX/Textures/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Algorithmic textures @@ -210,11 +210,11 @@

Table of Contents

@@ -233,8 +233,8 @@ } -
-

1. Circular waves

+
+

1. Circular waves

This QBasic program creates visually captivating circular wave @@ -313,8 +313,8 @@ algorithms can produce intricate and visually appealing results.

-
-

2. Diamond square clouds

+
+

2. Diamond square clouds

This QBasic program demonstrates the Diamond-Square algorithm, a @@ -429,8 +429,8 @@ WAITa$ = INPUT$(1)

-
-

3. Old paper

+
+

3. Old paper

This QBasic program generates a procedural texture that simulates the @@ -527,8 +527,8 @@ inputKey$ = INPUT$(1)

-
-

4. Wood

+
+

4. Wood

This QBasic program creates a visually appealing simulation of a wood @@ -622,8 +622,8 @@ exitKey$ = INPUT$(1)

-
-

5. Yellow flame

+
+

5. Yellow flame

"Yellow Flame" is a visually captivating program written in QBasic @@ -702,7 +702,7 @@ userInput$ = INPUT$(1)

-

Created: 2025-07-29 ti 17:31

+

Created: 2025-07-30 ke 01:27

Validate

diff --git a/3D GFX/3D Synthezier/doc/index.html b/3D GFX/3D Synthezier/doc/index.html index c1b6b97..3c57508 100644 --- a/3D GFX/3D Synthezier/doc/index.html +++ b/3D GFX/3D Synthezier/doc/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + 3D Synthezier @@ -1103,39 +1103,39 @@ hsAddReviewPanels();

Table of Contents

@@ -1157,8 +1157,8 @@ hsAddReviewPanels(); -
-

1. Operating principle

+
+

1. Operating principle

Parses scene definition language and creates 3D world based on @@ -1221,60 +1221,60 @@ They were produced by importing generated -

1.1. Rectangular city

+
+

1.1. Rectangular city

-
+

rectangular city, 1.jpeg

-
+

rectangular city, 2.jpeg

-
+

rectangular city, 3.jpeg

-
-

1.2. Hexagonal city

+
+

1.2. Hexagonal city

-
+

hexagonal city, 1.jpeg

-
+

hexagonal city, 2.jpeg

-
+

hexagonal city, 3.jpeg

-
-

2. Scene description language

+
+

2. Scene description language

See also examples.

-
-

2.1. here

+
+

2.1. here

 here
@@ -1285,8 +1285,8 @@ defines new segment
 

-
-

2.2. p

+
+

2.2. p

 p  x y z
@@ -1297,8 +1297,8 @@ defines new point
 

-
-

2.3. f

+
+

2.3. f

 f  p1 p2 p3 p4
@@ -1309,8 +1309,8 @@ defines new polygon,  p4  may be unused
 

-
-

2.4. warn

+
+

2.4. warn

 warn  <message>
@@ -1321,8 +1321,8 @@ displays warning message, and wait for key
 

-
-

2.5. end

+
+

2.5. end

 end
@@ -1333,8 +1333,8 @@ terminates parser
 

-
-

2.6. mtl

+
+

2.6. mtl

 mtl  material
@@ -1345,8 +1345,8 @@ selects material
 

-
-

2.7. mtlrnd

+
+

2.7. mtlrnd

 mtlrnd  material ...
@@ -1357,8 +1357,8 @@ selects random material from list
 

-
-

2.8. obj

+
+

2.8. obj

 obj  object xz45 xy20 x+3 y*2
@@ -1373,14 +1373,14 @@ directly from file, and not chached, to allow loading of greater than
 

-
+

rotation.png

-
-

2.9. rnd

+
+

2.9. rnd

 rnd  p^1^2^3 p^7^2^1
@@ -1391,8 +1391,8 @@ select random command to execute, ^ will be converted to spaces.
 

-
-

2.10. #

+
+

2.10. #

 # whatever text
@@ -1403,8 +1403,8 @@ comment
 

-
-

2.11. out

+
+

2.11. out

 out  file
@@ -1415,8 +1415,8 @@ specify output file name, must be first command
 

-
-

2.12. set

+
+

2.12. set

 set  variable  contents
@@ -1428,8 +1428,8 @@ string. max variables is 100. first is 0.
 

-
-

2.13. variables usage

+
+

2.13. variables usage

 anycommand %1 anything
@@ -1440,8 +1440,8 @@ inserts variable 1 contents info line
 

-
-

2.14. cmp

+
+

2.14. cmp

 cmp  flag string1 string2
@@ -1452,8 +1452,8 @@ compares strings, and inserts TRUE to flag, if they are equal, else inserts FALS
 

-
-

2.15. ?

+
+

2.15. ?

 ?flag anycommand
@@ -1468,8 +1468,8 @@ exapmle: ?3 obj car z*2 xy45
 

-
-

2.16. dum

+
+

2.16. dum

 dum
@@ -1482,16 +1482,16 @@ dummy function, does notheing
 
-
-

3. Installation

+
+

3. Installation

Edit bin/3dparse.bas file and update include path in there.

-
-

3.1. System requirements

+
+

3.1. System requirements

@@ -1522,8 +1522,8 @@ Edit bin/3dparse.bas file and update include path in there. -
-

3.2. Directory layout

+
+

3.2. Directory layout

bin
@@ -1540,8 +1540,8 @@ Edit bin/3dparse.bas file and update include path in there.
-
-

4. Usage

+
+

4. Usage

Make sure you have QB binaries in your PATH. Execute @@ -1566,7 +1566,7 @@ Visualize scene with your favourite renderer.

-

Created: 2025-07-29 ti 17:32

+

Created: 2025-07-30 ke 01:28

Validate

diff --git a/3D GFX/Miscellaneous/index.html b/3D GFX/Miscellaneous/index.html index 7a61679..7b85e61 100644 --- a/3D GFX/Miscellaneous/index.html +++ b/3D GFX/Miscellaneous/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Miscellaneous 3D graphics demos @@ -210,14 +210,14 @@

Table of Contents

@@ -238,8 +238,8 @@ } -
-

1. Rotating exclamation mark

+
+

1. Rotating exclamation mark

Wireframe 3D model of a rotating exclamation mark. @@ -258,8 +258,8 @@ Wireframe 3D model of a rotating exclamation mark.

-
-

2. 3D bouncing ball

+
+

2. 3D bouncing ball

This QBasic program creates a visually engaging 3D animation of a @@ -280,8 +280,8 @@ of early computer graphics techniques.

-
-

3. 3D text in a room

+
+

3. 3D text in a room

Wireframe 3D text hanging in a wireframe 3D room. User can look and @@ -301,8 +301,8 @@ fly around in all directions.

-
-

4. 3D bouncing cubes on grid floor

+
+

4. 3D bouncing cubes on grid floor

3D wireframe cubes bouncing on a grid floor, creating an immersive and @@ -322,8 +322,8 @@ dynamic visual effect.

-
-

5. Matrix math for rotation in 3D space

+
+

5. Matrix math for rotation in 3D space

Instead of combining simple 2D rotors, pixels in this 3D space are @@ -343,8 +343,8 @@ rotated by using matrix multiplications.

-
-

6. Maze explorer

+
+

6. Maze explorer

The Evolving 3D Maze Explorer is a QBasic program that generates and @@ -355,7 +355,7 @@ changes as they navigate through it.

-
+

Maze%20explorer.png

@@ -366,8 +366,8 @@ changes as they navigate through it.
-
-

7. Tank animation

+
+

7. Tank animation

Animated tank driving through the bridge back and forward. User can @@ -387,8 +387,8 @@ look and fly around in all directions.

-
-

8. Tiled room

+
+

8. Tiled room

Room with some tiles on the wall and on the floor. User can freely fly @@ -409,7 +409,7 @@ around.

-

Created: 2025-07-29 ti 17:32

+

Created: 2025-07-30 ke 01:28

Validate

diff --git a/3D GFX/Space/index.html b/3D GFX/Space/index.html index d3444ee..b4d79a4 100644 --- a/3D GFX/Space/index.html +++ b/3D GFX/Space/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Space themed 3D graphics @@ -210,10 +210,10 @@

Table of Contents

@@ -234,8 +234,8 @@ } -
-

1. Galaxy explorer

+
+

1. Galaxy explorer

This QBasic program renders a navigable 3D point cloud galaxy, @@ -245,7 +245,7 @@ galaxy with stars distributed in a spiral pattern.

-
+

Galaxy%20explorer.png

@@ -256,8 +256,8 @@ galaxy with stars distributed in a spiral pattern.
-
-

2. Rocket simulator

+
+

2. Rocket simulator

QBasic program that simulates the takeoff and flight of a rocket from @@ -279,8 +279,8 @@ observe the rocket's trajectory from various angles.

-
-

3. Stars

+
+

3. Stars

The 3D Starfield Simulation is a QBasic program that creates a @@ -320,8 +320,8 @@ based on its distance, with closer stars appearing brighter.

-
-

4. Universe explorer

+
+

4. Universe explorer

This QBasic program that simulates a navigable 3D universe. Users can @@ -358,19 +358,19 @@ limiting the number of rendered objects based on distance. -

+

1.png

-
+

2.png

-
+

3.png

@@ -382,7 +382,7 @@ limiting the number of rendered objects based on distance.
-

Created: 2025-07-29 ti 17:32

+

Created: 2025-07-30 ke 01:28

Validate

diff --git a/Math/Plotting/index.html b/Math/Plotting/index.html index b4d8be5..13be060 100644 --- a/Math/Plotting/index.html +++ b/Math/Plotting/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Plotting @@ -210,10 +210,10 @@

Table of Contents

@@ -234,8 +234,8 @@ } -
-

1. 2D graph

+
+

1. 2D graph

The 2D Graph Plotter is a simple yet effective program written in @@ -251,7 +251,7 @@ based on a user-defined mathematical function.

-
+

2D%20graph%20plot.png

@@ -262,8 +262,8 @@ based on a user-defined mathematical function.
-
-

2. 3D graph

+
+

2. 3D graph

The 3D Heightmap Explorer is a QBasic program designed to visualize @@ -299,7 +299,7 @@ grid.

-
+

3D%20graph.png

@@ -310,8 +310,8 @@ grid.
-
-

3. Deriviative calculator

+
+

3. Deriviative calculator

This QBasic program is designed to compute and plot an arbitrary @@ -324,7 +324,7 @@ visualized.

-
+

Deriviative%20calculator.png

@@ -335,8 +335,8 @@ visualized.
-
-

4. Sine and cosine table

+
+

4. Sine and cosine table

The SIN & COS Table Generator is a QBasic program designed to visually @@ -346,7 +346,7 @@ visual representation of these fundamental trigonometric functions.

-
+

Sine%20and%20cosine%20table.png

@@ -358,7 +358,7 @@ visual representation of these fundamental trigonometric functions.
-

Created: 2025-07-29 ti 17:33

+

Created: 2025-07-30 ke 01:28

Validate

diff --git a/Math/Simulation/index.html b/Math/Simulation/index.html index 46fbb93..9bf6f7a 100644 --- a/Math/Simulation/index.html +++ b/Math/Simulation/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Simulation @@ -210,14 +210,14 @@

Table of Contents

@@ -238,8 +238,8 @@ } -
-

1. Explosion simulator

+
+

1. Explosion simulator

This QBasic program simulates the propagation of shock waves in a gas @@ -265,7 +265,7 @@ conditions by setting velocities to zero at wall boundaries.

-
+

Explosion%20simulator.png

@@ -276,8 +276,8 @@ conditions by setting velocities to zero at wall boundaries.
-
-

2. Gravity in 2D

+
+

2. Gravity in 2D

The Gravitation Simulation program is a simple yet insightful QBasic @@ -289,7 +289,7 @@ educational tool for understanding basic orbital mechanics.

-
+

Gravity%20in%202D.png

@@ -300,8 +300,8 @@ educational tool for understanding basic orbital mechanics.
-
-

3. Gravity in 3D

+
+

3. Gravity in 3D

This QBasic program simulates the gravitational interactions between @@ -335,8 +335,8 @@ will reach stable configuration.

-
-

4. Interference

+
+

4. Interference

This QBasic program simulates the interference pattern created by two @@ -364,8 +364,8 @@ displayed as a third waveform.

-
-

5. Interferogram

+
+

5. Interferogram

This QBasic program simulates the interference pattern created by @@ -375,7 +375,7 @@ used in physics and engineering to analyze wave interactions.

-
+

Interferogram.png

@@ -386,8 +386,8 @@ used in physics and engineering to analyze wave interactions.
-
-

6. Surface tension

+
+

6. Surface tension

This QBasic program simulates the behavior of water spills and the @@ -411,7 +411,7 @@ water cell if surrounded by a high density of water cells.

-
+

Surface%20tension.png

@@ -422,8 +422,8 @@ water cell if surrounded by a high density of water cells.
-
-

7. Wave 1

+
+

7. Wave 1

This QBasic program simulates the propagation of waves across a @@ -439,7 +439,7 @@ loss.

-
+

Wave%201.png

@@ -450,8 +450,8 @@ loss.
-
-

8. Wave 2

+
+

8. Wave 2

This QBasic program simulates and visualizes the behavior of water @@ -463,7 +463,7 @@ understanding wave mechanics.

-
+

Wave%202.png

@@ -475,7 +475,7 @@ understanding wave mechanics.
-

Created: 2025-07-29 ti 17:33

+

Created: 2025-07-30 ke 01:29

Validate

diff --git a/Math/Truth table/index.html b/Math/Truth table/index.html index a993d50..27ee4b5 100644 --- a/Math/Truth table/index.html +++ b/Math/Truth table/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Truth table calculator @@ -1103,20 +1103,20 @@ hsAddReviewPanels();

Table of Contents

@@ -1133,12 +1133,12 @@ the input variables, with the corresponding output value. Truth tables are cruci designing and understanding digital circuits, Boolean algebra, and logical expressions.

-
-

1. Implemented logical operations

+
+

1. Implemented logical operations

-
-

1.1. Equivalent ( ⇔ , 1 )

+
+

1.1. Equivalent ( ⇔ , 1 )

The equivalent operation, also known as logical biconditional, is true if and only if @@ -1196,8 +1196,8 @@ Truth Table:

-
-

1.2. Implies ( ⇒ , 2 )

+
+

1.2. Implies ( ⇒ , 2 )

An implication asserts that if the first proposition is true, the @@ -1255,8 +1255,8 @@ Truth table:

-
-

1.3. OR ( ∨ , 3 )

+
+

1.3. OR ( ∨ , 3 )

The OR operation, also known as logical disjunction, is true if at @@ -1314,8 +1314,8 @@ Truth table:

-
-

1.4. AND ( ∧ , 4 )

+
+

1.4. AND ( ∧ , 4 )

The AND operation, also known as logical conjunction, is true if and @@ -1372,8 +1372,8 @@ Truth table:

-
-

1.5. NOT ( ¬ , 5 )

+
+

1.5. NOT ( ¬ , 5 )

The NOT operation, also known as logical negation, inverts the value @@ -1414,12 +1414,12 @@ Truth Table:

-
-

2. Examples

+
+

2. Examples

-
-

2.1. Example: (A ∧ B) ∨ ¬C

+
+

2.1. Example: (A ∧ B) ∨ ¬C

@@ -1502,8 +1502,8 @@ Truth Table: -
-

2.2. Example: A ⇒ (B ∨ ¬C)

+
+

2.2. Example: A ⇒ (B ∨ ¬C)

@@ -1586,8 +1586,8 @@ Truth Table: -
-

2.3. Example: (A ⇔ B) ∧ C

+
+

2.3. Example: (A ⇔ B) ∧ C

Truth Table: @@ -1676,7 +1676,7 @@ Truth Table:

-

Created: 2025-07-29 ti 17:34

+

Created: 2025-07-30 ke 01:30

Validate

diff --git a/Miscellaneous/4D engine.bas b/Miscellaneous/4D engine.bas new file mode 100755 index 0000000..1f87299 --- /dev/null +++ b/Miscellaneous/4D engine.bas @@ -0,0 +1,350 @@ +' 4D engine. It renders a 5-cell (aka. pentachoron) as a series +' of 3D tetrahedrons with varying brightness. Brightness is used +' to indicate shift in the fourth dimension. +' +' In essence, you can look at a 3D object as a series of 2D +' cross-sections along the third dimension. Here we look at +' a 4D object as a series of 3D cross-sections with varying +' brightness (to distinguish between them). +' +' 4 dimensions also make it possible to rotate the object along +' 6 different axes. Interestingly, the shape of the object changes +' in 3D space when it is rotated along any of the axes that +' involve the fourth dimension. +' +' This program is free software: released under Creative Commons Zero (CC0) license +' by Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 2003.08, Initial version +' 2024 - 2025, Improved program readability + +' Declare subroutines and functions that will be used in the program +DECLARE SUB CalculateInterpolatedLine (originalX1!, originalY1!, originalZ1!, originalQ1!, originalX2!, originalY2!, originalZ2!, originalQ2!) +DECLARE SUB RotatePoint (x1!, y1!, z1!, q1!, x4!, y4!, z4!, q4!) +DECLARE SUB SetupPalette () +DECLARE SUB GetPointAtDistance (x1!, y1!, z1!, q1!, x2!, y2!, z2!, q2!, distanceFactor!, rx!, ry!, rz!, rq!) +DECLARE SUB RenderPentachoron (ox1!, oy1!, oz1!, oq1!, ox2!, oy2!, oz2!, oq2!, ox3!, oy3!, oz3!, oq3!, ox4!, oy4!, oz4!, oq4!, ox5!, oy5!, oz5!, oq5!) +DECLARE FUNCTION CalculateDistance (x1!, y1!, z1!, q1!, x2!, y2!, z2!, q2!) + +' Shared variables that can be accessed from any subroutine +DIM SHARED screenSize +DIM SHARED angleXZ, angleYZ, angleXY, angleQX, angleQY, angleQZ +DIM SHARED cameraX, cameraY, cameraZ, cameraQ +DIM SHARED pi +DIM SHARED sineXZ, sineYZ, sineXY, sineQX, sineQY, sineQZ +DIM SHARED cosineXZ, cosineYZ, cosineXY, cosineQX, cosineQY, cosineQZ + +' Arrays to store projected points and other drawing information +DIM SHARED projectedX(1 TO 10) +DIM SHARED projectedY(1 TO 10) +DIM SHARED pointCount +DIM SHARED frame + +' Display control instructions to the user +PRINT "" +PRINT " Use keys:" +PRINT " Rotate:" +PRINT " qw - XZ" +PRINT " as - YZ" +PRINT " zx - XY" +PRINT " er - QX" +PRINT " df - QY" +PRINT " cv - QZ" +PRINT " Move:" +PRINT " 46 - x" +PRINT " 82 - y" +PRINT " 71 - z" +PRINT " -+ - q" +PRINT +PRINT " ESC - to quit program" +PRINT +PRINT " Press any key to continue..." +in$ = INPUT$(1) + +' Initialize pi value for rotation calculations +pi = 3.1415 + +' Initialize rotation angles for each axis +angleXZ = pi * .5 +angleYZ = angleXZ +angleXY = angleXZ +angleQX = angleXZ +angleQY = angleXZ +angleQZ = angleXZ + +' Set initial camera position in 4D space +cameraX = 0 +cameraY = 0 +cameraZ = 0 +cameraQ = .5 + +' Set graphics mode to 640x480 with 16 colors +SCREEN 12 +' Setup the color palette for rendering +SetupPalette + +MainLoop: +' Clear screen for new frame +CLS + +' Calculate sine and cosine values for each rotation angle +sineXZ = SIN(angleXZ): cosineXZ = COS(angleXZ) +sineYZ = SIN(angleYZ): cosineYZ = COS(angleYZ) +sineXY = SIN(angleXY): cosineXY = COS(angleXY) +sineQX = SIN(angleQX): cosineQX = COS(angleQX) +sineQY = SIN(angleQY): cosineQY = COS(angleQY) +sineQZ = SIN(angleQZ): cosineQZ = COS(angleQZ) + +' Render multiple frames of the pentachoron with varying depth +FOR frame = 1 TO 15 STEP 3 + ' Render a pentachoron (5-cell) with the current camera position and rotation + RenderPentachoron -10, -10, -10, 0, 10, -10, -10, 0, 0, -10, 10, 0, 0, 10, 0, 0, 0, 0, 0, 10 +NEXT frame + +' Get user input for camera control +in$ = INPUT$(1) + +' Handle user input for rotation and movement +SELECT CASE in$ +CASE CHR$(27) + ' ESC key pressed - exit program + SYSTEM +CASE "q" + ' Increase rotation angle along XZ axis + angleXZ = angleXZ + .1 +CASE "w" + ' Decrease rotation angle along XZ axis + angleXZ = angleXZ - .1 +CASE "a" + ' Increase rotation angle along YZ axis + angleYZ = angleYZ + .1 +CASE "s" + ' Decrease rotation angle along YZ axis + angleYZ = angleYZ - .1 +CASE "z" + ' Increase rotation angle along XY axis + angleXY = angleXY + .1 +CASE "x" + ' Decrease rotation angle along XY axis + angleXY = angleXY - .1 +CASE "e" + ' Increase rotation angle along QX axis + angleQX = angleQX + .1 +CASE "r" + ' Decrease rotation angle along QX axis + angleQX = angleQX - .1 +CASE "d" + ' Increase rotation angle along QY axis + angleQY = angleQY + .1 +CASE "f" + ' Decrease rotation angle along QY axis + angleQY = angleQY - .1 +CASE "c" + ' Increase rotation angle along QZ axis + angleQZ = angleQZ + .1 +CASE "v" + ' Decrease rotation angle along QZ axis + angleQZ = angleQZ - .1 + +' Handle user input for movement in the 4D space +CASE "4" + ' Move camera left along X axis + cameraX = cameraX - 3 +CASE "6" + ' Move camera right along X axis + cameraX = cameraX + 3 +CASE "8" + ' Move camera forward along Z axis + cameraZ = cameraZ + 3 +CASE "2" + ' Move camera backward along Z axis + cameraZ = cameraZ - 3 +CASE "7" + ' Move camera up along Y axis + cameraY = cameraY + 3 +CASE "1" + ' Move camera down along Y axis + cameraY = cameraY - 3 +CASE "+" + ' Move camera forward along Q axis (4th dimension) + cameraQ = cameraQ + .3 +CASE "-" + ' Move camera backward along Q axis (4th dimension) + cameraQ = cameraQ - .3 + +END SELECT + +' Loop back to render next frame +GOTO MainLoop + +' Function to calculate the distance between two points in 4D space +FUNCTION CalculateDistance (x1, y1, z1, q1, x2, y2, z2, q2) + ' Calculate Euclidean distance in 4D space + CalculateDistance = SQR((x1 - x2) ^ 2 + (y1 - y2) ^ 2 + (z1 - z2) ^ 2 + (q1 - q2) ^ 2) +END FUNCTION + +' Subroutine to calculate the linear interpolation between two points +SUB CalculateInterpolatedLine (originalX1, originalY1, originalZ1, originalQ1, originalX2, originalY2, originalZ2, originalQ2) + ' Local variables to store coordinates of the two points + x1 = originalX1: y1 = originalY1: z1 = originalZ1: q1 = originalQ1 + x2 = originalX2: y2 = originalY2: z2 = originalZ2: q2 = originalQ2 + + ' If the first point is in front of the camera and the second is behind, + ' swap them to ensure proper rendering order + IF (q1 > cameraQ) AND (q2 < cameraQ) THEN + SWAP x1, x2 + SWAP y1, y2 + SWAP z1, z2 + SWAP q1, q2 + END IF + + ' If the first point is in front of the camera and the second is behind, + ' calculate the intersection point where the line segment crosses the camera plane + IF (q1 < cameraQ) AND (q2 > cameraQ) THEN + ' Calculate the difference in Q coordinates + qDifference = q2 - q1 + ' Calculate how far along the line segment we need to go to reach the camera plane + qToCamera = cameraQ - q1 + ' Calculate the interpolation factor + interpolationFactor = qToCamera / qDifference + ' Increment point counter + pointCount = pointCount + 1 + ' Calculate interpolated coordinates + interpolatedX = (x2 - x1) * interpolationFactor + x1 + interpolatedY = (y2 - y1) * interpolationFactor + y1 + interpolatedZ = (z2 - z1) * interpolationFactor + z1 + 50 + ' Project 3D coordinates to 2D screen coordinates and store them + projectedX(pointCount) = interpolatedX / interpolatedZ * 700 + 320 + projectedY(pointCount) = interpolatedY / interpolatedZ * 700 + 240 + END IF +END SUB + +' Subroutine to get a point at a specific distance along the line segment +SUB GetPointAtDistance (x1, y1, z1, q1, x2, y2, z2, q2, distanceFactor, rx, ry, rz, rq) + ' Calculate the vector between the two points + xVector = x2 - x1 + yVector = y2 - y1 + zVector = z2 - z1 + qVector = q2 - q1 + + ' Calculate the coordinates of the point at the specified distance along the line segment + rx = x1 + (xVector * distanceFactor) + ry = y1 + (yVector * distanceFactor) + rz = z1 + (zVector * distanceFactor) + rq = q1 + (qVector * distanceFactor) +END SUB + +' Subroutine to render a 3D tetrahedron with varying brightness +SUB RenderPentachoron (originalX1, originalY1, originalZ1, originalQ1, originalX2, originalY2, originalZ2, originalQ2, originalX3, originalY3, originalZ3, originalQ3, originalX4, originalY4, originalZ4, originalQ4, originalX5, originalY5, originalZ5 _ +, originalQ5) + + ' Adjust coordinates based on camera position and frame depth + originalX1 = originalX1 - cameraX + originalY1 = originalY1 - cameraY + originalZ1 = originalZ1 - cameraZ + originalQ1 = originalQ1 - cameraQ - frame + + originalX2 = originalX2 - cameraX + originalY2 = originalY2 - cameraY + originalZ2 = originalZ2 - cameraZ + originalQ2 = originalQ2 - cameraQ - frame + + originalX3 = originalX3 - cameraX + originalY3 = originalY3 - cameraY + originalZ3 = originalZ3 - cameraZ + originalQ3 = originalQ3 - cameraQ - frame + + originalX4 = originalX4 - cameraX + originalY4 = originalY4 - cameraY + originalZ4 = originalZ4 - cameraZ + originalQ4 = originalQ4 - cameraQ - frame + + originalX5 = originalX5 - cameraX + originalY5 = originalY5 - cameraY + originalZ5 = originalZ5 - cameraZ + originalQ5 = originalQ5 - cameraQ - frame + + ' Rotate all points based on current rotation angles + RotatePoint originalX1, originalY1, originalZ1, originalQ1, x1, y1, z1, q1 + RotatePoint originalX2, originalY2, originalZ2, originalQ2, x2, y2, z2, q2 + RotatePoint originalX3, originalY3, originalZ3, originalQ3, x3, y3, z3, q3 + RotatePoint originalX4, originalY4, originalZ4, originalQ4, x4, y4, z4, q4 + RotatePoint originalX5, originalY5, originalZ5, originalQ5, x5, y5, z5, q5 + + ' Initialize point counter + pointCount = 0 + + ' Calculate interpolated points for all edges of the pentachoron + CalculateInterpolatedLine x1, y1, z1, q1, x2, y2, z2, q2 + CalculateInterpolatedLine x1, y1, z1, q1, x3, y3, z3, q3 + CalculateInterpolatedLine x1, y1, z1, q1, x4, y4, z4, q4 + CalculateInterpolatedLine x1, y1, z1, q1, x5, y5, z5, q5 + + CalculateInterpolatedLine x2, y2, z2, q2, x3, y3, z3, q3 + CalculateInterpolatedLine x2, y2, z2, q2, x4, y4, z4, q4 + CalculateInterpolatedLine x2, y2, z2, q2, x5, y5, z5, q5 + + CalculateInterpolatedLine x3, y3, z3, q3, x4, y4, z4, q4 + CalculateInterpolatedLine x3, y3, z3, q3, x5, y5, z5, q5 + + CalculateInterpolatedLine x4, y4, z4, q4, x5, y5, z5, q5 + + ' Draw lines between each pair of interpolated points + FOR pointA = 1 TO pointCount + FOR pointB = pointA + 1 TO pointCount + ' Draw line with color based on frame depth (for varying brightness) + LINE (projectedX(pointA), projectedY(pointA))-(projectedX(pointB), projectedY(pointB)), 15 - frame + NEXT pointB + NEXT pointA + +END SUB + +' Subroutine to rotate a point along the specified axes +SUB RotatePoint (x1, y1, z1, q1, x4, y4, z4, q4) + + ' Rotate the point along the QX axis + q2 = q1 * sineQX - x1 * cosineQX + x2 = q1 * cosineQX + x1 * sineQX + + ' Rotate the point along the QY axis + q3 = q2 * sineQY - y1 * cosineQY + y2 = q2 * cosineQY + y1 * sineQY + + ' Rotate the point along the QZ axis + q4 = q3 * sineQZ - z1 * cosineQZ + z2 = q3 * cosineQZ + z1 * sineQZ + + ' Rotate the point along the XZ axis + x3 = x2 * sineXZ - z2 * cosineXZ + z3 = x2 * cosineXZ + z2 * sineXZ + + ' Rotate the point along the YZ axis + y3 = y2 * sineYZ - z3 * cosineYZ + z4 = y2 * cosineYZ + z3 * sineYZ + + ' Rotate the point along the XY axis + y4 = y3 * sineXY - x3 * cosineXY + x4 = y3 * cosineXY + x3 * sineXY + +END SUB + +' Subroutine to set up the color palette +SUB SetupPalette + + ' Set up a grayscale color palette + FOR colorIndex = 0 TO 15 + ' Set palette register + OUT &H3C8, colorIndex + ' Set RGB values (all equal for grayscale) + OUT &H3C9, colorIndex * 4 + OUT &H3C9, colorIndex * 4 + OUT &H3C9, colorIndex * 4 + ' Draw a vertical line with this color to visualize the palette + LINE (colorIndex, 0)-(colorIndex, 400), colorIndex + NEXT colorIndex + +END SUB + diff --git a/Miscellaneous/4D engine.png b/Miscellaneous/4D engine.png new file mode 100644 index 0000000..03e6e3e Binary files /dev/null and b/Miscellaneous/4D engine.png differ diff --git a/Miscellaneous/4D engine/index.html b/Miscellaneous/4D engine/index.html deleted file mode 100644 index 67998b4..0000000 --- a/Miscellaneous/4D engine/index.html +++ /dev/null @@ -1,22 +0,0 @@ - -4D engine - - - -

4D engine

-
-
-Implementation of 4 dimensional (4D) engine. -It's like 3D but with additional extra dimension. - -It's possible to define objects from 4D polygons. -In 4D world minimum amount of points to define 4D -shape is 5. Each point will be defined by 4 coordinates (X, Y, Z, Q). - -You can rotate object around any axis -(4D world has 6 rotation axes!) -Program allows you to move along any dimension. - -
- - \ No newline at end of file diff --git a/Miscellaneous/4D engine/qeng.bas b/Miscellaneous/4D engine/qeng.bas deleted file mode 100755 index 1f87299..0000000 --- a/Miscellaneous/4D engine/qeng.bas +++ /dev/null @@ -1,350 +0,0 @@ -' 4D engine. It renders a 5-cell (aka. pentachoron) as a series -' of 3D tetrahedrons with varying brightness. Brightness is used -' to indicate shift in the fourth dimension. -' -' In essence, you can look at a 3D object as a series of 2D -' cross-sections along the third dimension. Here we look at -' a 4D object as a series of 3D cross-sections with varying -' brightness (to distinguish between them). -' -' 4 dimensions also make it possible to rotate the object along -' 6 different axes. Interestingly, the shape of the object changes -' in 3D space when it is rotated along any of the axes that -' involve the fourth dimension. -' -' This program is free software: released under Creative Commons Zero (CC0) license -' by Svjatoslav Agejenko. -' Email: svjatoslav@svjatoslav.eu -' Homepage: http://www.svjatoslav.eu -' -' Changelog: -' 2003.08, Initial version -' 2024 - 2025, Improved program readability - -' Declare subroutines and functions that will be used in the program -DECLARE SUB CalculateInterpolatedLine (originalX1!, originalY1!, originalZ1!, originalQ1!, originalX2!, originalY2!, originalZ2!, originalQ2!) -DECLARE SUB RotatePoint (x1!, y1!, z1!, q1!, x4!, y4!, z4!, q4!) -DECLARE SUB SetupPalette () -DECLARE SUB GetPointAtDistance (x1!, y1!, z1!, q1!, x2!, y2!, z2!, q2!, distanceFactor!, rx!, ry!, rz!, rq!) -DECLARE SUB RenderPentachoron (ox1!, oy1!, oz1!, oq1!, ox2!, oy2!, oz2!, oq2!, ox3!, oy3!, oz3!, oq3!, ox4!, oy4!, oz4!, oq4!, ox5!, oy5!, oz5!, oq5!) -DECLARE FUNCTION CalculateDistance (x1!, y1!, z1!, q1!, x2!, y2!, z2!, q2!) - -' Shared variables that can be accessed from any subroutine -DIM SHARED screenSize -DIM SHARED angleXZ, angleYZ, angleXY, angleQX, angleQY, angleQZ -DIM SHARED cameraX, cameraY, cameraZ, cameraQ -DIM SHARED pi -DIM SHARED sineXZ, sineYZ, sineXY, sineQX, sineQY, sineQZ -DIM SHARED cosineXZ, cosineYZ, cosineXY, cosineQX, cosineQY, cosineQZ - -' Arrays to store projected points and other drawing information -DIM SHARED projectedX(1 TO 10) -DIM SHARED projectedY(1 TO 10) -DIM SHARED pointCount -DIM SHARED frame - -' Display control instructions to the user -PRINT "" -PRINT " Use keys:" -PRINT " Rotate:" -PRINT " qw - XZ" -PRINT " as - YZ" -PRINT " zx - XY" -PRINT " er - QX" -PRINT " df - QY" -PRINT " cv - QZ" -PRINT " Move:" -PRINT " 46 - x" -PRINT " 82 - y" -PRINT " 71 - z" -PRINT " -+ - q" -PRINT -PRINT " ESC - to quit program" -PRINT -PRINT " Press any key to continue..." -in$ = INPUT$(1) - -' Initialize pi value for rotation calculations -pi = 3.1415 - -' Initialize rotation angles for each axis -angleXZ = pi * .5 -angleYZ = angleXZ -angleXY = angleXZ -angleQX = angleXZ -angleQY = angleXZ -angleQZ = angleXZ - -' Set initial camera position in 4D space -cameraX = 0 -cameraY = 0 -cameraZ = 0 -cameraQ = .5 - -' Set graphics mode to 640x480 with 16 colors -SCREEN 12 -' Setup the color palette for rendering -SetupPalette - -MainLoop: -' Clear screen for new frame -CLS - -' Calculate sine and cosine values for each rotation angle -sineXZ = SIN(angleXZ): cosineXZ = COS(angleXZ) -sineYZ = SIN(angleYZ): cosineYZ = COS(angleYZ) -sineXY = SIN(angleXY): cosineXY = COS(angleXY) -sineQX = SIN(angleQX): cosineQX = COS(angleQX) -sineQY = SIN(angleQY): cosineQY = COS(angleQY) -sineQZ = SIN(angleQZ): cosineQZ = COS(angleQZ) - -' Render multiple frames of the pentachoron with varying depth -FOR frame = 1 TO 15 STEP 3 - ' Render a pentachoron (5-cell) with the current camera position and rotation - RenderPentachoron -10, -10, -10, 0, 10, -10, -10, 0, 0, -10, 10, 0, 0, 10, 0, 0, 0, 0, 0, 10 -NEXT frame - -' Get user input for camera control -in$ = INPUT$(1) - -' Handle user input for rotation and movement -SELECT CASE in$ -CASE CHR$(27) - ' ESC key pressed - exit program - SYSTEM -CASE "q" - ' Increase rotation angle along XZ axis - angleXZ = angleXZ + .1 -CASE "w" - ' Decrease rotation angle along XZ axis - angleXZ = angleXZ - .1 -CASE "a" - ' Increase rotation angle along YZ axis - angleYZ = angleYZ + .1 -CASE "s" - ' Decrease rotation angle along YZ axis - angleYZ = angleYZ - .1 -CASE "z" - ' Increase rotation angle along XY axis - angleXY = angleXY + .1 -CASE "x" - ' Decrease rotation angle along XY axis - angleXY = angleXY - .1 -CASE "e" - ' Increase rotation angle along QX axis - angleQX = angleQX + .1 -CASE "r" - ' Decrease rotation angle along QX axis - angleQX = angleQX - .1 -CASE "d" - ' Increase rotation angle along QY axis - angleQY = angleQY + .1 -CASE "f" - ' Decrease rotation angle along QY axis - angleQY = angleQY - .1 -CASE "c" - ' Increase rotation angle along QZ axis - angleQZ = angleQZ + .1 -CASE "v" - ' Decrease rotation angle along QZ axis - angleQZ = angleQZ - .1 - -' Handle user input for movement in the 4D space -CASE "4" - ' Move camera left along X axis - cameraX = cameraX - 3 -CASE "6" - ' Move camera right along X axis - cameraX = cameraX + 3 -CASE "8" - ' Move camera forward along Z axis - cameraZ = cameraZ + 3 -CASE "2" - ' Move camera backward along Z axis - cameraZ = cameraZ - 3 -CASE "7" - ' Move camera up along Y axis - cameraY = cameraY + 3 -CASE "1" - ' Move camera down along Y axis - cameraY = cameraY - 3 -CASE "+" - ' Move camera forward along Q axis (4th dimension) - cameraQ = cameraQ + .3 -CASE "-" - ' Move camera backward along Q axis (4th dimension) - cameraQ = cameraQ - .3 - -END SELECT - -' Loop back to render next frame -GOTO MainLoop - -' Function to calculate the distance between two points in 4D space -FUNCTION CalculateDistance (x1, y1, z1, q1, x2, y2, z2, q2) - ' Calculate Euclidean distance in 4D space - CalculateDistance = SQR((x1 - x2) ^ 2 + (y1 - y2) ^ 2 + (z1 - z2) ^ 2 + (q1 - q2) ^ 2) -END FUNCTION - -' Subroutine to calculate the linear interpolation between two points -SUB CalculateInterpolatedLine (originalX1, originalY1, originalZ1, originalQ1, originalX2, originalY2, originalZ2, originalQ2) - ' Local variables to store coordinates of the two points - x1 = originalX1: y1 = originalY1: z1 = originalZ1: q1 = originalQ1 - x2 = originalX2: y2 = originalY2: z2 = originalZ2: q2 = originalQ2 - - ' If the first point is in front of the camera and the second is behind, - ' swap them to ensure proper rendering order - IF (q1 > cameraQ) AND (q2 < cameraQ) THEN - SWAP x1, x2 - SWAP y1, y2 - SWAP z1, z2 - SWAP q1, q2 - END IF - - ' If the first point is in front of the camera and the second is behind, - ' calculate the intersection point where the line segment crosses the camera plane - IF (q1 < cameraQ) AND (q2 > cameraQ) THEN - ' Calculate the difference in Q coordinates - qDifference = q2 - q1 - ' Calculate how far along the line segment we need to go to reach the camera plane - qToCamera = cameraQ - q1 - ' Calculate the interpolation factor - interpolationFactor = qToCamera / qDifference - ' Increment point counter - pointCount = pointCount + 1 - ' Calculate interpolated coordinates - interpolatedX = (x2 - x1) * interpolationFactor + x1 - interpolatedY = (y2 - y1) * interpolationFactor + y1 - interpolatedZ = (z2 - z1) * interpolationFactor + z1 + 50 - ' Project 3D coordinates to 2D screen coordinates and store them - projectedX(pointCount) = interpolatedX / interpolatedZ * 700 + 320 - projectedY(pointCount) = interpolatedY / interpolatedZ * 700 + 240 - END IF -END SUB - -' Subroutine to get a point at a specific distance along the line segment -SUB GetPointAtDistance (x1, y1, z1, q1, x2, y2, z2, q2, distanceFactor, rx, ry, rz, rq) - ' Calculate the vector between the two points - xVector = x2 - x1 - yVector = y2 - y1 - zVector = z2 - z1 - qVector = q2 - q1 - - ' Calculate the coordinates of the point at the specified distance along the line segment - rx = x1 + (xVector * distanceFactor) - ry = y1 + (yVector * distanceFactor) - rz = z1 + (zVector * distanceFactor) - rq = q1 + (qVector * distanceFactor) -END SUB - -' Subroutine to render a 3D tetrahedron with varying brightness -SUB RenderPentachoron (originalX1, originalY1, originalZ1, originalQ1, originalX2, originalY2, originalZ2, originalQ2, originalX3, originalY3, originalZ3, originalQ3, originalX4, originalY4, originalZ4, originalQ4, originalX5, originalY5, originalZ5 _ -, originalQ5) - - ' Adjust coordinates based on camera position and frame depth - originalX1 = originalX1 - cameraX - originalY1 = originalY1 - cameraY - originalZ1 = originalZ1 - cameraZ - originalQ1 = originalQ1 - cameraQ - frame - - originalX2 = originalX2 - cameraX - originalY2 = originalY2 - cameraY - originalZ2 = originalZ2 - cameraZ - originalQ2 = originalQ2 - cameraQ - frame - - originalX3 = originalX3 - cameraX - originalY3 = originalY3 - cameraY - originalZ3 = originalZ3 - cameraZ - originalQ3 = originalQ3 - cameraQ - frame - - originalX4 = originalX4 - cameraX - originalY4 = originalY4 - cameraY - originalZ4 = originalZ4 - cameraZ - originalQ4 = originalQ4 - cameraQ - frame - - originalX5 = originalX5 - cameraX - originalY5 = originalY5 - cameraY - originalZ5 = originalZ5 - cameraZ - originalQ5 = originalQ5 - cameraQ - frame - - ' Rotate all points based on current rotation angles - RotatePoint originalX1, originalY1, originalZ1, originalQ1, x1, y1, z1, q1 - RotatePoint originalX2, originalY2, originalZ2, originalQ2, x2, y2, z2, q2 - RotatePoint originalX3, originalY3, originalZ3, originalQ3, x3, y3, z3, q3 - RotatePoint originalX4, originalY4, originalZ4, originalQ4, x4, y4, z4, q4 - RotatePoint originalX5, originalY5, originalZ5, originalQ5, x5, y5, z5, q5 - - ' Initialize point counter - pointCount = 0 - - ' Calculate interpolated points for all edges of the pentachoron - CalculateInterpolatedLine x1, y1, z1, q1, x2, y2, z2, q2 - CalculateInterpolatedLine x1, y1, z1, q1, x3, y3, z3, q3 - CalculateInterpolatedLine x1, y1, z1, q1, x4, y4, z4, q4 - CalculateInterpolatedLine x1, y1, z1, q1, x5, y5, z5, q5 - - CalculateInterpolatedLine x2, y2, z2, q2, x3, y3, z3, q3 - CalculateInterpolatedLine x2, y2, z2, q2, x4, y4, z4, q4 - CalculateInterpolatedLine x2, y2, z2, q2, x5, y5, z5, q5 - - CalculateInterpolatedLine x3, y3, z3, q3, x4, y4, z4, q4 - CalculateInterpolatedLine x3, y3, z3, q3, x5, y5, z5, q5 - - CalculateInterpolatedLine x4, y4, z4, q4, x5, y5, z5, q5 - - ' Draw lines between each pair of interpolated points - FOR pointA = 1 TO pointCount - FOR pointB = pointA + 1 TO pointCount - ' Draw line with color based on frame depth (for varying brightness) - LINE (projectedX(pointA), projectedY(pointA))-(projectedX(pointB), projectedY(pointB)), 15 - frame - NEXT pointB - NEXT pointA - -END SUB - -' Subroutine to rotate a point along the specified axes -SUB RotatePoint (x1, y1, z1, q1, x4, y4, z4, q4) - - ' Rotate the point along the QX axis - q2 = q1 * sineQX - x1 * cosineQX - x2 = q1 * cosineQX + x1 * sineQX - - ' Rotate the point along the QY axis - q3 = q2 * sineQY - y1 * cosineQY - y2 = q2 * cosineQY + y1 * sineQY - - ' Rotate the point along the QZ axis - q4 = q3 * sineQZ - z1 * cosineQZ - z2 = q3 * cosineQZ + z1 * sineQZ - - ' Rotate the point along the XZ axis - x3 = x2 * sineXZ - z2 * cosineXZ - z3 = x2 * cosineXZ + z2 * sineXZ - - ' Rotate the point along the YZ axis - y3 = y2 * sineYZ - z3 * cosineYZ - z4 = y2 * cosineYZ + z3 * sineYZ - - ' Rotate the point along the XY axis - y4 = y3 * sineXY - x3 * cosineXY - x4 = y3 * cosineXY + x3 * sineXY - -END SUB - -' Subroutine to set up the color palette -SUB SetupPalette - - ' Set up a grayscale color palette - FOR colorIndex = 0 TO 15 - ' Set palette register - OUT &H3C8, colorIndex - ' Set RGB values (all equal for grayscale) - OUT &H3C9, colorIndex * 4 - OUT &H3C9, colorIndex * 4 - OUT &H3C9, colorIndex * 4 - ' Draw a vertical line with this color to visualize the palette - LINE (colorIndex, 0)-(colorIndex, 400), colorIndex - NEXT colorIndex - -END SUB - diff --git a/Miscellaneous/4D engine/sshot.png b/Miscellaneous/4D engine/sshot.png deleted file mode 100644 index 03e6e3e..0000000 Binary files a/Miscellaneous/4D engine/sshot.png and /dev/null differ diff --git a/Miscellaneous/Alarm 1.bas b/Miscellaneous/Alarm 1.bas new file mode 100755 index 0000000..5e973a0 --- /dev/null +++ b/Miscellaneous/Alarm 1.bas @@ -0,0 +1,57 @@ +' Program to play sound that resembles security alarm. +' This program is free software: released under Creative Commons Zero (CC0) license +' by Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' ?, Initial version +' 2024 - 2025, Enhanced program readability + +SCREEN 1 +CLS + +' Initialize main frequency control variable +' This will create the oscillating siren effect by increasing/decreasing value +currentFrequency = 40 + +StartLoop: + ' Play primary oscillating tone (main siren component) + ' Frequency sweeps up and down between thresholds + SOUND currentFrequency, .3 + + ' Add secondary fixed-frequency component (200Hz for 1 duration unit) + ' Creates layered audio effect that makes alarm more realistic + ' Duration parameter uses QBasic's time units (1 ≈ 0.05 seconds) + SOUND 200, 1 + + ' Rapidly increase frequency for ascending siren sweep + ' Jump amount (100) creates dramatic pitch jumps + currentFrequency = currentFrequency + 100 + + ' Check if we've exceeded upper frequency threshold (1000Hz) + ' If yes, switch to descending phase + IF currentFrequency > 1000 THEN GoTo DecreaseFrequency + + ' Repeat ascending sweep until reaching maximum threshold + GOTO StartLoop + +DecreaseFrequency: + ' Continue playing oscillating tone during descending phase + SOUND currentFrequency, .3 + + ' Add high-pitched pulse (500Hz for short duration) + ' Creates distinctive alarm "warble" pattern + ' Shorter duration (.2) adds rhythmic pulsing + SOUND 500, .2 + + ' Gradually decrease frequency for descending sweep + ' Smaller decrement (10) creates slower descent than ascent + currentFrequency = currentFrequency - 10 + + ' Check if we've dropped below lower threshold (200Hz) + ' If yes, restart ascending phase to complete siren cycle + IF currentFrequency < 200 THEN GoTo StartLoop + + ' Continue descending sweep until reaching minimum threshold + GOTO DecreaseFrequency diff --git a/Miscellaneous/Alarm 1.mp3 b/Miscellaneous/Alarm 1.mp3 new file mode 100644 index 0000000..eec2000 Binary files /dev/null and b/Miscellaneous/Alarm 1.mp3 differ diff --git a/Miscellaneous/Alarm 2.bas b/Miscellaneous/Alarm 2.bas new file mode 100755 index 0000000..87f03c1 --- /dev/null +++ b/Miscellaneous/Alarm 2.bas @@ -0,0 +1,34 @@ +' This program generates a security alarm sound effect with two alternating patterns + +DEFINT A-Z + +' Start of infinite alarm cycle +1 + + ' Pattern 1: Ascending frequency sweep with counterpoint tone + ' Increase primary frequency from 100Hz to 1000Hz in steps of 3Hz + FOR ascendingFrequency = 100 TO 1000 STEP 3 + ' Play main ascending tone + SOUND ascendingFrequency, .05 + + ' Generate counterpoint tone that decreases as primary increases + ' Formula creates complementary frequency by subtracting double current frequency + ' At 100Hz -> 5000-2*100=4800Hz; At 1000Hz -> 5000-2*1000=3000Hz + counterToneFrequency = 5000 - (ascendingFrequency * 2) + SOUND counterToneFrequency, .1 + NEXT ascendingFrequency + + ' Pattern 2: Descending frequency sweep with harmonic enhancement + ' Decrease frequency from 1000Hz back to 100Hz in larger steps (-5) + FOR descendingFrequency = 1000 TO 100 STEP -5 + ' Play main descending tone + SOUND descendingFrequency, .05 + + ' Add harmonic overtone at triple frequency plus small offset + ' Creates richer, more complex sound texture + harmonicFrequency = (descendingFrequency * 3) + 10 + SOUND harmonicFrequency, .05 + NEXT descendingFrequency + +' Continuously repeat between both sound patterns +GOTO 1 diff --git a/Miscellaneous/Alarm 2.mp3 b/Miscellaneous/Alarm 2.mp3 new file mode 100644 index 0000000..c00ecf5 Binary files /dev/null and b/Miscellaneous/Alarm 2.mp3 differ diff --git a/Miscellaneous/Mouse driver/index.html b/Miscellaneous/Mouse driver/index.html index 6f5af43..3e67a5a 100644 --- a/Miscellaneous/Mouse driver/index.html +++ b/Miscellaneous/Mouse driver/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Mouse driver for QBasic programs @@ -210,37 +210,63 @@

Table of Contents

-
-

1. Overview

+
+

1. Overview

QBasic, a popular programming language in the DOS era, lacks native mouse support. This limitation can be a hurdle for developers looking to create interactive applications. To bridge this gap, I developed a -solution that involves a Terminate and Stay Resident (TSR) program -written in x86 assembly and a QBasic demonstration program. +workaround that allows QBasic to use mouse input. +

+
+
+ +
+

2. High-level idea

+
+

+Workaround to access mouse involves a Terminate and Stay Resident +(TSR) program written in x86 assembly. This TSR program must be +started before running QBasic program that depends on mouse. This TSR +program hooks into the system's interrupt mechanism, specifically the +timer interrupt (IRQ 0), allowing it to regularly check for mouse +activity several times per second.

+

+When this timer interrupt triggers, the TSR reads the latest mouse's +horizontal and vertical movements and button states using mouse +interrupts. This data is then stored in a dedicated memory location — +a data table within the TSR's memory space. The TSR uses interrupt 79h +as a pointer to this data table, making it accessible to other +programs, including the QBasic application. +

-The solution comprises two main components: +While QBasic originally is not able to read mouse, it is able to read +(and write) arbitrary location in system RAM. The QBasic demonstration +program begins by retrieving the address of the TSR mouse data table +from the interrupt vector table using interrupt 79h. By checking a +predefined magic number (1983) in the data table, the program confirms +that the mouse driver is loaded. Once verified, the QBasic program +continuously reads mouse data from this shared memory location, while +TSR keeps updating it with latest mouse state simultaneously.

+
- -
-

1.1. Terminate and Stay Resident module

-
+
+

3. Terminate and Stay Resident module

+

A DOS TSR program that hooks into the system's interrupt mechanism to regularly read mouse input and store it in a dedicated memory @@ -258,9 +284,9 @@ Files:

-
-

1.2. QBasic demonstration program

-
+
+

4. QBasic demonstration program

+

A QBasic program that reads mouse data from the memory location populated by the TSR and demonstrates mouse movement and button @@ -269,7 +295,7 @@ clicks. -

+

screenshot.png

@@ -280,9 +306,8 @@ clicks.
-
-

Created: 2025-07-29 ti 17:34

+

Created: 2025-07-30 ke 01:30

Validate

diff --git a/Miscellaneous/Mouse driver/index.org b/Miscellaneous/Mouse driver/index.org index 338e706..e87e35a 100644 --- a/Miscellaneous/Mouse driver/index.org +++ b/Miscellaneous/Mouse driver/index.org @@ -50,6 +50,27 @@ Files: - [[file:qbext.com][qbext.com - binary COM executable for DOS]] +Here is the detailed technical specification for an in-memory table +used to exchange mouse coordinates between a TSR program and a QBasic +program. + +| Offset | Size (bytes) | Description | +|--------+--------------+-------------------------| +| 0x00 | 2 | Magic Number (1983) | +| 0x02 | 2 | Horizontal Movement (X) | +| 0x04 | 2 | Vertical Movement (Y) | +| 0x06 | 2 | Button Status | +| 0x08 | 1 | Update counter | + +- Update counter :: Signals to the QBasic program that new mouse data + is available in the shared memory table. It ensures that the QBasic + program only reads fresh data and avoids processing outdated or + repeated data. When the TSR updates the mouse data, it increments + this flag by 1 to signal the QBasic program that new data is + available. QBasic can compare this number against last retrieved + value. If value has been increased, then there had been update + meanwhile. + * QBasic demonstration program A QBasic program that reads mouse data from the memory location @@ -62,3 +83,8 @@ clicks. [[file:mousedrv.bas][file:screenshot.png]] [[file:mousedrv.bas][mousedrv.bas - source code]] + +Here are more practical examples where this mouse driver is being +used: Within [[https://www3.svjatoslav.eu/projects/qbasicapps/3D%20GFX/Space/index.html][Space themed 3D graphics]], see: +- Galaxy explorer +- Universe explorer diff --git a/Miscellaneous/alarm 1.bas b/Miscellaneous/alarm 1.bas deleted file mode 100755 index 5e973a0..0000000 --- a/Miscellaneous/alarm 1.bas +++ /dev/null @@ -1,57 +0,0 @@ -' Program to play sound that resembles security alarm. -' This program is free software: released under Creative Commons Zero (CC0) license -' by Svjatoslav Agejenko. -' Email: svjatoslav@svjatoslav.eu -' Homepage: http://www.svjatoslav.eu -' -' Changelog: -' ?, Initial version -' 2024 - 2025, Enhanced program readability - -SCREEN 1 -CLS - -' Initialize main frequency control variable -' This will create the oscillating siren effect by increasing/decreasing value -currentFrequency = 40 - -StartLoop: - ' Play primary oscillating tone (main siren component) - ' Frequency sweeps up and down between thresholds - SOUND currentFrequency, .3 - - ' Add secondary fixed-frequency component (200Hz for 1 duration unit) - ' Creates layered audio effect that makes alarm more realistic - ' Duration parameter uses QBasic's time units (1 ≈ 0.05 seconds) - SOUND 200, 1 - - ' Rapidly increase frequency for ascending siren sweep - ' Jump amount (100) creates dramatic pitch jumps - currentFrequency = currentFrequency + 100 - - ' Check if we've exceeded upper frequency threshold (1000Hz) - ' If yes, switch to descending phase - IF currentFrequency > 1000 THEN GoTo DecreaseFrequency - - ' Repeat ascending sweep until reaching maximum threshold - GOTO StartLoop - -DecreaseFrequency: - ' Continue playing oscillating tone during descending phase - SOUND currentFrequency, .3 - - ' Add high-pitched pulse (500Hz for short duration) - ' Creates distinctive alarm "warble" pattern - ' Shorter duration (.2) adds rhythmic pulsing - SOUND 500, .2 - - ' Gradually decrease frequency for descending sweep - ' Smaller decrement (10) creates slower descent than ascent - currentFrequency = currentFrequency - 10 - - ' Check if we've dropped below lower threshold (200Hz) - ' If yes, restart ascending phase to complete siren cycle - IF currentFrequency < 200 THEN GoTo StartLoop - - ' Continue descending sweep until reaching minimum threshold - GOTO DecreaseFrequency diff --git a/Miscellaneous/alarm 1.mp3 b/Miscellaneous/alarm 1.mp3 deleted file mode 100644 index eec2000..0000000 Binary files a/Miscellaneous/alarm 1.mp3 and /dev/null differ diff --git a/Miscellaneous/alarm 2.bas b/Miscellaneous/alarm 2.bas deleted file mode 100755 index 87f03c1..0000000 --- a/Miscellaneous/alarm 2.bas +++ /dev/null @@ -1,34 +0,0 @@ -' This program generates a security alarm sound effect with two alternating patterns - -DEFINT A-Z - -' Start of infinite alarm cycle -1 - - ' Pattern 1: Ascending frequency sweep with counterpoint tone - ' Increase primary frequency from 100Hz to 1000Hz in steps of 3Hz - FOR ascendingFrequency = 100 TO 1000 STEP 3 - ' Play main ascending tone - SOUND ascendingFrequency, .05 - - ' Generate counterpoint tone that decreases as primary increases - ' Formula creates complementary frequency by subtracting double current frequency - ' At 100Hz -> 5000-2*100=4800Hz; At 1000Hz -> 5000-2*1000=3000Hz - counterToneFrequency = 5000 - (ascendingFrequency * 2) - SOUND counterToneFrequency, .1 - NEXT ascendingFrequency - - ' Pattern 2: Descending frequency sweep with harmonic enhancement - ' Decrease frequency from 1000Hz back to 100Hz in larger steps (-5) - FOR descendingFrequency = 1000 TO 100 STEP -5 - ' Play main descending tone - SOUND descendingFrequency, .05 - - ' Add harmonic overtone at triple frequency plus small offset - ' Creates richer, more complex sound texture - harmonicFrequency = (descendingFrequency * 3) + 10 - SOUND harmonicFrequency, .05 - NEXT descendingFrequency - -' Continuously repeat between both sound patterns -GOTO 1 diff --git a/Miscellaneous/alarm 2.mp3 b/Miscellaneous/alarm 2.mp3 deleted file mode 100644 index c00ecf5..0000000 Binary files a/Miscellaneous/alarm 2.mp3 and /dev/null differ diff --git a/index.org b/index.org index 6995bad..fda7e27 100644 --- a/index.org +++ b/index.org @@ -247,8 +247,7 @@ filled with colors that alternate to create a checkerboard pattern.
#+end_export - -[[file:3D%20GFX/3D%20land.bas][3D land.bas]] +Download source code: [[file:3D%20GFX/3D%20land.bas][3D land.bas]] #+INCLUDE: "3D GFX/3D land.bas" src basic-qb45 @@ -475,6 +474,10 @@ patterns and trends in lottery numbers over time. The program reads data from a text file and offers multiple visualization options to help users understand the data better. +Note: In the example data there are made-up numbers and there are +repetitions in example data on-purpose. Those repeating patterns +become easily detectable in visual graphs. + #+attr_html: :class responsive-img #+attr_latex: :width 1000px [[file:Math/Lottery/Lottery%20analysis.bas][file:Math/Lottery/screenshot,%203.png]] @@ -568,6 +571,152 @@ The dithering process helps to mitigate the limitations of the #+attr_latex: :width 1000px [[file:Miscellaneous/Custom%20palette.bas][file:Miscellaneous/Custom%20palette,%203.png]] +** Alarm 1 + +This QBasic program simulates the sound of a security alarm siren. It +creates an oscillating sound effect by varying the frequency of the +primary tone, mimicking the familiar rise-and-fall pattern of a siren. + +The program works by initializing a frequency variable and playing a +primary oscillating tone alongside secondary fixed-frequency +tones. This combination produces a realistic alarm sound. The +frequency of the primary tone increases and decreases within set +thresholds, controlled by conditional checks and loops. + +#+begin_export html +
+ +
+#+end_export + +#+INCLUDE: "Miscellaneous/Alarm 1.bas" src basic-qb45 + +Download source code: [[file:Miscellaneous/Alarm,%201.bas][Alarm 1.bas]] + +** Alarm 2 + +This QBasic program generates a security alarm sound effect by +alternating between two distinct audio patterns. The first pattern +features an ascending sweep of frequencies from 100 Hz to 1000 Hz, +paired with a counterpoint tone that decreases in frequency. The +second pattern involves a descending sweep from 1000 Hz back to 100 +Hz, enhanced with a harmonic overtone to create a richer sound +texture. + +#+begin_export html +
+ +
+#+end_export + +#+INCLUDE: "Miscellaneous/Alarm 2.bas" src basic-qb45 + +Download source code: [[file:Miscellaneous/Alarm,%202.bas][Alarm 2.bas]] + +** 4D engine + +Implementation of 4 dimensional (4D) engine. It's like 3D (X, Y, Z) +but with additional extra dimension that I decided to call Q. + +*** Polygon -> Tetrahedron -> Pentatope + +- In 2D world you can have polygon. It takes 3 vertices (points) to + define. It is the minimal object in 2D world to have surface. + +- In 3D world you can have tetrahedron. It takes 4 vertices to + define. It is the minimal object in 3D world to have volume. + +- In 4D world you can have 5-cell (aka. pentatope). It takes 5 + vertices to define. It is the minimal object in 4D world to have + hypervolume (aka. 4D volume). + + +*** Planes or rotation in 3D world vs 4D world + +In 3D space, the planes of rotation correspond to rotations around the +three principal axes, and they are as follows: + +- The yz-plane, corresponding to rotation around the x-axis. +- The xz-plane, corresponding to rotation around the y-axis. +- The xy-plane, corresponding to rotation around the z-axis. + + +In 4D space, there are six possible planes of rotation, which can be +described by the combinations of two axes out of four. These are: + +- The yz-plane (same as in 3D space) +- The xz-plane (same as in 3D space) +- The xy-plane (same as in 3D space) +- The xq-plane (novel plane) +- The yq-plane (novel plane) +- The zq-plane (novel plane) + +*** Representing higher-dimensional objects through lower-dimensional slices + +The concept of representing higher-dimensional objects through +lower-dimensional slices involves taking cross-sections along one +dimension and viewing the resulting shapes. + +Here’s how it applies to both 3D to 2D and 4D to 3D representations: + +- *Representing a 3D Shape in 2D*: + - A 3D object can be represented as a series of 2D slices by taking + cross-sections along one axis (e.g., the z-axis). Each slice is a + flat, 2D shape that corresponds to the intersection of the 3D + object with a plane at a particular position along that axis. + - By stacking these 2D slices together in sequence, you can + reconstruct the 3D object. This method is akin to how CT scans + create images of the inside of a body by combining multiple + cross-sectional X-ray images. + +- *Representing a 4D Object in 3D*: + - Similarly, a 4D object can be represented in 3D space by taking + cross-sections along the fourth dimension. Each cross-section is a + 3D shape that represents the intersection of the 4D object with a + hyperplane at a particular position along the fourth axis (e.g., + Q-axis). + - By viewing these 3D slices in sequence, you can form an idea of + the structure and shape of the 4D object. This process allows us + to visualize a 4D object by observing how the 3D cross-sections + change over the fourth dimension. + +In both cases, the method of "slicing" allows us to understand and +visualize objects in dimensions that we cannot directly perceive, by +breaking them down into more manageable and comprehensible +lower-dimensional pieces. + +*** Implementation + +Current 4D engine renders single pentatope. Each pentatope vertex is +defined by 4 coordinates within 4D space:X, Y, Z, Q. + +You can rotate pentatope around any plane in 4D space (all 6 are +supported). Also you as a viewer can move around any axis in 4D space +(all 4 are supported). + +4D pentatope is shown on a screen as a series of 3D slices with +varying brightness along the new Q axis. + +Wireframe rendering is quite useful in this case because it allows to +see multiple overlayed 3D shapes at the same time. + +#+attr_html: :class responsive-img +#+attr_latex: :width 1000px +[[file:Miscellaneous/4D%20engine.bas][file:Miscellaneous/4D%20engine.png]] + +It is interesting how 3D slices of 4D pentatope stay as familiar +tetrahedrons while you rotate the shape along familiar X,Y,Z axis. But +shape starts changing in weird ways when you start rotating it along +novel planes of 4D space. + +Download source code: [[file:Miscellaneous/4D%20engine.bas][4D engine.bas]] + * Download ** Getting the source code