From 132dc1a5e74fb5e59e107717f489d7cc47aad951 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Wed, 11 Sep 2024 17:49:43 +0300 Subject: [PATCH] Using AI to improve code readability --- .../3D/KHK Intellektika 2004 demo/KHKDEMO.BAS | 473 +++++++++--------- .../KHK Intellektika 2004 demo/khkdemo5.BAS | 219 ++++---- .../KHK Intellektika 2004 demo/khkdemo4.BAS | 35 +- 3 files changed, 345 insertions(+), 382 deletions(-) diff --git a/Graphics/3D/KHK Intellektika 2004 demo/KHKDEMO.BAS b/Graphics/3D/KHK Intellektika 2004 demo/KHKDEMO.BAS index 601f9d6..77b7ff2 100755 --- a/Graphics/3D/KHK Intellektika 2004 demo/KHKDEMO.BAS +++ b/Graphics/3D/KHK Intellektika 2004 demo/KHKDEMO.BAS @@ -1,3 +1,12 @@ +' Graphics animation. +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 200?, Initial version +' 2024.09, Improved program readability using AI + DECLARE SUB playsound (a$) DECLARE SUB turnon () DECLARE SUB ellips (x!, y!, s!, v!, t!) @@ -28,10 +37,10 @@ SCREEN 7, , , 1 timerinit s = 50 -2 -s1 = SIN(timerCvalue(1) * 1.3) * .5 + 1.1 -s2 = COS(timerCvalue(1) * 1.3) * .5 + 1.1 +2 : + s1 = SIN(timerCvalue(1) * 1.3) * .5 + 1.1 + s2 = COS(timerCvalue(1) * 1.3) * .5 + 1.1 frm = frm + 1 sv1 = 5 * s1 @@ -42,7 +51,6 @@ sh1 = 2 * s2 sh2 = 1.4 hp = SIN(timerCvalue(1)) * .7 - mo timerCvalue(2), timerCvalue(3), timerCvalue(4), timerCvalue(0), 0 ellips 100, timerCvalue(6), timerCvalue(7) + 4, 14, .5 @@ -54,6 +62,7 @@ prn timerCvalue(8), 130, "Infotehno-", 2, 0 prn timerCvalue(8), 150, " loogia", 2, 0 timerprocess + LOCATE 1, 1 'PRINT timerCtime(0) IF timerCtime(0) > 26 THEN CHAIN "ray.bas" @@ -63,290 +72,266 @@ GOTO 2 SYSTEM SUB ellips (x, y, s, v, t) - -IF x > 0 THEN -IF y > 0 THEN - -CIRCLE (x, y), s, v, , , t -PAINT (x, y), v - -END IF -END IF - + ' Draws an ellipse if the coordinates are positive + IF x > 0 THEN + IF y > 0 THEN + CIRCLE (x, y), s, v, , , t + PAINT (x, y), v + END IF + END IF END SUB SUB mo (x, y, an, s, w) -depth = depth + 1 -IF s < .2 THEN GOTO 1 - -IF depth / 2 = depth \ 2 THEN c = 1 ELSE c = 3 - -CIRCLE (x, y), s, c -PAINT (x, y), c - -IF w <> 1 THEN -x1 = SIN(an) * s * 2.5 + x -y1 = COS(an) * s * 2.5 + y -IF w = 3 THEN ns = s / sv2 ELSE ns = s / sv1 -mo x1, y1, an + vp, ns, 3 -END IF - -IF w <> 2 THEN -x1 = SIN(an - pi / 2) * s * 2.5 + x -y1 = COS(an - pi / 2) * s * 2.5 + y -IF w = 4 THEN ns = s / sh2 ELSE ns = s / sh1 -mo x1, y1, an + hp, ns, 4 -END IF - -IF w <> 3 THEN -x1 = SIN(an - pi) * s * 2.5 + x -y1 = COS(an - pi) * s * 2.5 + y -IF w = 1 THEN ns = s / sv2 ELSE ns = s / sv1 -mo x1, y1, an + vp, ns, 1 -END IF - -IF w <> 4 THEN -x1 = SIN(an - pi * 1.5) * s * 2.5 + x -y1 = COS(an - pi * 1.5) * s * 2.5 + y -IF w = 2 THEN ns = s / sh2 ELSE ns = s / sh1 -mo x1, y1, an + hp, ns, 2 -END IF - -1 -depth = depth - 1 -END SUB + ' Recursive function to draw a shape with rotating and scaling properties + depth = depth + 1 + IF s < .2 THEN GOTO 1 -SUB playsound (a$) -REM SHELL "c:\progra~1\winamp\winamp.exe " + a$ -SCREEN 0 -SCREEN 7, , , 1 + IF depth / 2 = depth \ 2 THEN c = 1 ELSE c = 3 -END SUB + CIRCLE (x, y), s, c + PAINT (x, y), c -SUB prn (x, y, msg$, siz, col1) -IF x < 0 THEN GOTO prn1 -IF x > 319 THEN GOTO prn1 + IF w <> 1 THEN + x1 = SIN(an) * s * 2.5 + x + y1 = COS(an) * s * 2.5 + y + IF w = 3 THEN ns = s / sv2 ELSE ns = s / sv1 + mo x1, y1, an + vp, ns, 3 + END IF -DIM bck(10000) + IF w <> 2 THEN + x1 = SIN(an - pi / 2) * s * 2.5 + x + y1 = COS(an - pi / 2) * s * 2.5 + y + IF w = 4 THEN ns = s / sh2 ELSE ns = s / sh1 + mo x1, y1, an + hp, ns, 4 + END IF -GET (0, 0)-(100, 7), bck -LOCATE 1, 1 -PRINT msg$ - -col = col1 - -FOR x1 = 0 TO LEN(msg$) * 8 - 1 -FOR y1 = 0 TO 7 - IF POINT(x1, y1) > 0 THEN - rx = x1 * siz + x - ry = y1 * siz + y - IF col1 > 100 THEN col = RND * 4 + 10 - IF col1 > 200 THEN - LINE (rx, ry)-(rx + siz - 1, ry + siz - 1), col, B - ELSE - LINE (rx, ry)-(rx + siz - 1, ry + siz - 1), col, BF + IF w <> 3 THEN + x1 = SIN(an - pi) * s * 2.5 + x + y1 = COS(an - pi) * s * 2.5 + y + IF w = 1 THEN ns = s / sv2 ELSE ns = s / sv1 + mo x1, y1, an + vp, ns, 1 END IF -' LINE (rx, ry)-(rx + siz - 1, ry + siz - 1), col, BF - END IF -NEXT y1 -NEXT x1 + IF w <> 4 THEN + x1 = SIN(an - pi * 1.5) * s * 2.5 + x + y1 = COS(an - pi * 1.5) * s * 2.5 + y + IF w = 2 THEN ns = s / sh2 ELSE ns = s / sh1 + mo x1, y1, an + hp, ns, 2 + END IF + +1 : + depth = depth - 1 +END SUB -PUT (0, 0), bck, PSET +SUB prn (x, y, msg$, siz, col1) + ' Prints text with specified size and color at given coordinates + IF x < 0 THEN GOTO prn1 + IF x > 319 THEN GOTO prn1 + + DIM bck(10000) + + GET (0, 0)-(100, 7), bck + LOCATE 1, 1 + PRINT msg$ + + col = col1 + + FOR x1 = 0 TO LEN(msg$) * 8 - 1 + FOR y1 = 0 TO 7 + IF POINT(x1, y1) > 0 THEN + rx = x1 * siz + x + ry = y1 * siz + y + IF col1 > 100 THEN col = RND * 4 + 10 + IF col1 > 200 THEN + LINE (rx, ry)-(rx + siz - 1, ry + siz - 1), col, B + ELSE + LINE (rx, ry)-(rx + siz - 1, ry + siz - 1), col, BF + END IF + END IF + NEXT y1 + NEXT x1 + + PUT (0, 0), bck, PSET prn1: END SUB SUB timerAdd (element, time, value) - -FOR a = 0 TO 100 - IF (timerTime(element, a) = 0) AND (timerValue(element, a) = 0) THEN GOTO timer3 -NEXT a + ' Adds a new timer event for a specific element at a given time with the specified value + FOR a = 0 TO 100 + IF (timerTime(element, a) = 0) AND (timerValue(element, a) = 0) THEN GOTO timer3 + NEXT a timer3: -timerTime(element, a) = time -timerValue(element, a) = value - -END SUB - -SUB timerdisp -LOCATE 1, 1 - -FOR a = 0 TO 10 - PRINT timerCplace(a), timerCtime(a), timerCvalue(a) -NEXT a - + timerTime(element, a) = time + timerValue(element, a) = value END SUB SUB timerinit -timerLast = TIMER - -paus = 24 - -' stuff size -timerAdd 0, 0, 50 -timerAdd 0, 7, 10 -timerAdd 0, 20, 10 -timerAdd 0, 24, 0 -timerAdd 0, 1000, 0 + ' Initializes timers with predefined events and values + timerLast = TIMER + paus = 24 -' stuff speed -timerAdd 1, 0, .1 -timerAdd 1, 1000, 1000 + ' stuff size + timerAdd 0, 0, 50 + timerAdd 0, 7, 10 + timerAdd 0, 20, 10 + timerAdd 0, 24, 0 + timerAdd 0, 1000, 0 -' stuff X & Y -timerAdd 2, 0, 160 -timerAdd 3, 0, 100 + ' stuff speed + timerAdd 1, 0, .1 + timerAdd 1, 1000, 1000 -timerAdd 2, 5, 160 -timerAdd 3, 5, 100 + ' stuff X & Y + timerAdd 2, 0, 160 + timerAdd 3, 0, 100 -timerAdd 2, 9, 280 -timerAdd 3, 9, 160 + timerAdd 2, 5, 160 + timerAdd 3, 5, 100 -timerAdd 2, 10, 280 -timerAdd 3, 10, 160 + timerAdd 2, 9, 280 + timerAdd 3, 9, 160 -timerAdd 2, 20, 40 -timerAdd 3, 20, 160 + timerAdd 2, 10, 280 + timerAdd 3, 10, 160 -timerAdd 2, 1000, 40 -timerAdd 3, 1000, 160 + timerAdd 2, 20, 40 + timerAdd 3, 20, 160 -' stuff rotations -timerAdd 4, 0, .1 -timerAdd 4, 10, .1 -timerAdd 4, 22, 18 -timerAdd 4, 2000, 10000 + timerAdd 2, 1000, 40 + timerAdd 3, 1000, 160 -' KHK message X + ' stuff rotations + timerAdd 4, 0, .1 + timerAdd 4, 10, .1 + timerAdd 4, 22, 18 + timerAdd 4, 2000, 10000 -timerAdd 5, 0, -1 -timerAdd 5, 5, -1 -timerAdd 5, 9, 50 -timerAdd 5, 10, 30 -timerAdd 5, paus, 30 -timerAdd 5, paus + 2, 321 + ' KHK message X -' Ellips Y & radius -timerAdd 6, 0, -1 -timerAdd 6, 4, -1 -timerAdd 6, 10, 30 -timerAdd 6, 1000, 50 + timerAdd 5, 0, -1 + timerAdd 5, 5, -1 + timerAdd 5, 9, 50 + timerAdd 5, 10, 30 + timerAdd 5, paus, 30 + timerAdd 5, paus + 2, 321 -timerAdd 7, 0, 1 -timerAdd 7, 6, 1 -timerAdd 7, 12, 130 + ' Ellips Y & radius + timerAdd 6, 0, -1 + timerAdd 6, 4, -1 + timerAdd 6, 10, 30 + timerAdd 6, 1000, 50 -timerAdd 7, paus, 130 -timerAdd 7, paus + 2, 1 + timerAdd 7, 0, 1 + timerAdd 7, 6, 1 + timerAdd 7, 12, 130 -' "Infotehnoloogia" message - -timerAdd 8, 0, 320 -timerAdd 8, 11, 320 -timerAdd 8, 20, 100 -timerAdd 8, paus, 100 -timerAdd 8, paus + 1, -1 + timerAdd 7, paus, 130 + timerAdd 7, paus + 2, 1 + ' "Infotehnoloogia" message + timerAdd 8, 0, 320 + timerAdd 8, 11, 320 + timerAdd 8, 20, 100 + timerAdd 8, paus, 100 + timerAdd 8, paus + 1, -1 END SUB SUB timerprocess - -timerCurrent = TIMER -timerDiff = timerCurrent - timerLast -timerLast = timerCurrent - -FOR a = 0 TO 50 - ctim = timerCtime(a) + timerDiff - Cplace = timerCplace(a) + ' Processes timers to update their current values based on elapsed time + timerCurrent = TIMER + timerDiff = timerCurrent - timerLast + timerLast = timerCurrent + + FOR a = 0 TO 50 + ctim = timerCtime(a) + timerDiff + Cplace = timerCplace(a) timer2: - IF timerTime(a, Cplace + 1) = -1 THEN - ctim = 0 - Cplace = 0 - END IF - IF timerTime(a, Cplace + 1) < ctim THEN - IF timerTime(a, Cplace + 1) = 0 THEN - timerCvalue(a) = timerValue(a, Cplace) - GOTO timer1: - END IF - Cplace = Cplace + 1 - GOTO timer2 - END IF - - v1 = timerValue(a, Cplace) - t1 = timerTime(a, Cplace) - v2 = timerValue(a, Cplace + 1) - t2 = timerTime(a, Cplace + 1) - - IF v1 = v2 THEN - timerCvalue(a) = v1 - ELSE - Tdiff1 = t2 - t1 - Tdiff2 = ctim - t1 - Vdiff = v2 - v1 - timerCvalue(a) = Tdiff2 / Tdiff1 * Vdiff + v1 - END IF + IF timerTime(a, Cplace + 1) = -1 THEN + ctim = 0 + Cplace = 0 + END IF + IF timerTime(a, Cplace + 1) < ctim THEN + IF timerTime(a, Cplace + 1) = 0 THEN + timerCvalue(a) = timerValue(a, Cplace) + GOTO timer1: + END IF + Cplace = Cplace + 1 + GOTO timer2 + END IF + + v1 = timerValue(a, Cplace) + t1 = timerTime(a, Cplace) + v2 = timerValue(a, Cplace + 1) + t2 = timerTime(a, Cplace + 1) + + IF v1 = v2 THEN + timerCvalue(a) = v1 + ELSE + Tdiff1 = t2 - t1 + Tdiff2 = ctim - t1 + Vdiff = v2 - v1 + timerCvalue(a) = Tdiff2 / Tdiff1 * Vdiff + v1 + END IF timer1: - timerCplace(a) = Cplace - timerCtime(a) = ctim -NEXT a - + timerCplace(a) = Cplace + timerCtime(a) = ctim + NEXT a END SUB SUB turnon -'a$ = INPUT$(1) -playsound "marine.mp3" - -SCREEN 7, , , 1 - -FOR x = 0 TO 160 STEP 15 - - LINE (160 - x - 5, 90 - 5)-(160 + x + 5, 110 + 5), 1, BF - LINE (160 - x - 3, 90 - 3)-(160 + x + 3, 110 + 3), 3, BF - LINE (160 - x, 90)-(160 + x, 110), 15, BF - - PCOPY 0, 1 - CLS - SOUND 0, .5 -NEXT x - -FOR y = 10 TO 100 STEP 15 - CLS - - LINE (160 - x - 5, 90 - y - 5)-(160 + x + 5, 110 + y + 5), 1, BF - LINE (160 - x - 3, 90 - y - 3)-(160 + x + 3, 110 + y + 3), 3, BF - LINE (160 - x, 90 - y)-(160 + x, 110 + y), 15, BF - - PCOPY 0, 1 - SOUND 0, .5 -NEXT y - -FOR a = 1 TO 25 - prn RND * 250, RND * 180, STR$(INT(RND * 2)), 3, 0 - PCOPY 0, 1 - SOUND 0, 1 -NEXT a - -DIM buf(1 TO 1000) -FOR b = 1 TO 30 -FOR a = 0 TO 195 - t = ABS(100 - a) - - IF RND * 50 < t THEN - GET (1, a)-(318, a + 1), buf - IF a > 100 THEN - PUT (0, a), buf, PSET - ELSE - PUT (2, a), buf, PSET - END IF - END IF -NEXT a -PCOPY 0, 1 -'SOUND 0, 1 -NEXT b - - + ' Initializes the program by playing a sound and displaying an animation + SCREEN 0 + SCREEN 7, , , 1 + + + SCREEN 7, , , 1 + + FOR x = 0 TO 160 STEP 15 + LINE (160 - x - 5, 90 - 5)-(160 + x + 5, 110 + 5), 1, BF + LINE (160 - x - 3, 90 - 3)-(160 + x + 3, 110 + 3), 3, BF + LINE (160 - x, 90)-(160 + x, 110), 15, BF + + PCOPY 0, 1 + CLS + SOUND 0, .5 + NEXT x + + FOR y = 10 TO 100 STEP 15 + CLS + + LINE (160 - x - 5, 90 - y - 5)-(160 + x + 5, 110 + y + 5), 1, BF + LINE (160 - x - 3, 90 - y - 3)-(160 + x + 3, 110 + y + 3), 3, BF + LINE (160 - x, 90 - y)-(160 + x, 110 + y), 15, BF + + PCOPY 0, 1 + SOUND 0, .5 + NEXT y + + FOR a = 1 TO 25 + prn RND * 250, RND * 180, STR$(INT(RND * 2)), 3, 0 + PCOPY 0, 1 + SOUND 0, 1 + NEXT a + + DIM buf(1 TO 1000) + FOR b = 1 TO 30 + FOR a = 0 TO 195 + t = ABS(100 - a) + + IF RND * 50 < t THEN + GET (1, a)-(318, a + 1), buf + IF a > 100 THEN + PUT (0, a), buf, PSET + ELSE + PUT (2, a), buf, PSET + END IF + END IF + NEXT a + PCOPY 0, 1 + 'SOUND 0, 1 + NEXT b END SUB diff --git a/Graphics/3D/KHK Intellektika 2004 demo/khkdemo5.BAS b/Graphics/3D/KHK Intellektika 2004 demo/khkdemo5.BAS index 8f8b250..dd8de8c 100755 --- a/Graphics/3D/KHK Intellektika 2004 demo/khkdemo5.BAS +++ b/Graphics/3D/KHK Intellektika 2004 demo/khkdemo5.BAS @@ -1,15 +1,19 @@ -' 3D Maze explorer -' made by Svjatoslav Agejenko -' in 2003.12 -' H-Page: svjatoslav.eu -' E-Mail: svjatoslav@svjatoslav.eu - -DECLARE SUB startext () +DECLARE FUNCTION getWord& (addr!) +DECLARE FUNCTION getByte! (addr!) +' Render animated 3D maze. +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 2002, Initial version +' 2024.09, Improved program readability using AI + + +DECLARE SUB startText () DECLARE SUB control () -DECLARE SUB putbyte (addr!, dat!) -DECLARE SUB putword (addr!, dat!) -DECLARE FUNCTION getword! (addr!) -DECLARE FUNCTION getbyte! (addr!) +DECLARE SUB putByte (addr!, dat!) +DECLARE SUB putWord (addr!, dat!) DECLARE SUB start () DECLARE SUB animate () @@ -42,7 +46,6 @@ np = 0 start - cx = 0 cy = 0 cz = 0 @@ -52,6 +55,7 @@ px(1) = 0 py(1) = 0 pz(1) = 0 +' Main loop 1 frm = frm + 1 myx = SIN(frm / 30) * 100 @@ -60,35 +64,29 @@ myy = SIN(frm / 300) an1 = SIN(frm / 60) an2 = SIN(frm / 36) / 3 - np = np + 1 px(np) = cx py(np) = cy pz(np) = cz - - nl = nl + 1 l1(nl) = np l2(nl) = np - 1 lc(nl) = INT(RND * 15) + 1 -'lc(nl) = ABS(cx / 20) - - +' lc(nl) = ABS(cx / 20) va = INT(RND * 3) SELECT CASE va CASE 0 - cx = RND * 500 - 250 + cx = RND * 500 - 250 CASE 1 - cy = RND * 100 - 50 + cy = RND * 100 - 50 CASE 2 - cz = RND * 500 - 250 + cz = RND * 500 - 250 END SELECT - -'control +' control animate PCOPY 0, 1 @@ -96,13 +94,13 @@ CLS IF frm > 1200 THEN GOTO 200 GOTO 1 + 200 CHAIN "khkdemo6.bas" SUB animate - s1 = SIN(an1) s2 = SIN(an2) s3 = SIN(an3) @@ -111,79 +109,72 @@ c1 = COS(an1) c2 = COS(an2) c3 = COS(an3) - - +' Rotate and project points FOR a = 1 TO np - x = px(a) - myx - y = py(a) - myy - z = pz(a) - myz - - - x1 = x * c1 + z * s1 - z1 = z * c1 - x * s1 - - y1 = y * c2 + z1 * s2 - z2 = z1 * c2 - y * s2 - - -' z2 = z2 + 10 - - IF z2 > 3 THEN - rpe(a) = 1 - rpx(a) = x1 / z2 * 130 + 160 - rpy(a) = y1 / z2 * 130 + 100 - ELSE - rpe(a) = 0 - END IF - + x = px(a) - myx + y = py(a) - myy + z = pz(a) - myz + + ' First rotation around Y axis + x1 = x * c1 + z * s1 + z1 = z * c1 - x * s1 + + ' Second rotation around X axis + y1 = y * c2 + z1 * s2 + z2 = z1 * c2 - y * s2 + + ' Check if point is behind the viewer + IF z2 > 3 THEN + rpe(a) = 1 + rpx(a) = x1 / z2 * 130 + 160 + rpy(a) = y1 / z2 * 130 + 100 + ELSE + rpe(a) = 0 + END IF NEXT a - +' Draw lines between visible points FOR a = 1 TO nl - p1 = l1(a) - p2 = l2(a) - IF (rpe(p1) = 1) AND (rpe(p2) = 1) THEN LINE (rpx(p1), rpy(p1))-(rpx(p2), rpy(p2)), lc(a) + p1 = l1(a) + p2 = l2(a) + IF (rpe(p1) = 1) AND (rpe(p2) = 1) THEN LINE (rpx(p1), rpy(p1))-(rpx(p2), rpy(p2)), lc(a) NEXT a - END SUB SUB control - -IF getbyte(8) <> 0 THEN - putbyte 8, 0 - xp = getword(2) - putword 2, 0 - yp = getword(4) - putword 4, 0 - butt = getword(6) - putword 6, 0 - buttL = 0 - buttR = 0 - IF butt = 1 THEN buttL = 1 - IF butt = 2 THEN buttR = 1 - IF butt = 3 THEN buttL = 1: buttR = 1 - - - IF buttR = 1 THEN - IF buttL = 1 THEN - myxs = myxs + SIN(an1) * yp / 4 - myzs = myzs - COS(an1) * yp / 4 - GOTO 3 - END IF - myys = myys + yp / 4 +IF getByte(8) <> 0 THEN + putByte 8, 0 + xp = getWord(2) + putWord 2, 0 + yp = getWord(4) + putWord 4, 0 + butt = getWord(6) + putWord 6, 0 + buttL = 0 + buttR = 0 + IF butt = 1 THEN buttL = 1 + IF butt = 2 THEN buttR = 1 + IF butt = 3 THEN buttL = 1: buttR = 1 + + ' Handle mouse movement + IF buttR = 1 THEN + IF buttL = 1 THEN + myxs = myxs + SIN(an1) * yp / 4 + myzs = myzs - COS(an1) * yp / 4 + GOTO 3 + END IF + myys = myys + yp / 4 3 - yp = 0 - END IF + yp = 0 + END IF END IF - - - +' Limit movement to maxmove IF xp < -maxmove THEN xp = -maxmove IF xp > maxmove THEN xp = maxmove an1 = an1 - xp / 150 @@ -192,10 +183,9 @@ IF yp < -maxmove THEN yp = -maxmove IF yp > maxmove THEN yp = maxmove an2 = an2 - yp / 150 - - a$ = INKEY$ +' Handle keyboard input IF a$ = "a" THEN myxs = myxs - COS(an1): myzs = myzs - SIN(an1) IF a$ = "d" THEN myxs = myxs + COS(an1): myzs = myzs + SIN(an1) IF a$ = "w" THEN myxs = myxs - SIN(an1): myzs = myzs + COS(an1) @@ -212,46 +202,42 @@ myy = myy + myys END SUB -FUNCTION getbyte (addr) -getbyte = PEEK(extADDR + addr) +FUNCTION getByte (addr) + getByte = PEEK(extADDR + addr) END FUNCTION -FUNCTION getword (addr) -a = PEEK(extADDR + addr) -b = PEEK(extADDR + addr + 1) - +FUNCTION getWord& (addr) + a = PEEK(extADDR + addr) + b = PEEK(extADDR + addr + 1) -c$ = HEX$(a) -IF LEN(c$) = 1 THEN c$ = "0" + c$ -IF LEN(c$) = 0 THEN c$ = "00" + c$ = HEX$(a) + IF LEN(c$) = 1 THEN c$ = "0" + c$ + IF LEN(c$) = 0 THEN c$ = "00" + c = VAL("&H" + HEX$(b) + c$) -c = VAL("&H" + HEX$(b) + c$) - -getword = c + getWord = c END FUNCTION -SUB mousedemo - - +SUB mouseDemo cx = 150 cy = 100 maxmove = 50 + +' Main loop 100 frm = frm + 1 - LOCATE 1, 1 PRINT cx, cy PRINT frm CIRCLE (cx, cy), 10, 0 -xp = getword(2) -putword 2, 0 -yp = getword(4) -putword 4, 0 - +xp = getWord(2) +putWord 2, 0 +yp = getWord(4) +putWord 4, 0 IF xp < -maxmove THEN xp = -maxmove IF xp > maxmove THEN xp = maxmove @@ -261,23 +247,18 @@ IF yp < -maxmove THEN yp = -maxmove IF yp > maxmove THEN yp = maxmove cy = cy + yp - CIRCLE (cx, cy), 10, 10 - - SOUND 0, .05 GOTO 100 - END SUB -SUB putbyte (addr, dat) - -POKE (extADDR + addr), dat +SUB putByte (addr, dat) + POKE (extADDR + addr), dat END SUB -SUB putword (addr, dat) +SUB putWord (addr, dat) b$ = HEX$(dat) @@ -287,15 +268,13 @@ IF LEN(b$) < 4 THEN b$ = "0" + b$: GOTO 2 n1 = VAL("&H" + LEFT$(b$, 2)) n2 = VAL("&H" + RIGHT$(b$, 2)) - POKE (extADDR + addr), n2 POKE (extADDR + addr + 1), n1 END SUB SUB start -' startext - + ' startext SCREEN 7, , , 1 @@ -303,7 +282,7 @@ maxmove = 50 END SUB -SUB startext +SUB startText DEF SEG = 0 ' read first from interrupt table @@ -319,10 +298,10 @@ PRINT "relative address is:"; extADDR DEF SEG = extSEG -IF getword(0) <> 1983 THEN - PRINT "FATAL ERROR: you must load" - PRINT "QBasic extension TSR first!" - SYSTEM +IF getWord(0) <> 1983 THEN + PRINT "FATAL ERROR: you must load" + PRINT "QBasic extension TSR first!" + SYSTEM END IF END SUB diff --git a/Graphics/Presentations/KHK Intellektika 2004 demo/khkdemo4.BAS b/Graphics/Presentations/KHK Intellektika 2004 demo/khkdemo4.BAS index ec82d00..4842b71 100755 --- a/Graphics/Presentations/KHK Intellektika 2004 demo/khkdemo4.BAS +++ b/Graphics/Presentations/KHK Intellektika 2004 demo/khkdemo4.BAS @@ -1,20 +1,20 @@ -DECLARE SUB ga (x!, y!, s!) -DIM SHARED colr ' this variable holds fractal color - ' and because it is 'SHARED' it is accessible - ' from within sub module. +DECLARE SUB drawFractal (x!, y!, s!) +DIM SHARED fractalColor ' this variable holds fractal color + ' and because it is 'SHARED' it is accessible + ' from within sub module. SCREEN 12 -colr = 10 ' display single fractel -ga 320, 240, 127 +fractalColor = 10 ' display single fractal +drawFractal 320, 240, 127 FOR a = 1 TO 50 SOUND 0, 1 NEXT a CLS -FOR a = 1 TO 128 STEP 5 ' display fractal serie - colr = RND * 7 + 7 - ga 320, 240, a +FOR a = 1 TO 128 STEP 5 ' display fractal series + fractalColor = RND * 7 + 7 + drawFractal 320, 240, a NEXT a FOR a = 1 TO 50 @@ -23,13 +23,12 @@ NEXT a CHAIN "khkdemo5.bas" -SUB ga (x, y, s) -IF s >= 1 THEN - LINE (x - s, y - s)-(x + s, y + s), colr, B - ga x - s, y - s, s / 2.3 ' each fractel sub element is 2.3 times smaller - ga x + s, y - s, s / 2.3 ' than previous. - ga x + s, y + s, s / 2.3 - ga x - s, y + s, s / 2.3 -END IF +SUB drawFractal (x, y, s) + IF s >= 1 THEN + LINE (x - s, y - s)-(x + s, y + s), fractalColor, B + drawFractal x - s, y - s, s / 2.3 ' each fractal sub element is 2.3 times smaller + drawFractal x + s, y - s, s / 2.3 ' than previous. + drawFractal x + s, y + s, s / 2.3 + drawFractal x - s, y + s, s / 2.3 + END IF END SUB - -- 2.20.1