' in 2003.12\r
' H-Page: svjatoslav.eu\r
' E-Mail: svjatoslav@svjatoslav.eu\r
- \r
+\r
DECLARE SUB prn (x!, y!, a$)\r
DECLARE SUB pch (x!, y!, a$)\r
DECLARE SUB readfnt ()\r
myy = 0\r
myz = -100\r
\r
-\r
-\r
start\r
\r
nait3d\r
\r
SUB getcor\r
\r
+' Define the corners of a cube\r
xn(nump + 1) = -150\r
yn(nump + 1) = -125\r
zn(nump + 1) = -200\r
yn(nump + 4) = 125\r
zn(nump + 4) = -200\r
\r
-\r
xn(nump + 5) = -150\r
yn(nump + 5) = -125\r
zn(nump + 5) = 200\r
yn(nump + 8) = 125\r
zn(nump + 8) = 200\r
\r
-\r
+' Define the lines connecting the corners\r
point1(numl + 1) = nump + 1\r
point2(numl + 1) = nump + 2\r
\r
nump = nump + 8\r
numl = numl + 12\r
\r
-\r
-\r
-\r
+' Define the corners of rectangle\r
xn(nump + 1) = -150\r
yn(nump + 1) = -125 + 201\r
zn(nump + 1) = 0\r
yn(nump + 4) = -125\r
zn(nump + 4) = 0\r
\r
+' Define the lines connecting these corners\r
point1(numl + 1) = nump + 1\r
point2(numl + 1) = nump + 2\r
\r
nump = nump + 4\r
numl = numl + 4\r
\r
-\r
-\r
prn 0, 0, "three dimensional "\r
prn 0, -3, "text example"\r
prn 0, -6, "etc etc etc"\r
\r
-\r
-\r
END SUB\r
\r
SUB kuus (x, y, z, s)\r
\r
+' Initialize variables\r
b = 0\r
f = .3925\r
-FOR a = 0 + f TO 6 + f STEP 6.28 / 8\r
-x1 = SIN(a) * s\r
-y1 = COS(a) * s\r
-b = b + 1\r
-\r
-xn(nump + b) = x1 + x\r
-yn(nump + b) = y\r
-zn(nump + b) = y1 + z\r
\r
+' Loop to create points of the octagon\r
+FOR a = 0 + f TO 6 + f STEP 6.28 / 8\r
+ x1 = SIN(a) * s\r
+ y1 = COS(a) * s\r
+ b = b + 1\r
+\r
+ ' Store the points in the shared arrays\r
+ xn(nump + b) = x1 + x\r
+ yn(nump + b) = y\r
+ zn(nump + b) = y1 + z\r
NEXT a\r
\r
+' Define the lines connecting these points\r
point1(numl + 1) = nump + 1\r
point2(numl + 1) = nump + 2\r
col(numl + 1) = 12\r
point2(numl + 5) = nump + 6\r
col(numl + 5) = 12\r
\r
-\r
point1(numl + 6) = nump + 6\r
point2(numl + 6) = nump + 7\r
col(numl + 6) = 12\r
\r
nump = nump + b\r
numl = numl + 8\r
+\r
'LOCATE 1, 1\r
'PRINT b\r
\r
-\r
-\r
-\r
END SUB\r
\r
SUB nait3d\r
\r
+' Main loop for the 3D rendering\r
1\r
\r
myx = myx + SIN(deg1) * mye\r
myz = myz + COS(deg1) * mye\r
- \r
+\r
myx = myx + COS(deg1) * myk\r
myz = myz - SIN(deg1) * myk\r
\r
deg1 = deg1 + d1\r
Deg2 = Deg2 + d2\r
- \r
+\r
C1 = COS(deg1): S1 = SIN(deg1)\r
C2 = COS(Deg2): S2 = SIN(Deg2)\r
- \r
-FOR a = 1 TO nump\r
\r
-xo = xn(a) - myx\r
-yo = -yn(a) - myy\r
-zo = zn(a) - myz\r
- \r
-x1 = (xo * C1 - zo * S1)\r
-z1 = (xo * S1 + zo * C1)\r
- \r
-y1 = (yo * C2 - z1 * S2)\r
-z2 = (yo * S2 + z1 * C2)\r
- \r
-\r
-xo(a) = x(a)\r
-yo(a) = y(a)\r
-IF z2 < 20 THEN\r
-x(a) = -1\r
-ELSE\r
-x(a) = 320 + (x1 / z2 * 500)\r
-\r
-y(a) = 240 + (y1 / z2 * 500)\r
-END IF\r
+' Transform the coordinates\r
+FOR a = 1 TO nump\r
+ xo = xn(a) - myx\r
+ yo = -yn(a) - myy\r
+ zo = zn(a) - myz\r
+\r
+ x1 = (xo * C1 - zo * S1)\r
+ z1 = (xo * S1 + zo * C1)\r
+\r
+ y1 = (yo * C2 - z1 * S2)\r
+ z2 = (yo * S2 + z1 * C2)\r
+\r
+ ' Store the transformed coordinates\r
+ xo(a) = x(a)\r
+ yo(a) = y(a)\r
+\r
+ ' Check if the point is within the view\r
+ IF z2 < 20 THEN\r
+ x(a) = -1\r
+ ELSE\r
+ ' Apply perspective transformation\r
+ x(a) = 320 + (x1 / z2 * 500)\r
+ y(a) = 240 + (y1 / z2 * 500)\r
+ END IF\r
NEXT\r
- \r
\r
+' Draw the lines\r
FOR a = 1 TO numl\r
-p1 = point1(a)\r
-p2 = point2(a)\r
-IF xo(p1) = -1 OR xo(p2) = -1 THEN ELSE LINE (xo(p1), yo(p1))-(xo(p2), yo(p2)), 0\r
-IF x(p1) = -1 OR x(p2) = -1 THEN ELSE LINE (x(p1), y(p1))-(x(p2), y(p2)), col(a)\r
+ p1 = point1(a)\r
+ p2 = point2(a)\r
+\r
+ ' Check if the points are within the view\r
+ IF xo(p1) = -1 OR xo(p2) = -1 THEN\r
+ ' Do nothing\r
+ ELSE\r
+ ' erase line at old coordinates\r
+ LINE (xo(p1), yo(p1))-(xo(p2), yo(p2)), 0\r
+ END IF\r
+\r
+ IF x(p1) = -1 OR x(p2) = -1 THEN\r
+ ' Do nothing\r
+ ELSE\r
+ ' draw line at new coordinates\r
+ LINE (x(p1), y(p1))-(x(p2), y(p2)), col(a)\r
+ END IF\r
NEXT\r
- \r
\r
+' Handle user input\r
K$ = INKEY$\r
IF K$ <> "" THEN\r
\r
-SELECT CASE K$\r
+ SELECT CASE K$\r
\r
-CASE CHR$(0) + "P"\r
-mye = mye - 1\r
+ CASE CHR$(0) + "P"\r
+ mye = mye - 1\r
\r
-CASE CHR$(0) + "H"\r
-mye = mye + 1\r
+ CASE CHR$(0) + "H"\r
+ mye = mye + 1\r
\r
-CASE CHR$(0) + "M"\r
-myk = myk + 1\r
+ CASE CHR$(0) + "M"\r
+ myk = myk + 1\r
\r
-CASE CHR$(0) + "K"\r
-myk = myk - 1\r
+ CASE CHR$(0) + "K"\r
+ myk = myk - 1\r
\r
-CASE "+"\r
-myy = myy + 3\r
+ CASE "+"\r
+ myy = myy + 3\r
\r
-CASE "-"\r
-myy = myy - 3\r
+ CASE "-"\r
+ myy = myy - 3\r
\r
-CASE "6"\r
-d1 = d1 + .01\r
+ CASE "6"\r
+ d1 = d1 + .01\r
\r
-CASE "4"\r
-d1 = d1 - .01\r
+ CASE "4"\r
+ d1 = d1 - .01\r
\r
-CASE "8"\r
-d2 = d2 - .01\r
+ CASE "8"\r
+ d2 = d2 - .01\r
\r
-CASE "2"\r
-d2 = d2 + .01\r
+ CASE "2"\r
+ d2 = d2 + .01\r
\r
+ CASE " "\r
+ d1 = d1 / 2\r
+ d2 = d2 / 2\r
+ d3 = d3 / 2\r
+ mye = mye / 2\r
+ myk = myk / 2\r
\r
-CASE " "\r
-d1 = d1 / 2\r
-d2 = d2 / 2\r
-d3 = d3 / 2\r
-mye = mye / 2\r
-myk = myk / 2\r
+ CASE "q"\r
+ SYSTEM\r
\r
-CASE "q"\r
-SYSTEM\r
+ CASE CHR$(27)\r
+ SYSTEM\r
\r
-CASE CHR$(27)\r
-SYSTEM\r
-\r
-END SELECT\r
+ END SELECT\r
END IF\r
\r
GOTO 1\r
+\r
END SUB\r
\r
SUB pch (x, y, a$)\r
\r
-\r
+' Initialize variables\r
b = ASC(a$)\r
up = 0\r
ul = 0\r
\r
+' Loop to create points for the character\r
FOR c = 0 TO 100\r
-IF tpx(c, b) = 999 THEN GOTO 4\r
-up = up + 1\r
-xn(nump + up) = x + tpx(c, b)\r
-yn(nump + up) = y - tpy(c, b)\r
-zn(nump + up) = 0\r
+ IF tpx(c, b) = 999 THEN GOTO 4\r
+ up = up + 1\r
+ xn(nump + up) = x + tpx(c, b)\r
+ yn(nump + up) = y - tpy(c, b)\r
+ zn(nump + up) = 0\r
NEXT c\r
4\r
\r
+' Loop to define the lines for the character\r
FOR c = 0 TO 100\r
-IF tl1(c, b) = 999 THEN GOTO 5\r
-ul = ul + 1\r
-point1(numl + ul) = tl1(c, b) + nump + 1\r
-point2(numl + ul) = tl2(c, b) + nump + 1\r
-col(numl + ul) = 4\r
+ IF tl1(c, b) = 999 THEN GOTO 5\r
+ ul = ul + 1\r
+ point1(numl + ul) = tl1(c, b) + nump + 1\r
+ point2(numl + ul) = tl2(c, b) + nump + 1\r
+ col(numl + ul) = 4\r
NEXT c\r
5\r
\r
-\r
-\r
+' Update the counters\r
nump = nump + up\r
numl = numl + ul\r
\r
-\r
END SUB\r
\r
SUB porand\r
+' do floor of the 3D room\r
\r
+' Loop to create floor tiles made of hexagons and squares\r
FOR x = -100 TO 0 STEP 12.067 + .3\r
-FOR z = -100 TO 0 STEP 12.067 + .3\r
-kuus x, -125, z, 6.53\r
-ruut x + 6.033 + .15, -125, z + 6.033 + .15, 3.111 + .3\r
-NEXT z\r
+ FOR z = -100 TO 0 STEP 12.067 + .3\r
+ kuus x, -125, z, 6.53\r
+ ruut x + 6.033 + .15, -125, z + 6.033 + .15, 3.111 + .3\r
+ NEXT z\r
NEXT x\r
\r
+' Loop to create squares\r
FOR y = -100 TO 0 STEP 20.3\r
-FOR x = -100 TO 0 STEP 20.3\r
-ruut2 x, y, 200, 10\r
-NEXT x\r
+ FOR x = -100 TO 0 STEP 20.3\r
+ ruut2 x, y, 200, 10\r
+ NEXT x\r
NEXT y\r
\r
-\r
END SUB\r
\r
SUB prn (x, y, a$)\r
\r
+' Loop to print each character\r
FOR b = 1 TO LEN(a$)\r
-c$ = RIGHT$(LEFT$(a$, b), 1)\r
-pch x + b * 3, y, c$\r
+ c$ = RIGHT$(LEFT$(a$, b), 1)\r
+ pch x + b * 3, y, c$\r
NEXT b\r
+\r
END SUB\r
\r
SUB readfnt\r
+\r
+' Open the font file\r
OPEN "font.dat" FOR INPUT AS #1\r
+\r
+' Loop to read the font data\r
3\r
IF EOF(1) <> 0 THEN GOTO 2\r
LINE INPUT #1, a$\r
+\r
IF LEFT$(a$, 1) = "#" THEN\r
-chr = ASC(RIGHT$(LEFT$(a$, 3), 1))\r
-pp = 0\r
-lp = 0\r
+ chr = ASC(RIGHT$(LEFT$(a$, 3), 1))\r
+\r
+ ' Initialize counters\r
+ pp = 0\r
+ lp = 0\r
END IF\r
+\r
+' read the points for the character\r
IF LEFT$(a$, 1) = "p" THEN\r
-tpx(pp, chr) = VAL(RIGHT$(LEFT$(a$, 3), 1))\r
-tpy(pp, chr) = VAL(RIGHT$(LEFT$(a$, 5), 1))\r
-pp = pp + 1\r
+ tpx(pp, chr) = VAL(RIGHT$(LEFT$(a$, 3), 1))\r
+ tpy(pp, chr) = VAL(RIGHT$(LEFT$(a$, 5), 1))\r
+ pp = pp + 1\r
END IF\r
+\r
+' read the lines for the character\r
IF LEFT$(a$, 1) = "l" THEN\r
-tl1(lp, chr) = VAL(RIGHT$(LEFT$(a$, 3), 1))\r
-tl2(lp, chr) = VAL(RIGHT$(LEFT$(a$, 5), 1))\r
-lp = lp + 1\r
+ tl1(lp, chr) = VAL(RIGHT$(LEFT$(a$, 3), 1))\r
+ tl2(lp, chr) = VAL(RIGHT$(LEFT$(a$, 5), 1))\r
+ lp = lp + 1\r
END IF\r
\r
GOTO 3\r
+\r
+' Close the font file\r
2\r
CLOSE #1\r
\r
-\r
END SUB\r
\r
SUB ruut (x, y, z, s)\r
+\r
+' Define the corners of the rectangle\r
xn(nump + 1) = x\r
yn(nump + 1) = y\r
zn(nump + 1) = z + s\r
yn(nump + 4) = y\r
zn(nump + 4) = z\r
\r
+' Define the lines connecting these corners\r
point1(numl + 1) = nump + 1\r
point2(numl + 1) = nump + 2\r
col(numl + 1) = 10\r
point2(numl + 4) = nump + 1\r
col(numl + 4) = 10\r
\r
+' Update the counters\r
nump = nump + 4\r
numl = numl + 4\r
+\r
END SUB\r
\r
SUB ruut2 (x, y, z, s)\r
+\r
+' Define the corners of the rectangle\r
xn(nump + 1) = x - s\r
yn(nump + 1) = y - s\r
zn(nump + 1) = z\r
yn(nump + 4) = y + s\r
zn(nump + 4) = z\r
\r
+' Define the lines connecting these corners\r
point1(numl + 1) = nump + 1\r
point2(numl + 1) = nump + 2\r
col(numl + 1) = 14\r
point2(numl + 4) = nump + 1\r
col(numl + 4) = 14\r
\r
+' Update the counters\r
nump = nump + 4\r
numl = numl + 4\r
\r
END SUB\r
\r
SUB start\r
+\r
+' Initialize the screen and clear it\r
SCREEN 12\r
CLS\r
\r
+' Set the default color for all points\r
FOR a = 1 TO 4000\r
-col(a) = 15\r
+ col(a) = 15\r
NEXT a\r
\r
+' Initialize counters\r
nump = 0\r
numl = 0\r
+\r
+' Initialize font data\r
FOR a = 0 TO 255\r
-FOR b = 0 TO 10\r
-tpx(b, a) = 999\r
-tpy(b, a) = 999\r
-tl1(b, a) = 999\r
-tl2(b, a) = 999\r
-NEXT b\r
+ FOR b = 0 TO 10\r
+ tpx(b, a) = 999\r
+ tpy(b, a) = 999\r
+ tl1(b, a) = 999\r
+ tl2(b, a) = 999\r
+ NEXT b\r
NEXT a\r
\r
-\r
+' Read the font data\r
readfnt\r
+\r
+' Define the corners of the cubes\r
getcor\r
\r
END SUB\r