+++ /dev/null
-' Graphics animation.\r
-' By Svjatoslav Agejenko.\r
-' Email: svjatoslav@svjatoslav.eu\r
-' Homepage: http://www.svjatoslav.eu\r
-'\r
-' Changelog:\r
-' 200?, Initial version\r
-' 2024.09, Improved program readability using AI\r
-\r
-DECLARE SUB playsound (a$)\r
-DECLARE SUB turnon ()\r
-DECLARE SUB ellips (x!, y!, s!, v!, t!)\r
-DECLARE SUB prn (x!, y!, msg$, siz!, col1!)\r
-DECLARE SUB timerAdd (element!, time!, value!)\r
-DECLARE SUB timerdisp ()\r
-DECLARE SUB timerinit ()\r
-DECLARE SUB timerprocess ()\r
-DECLARE SUB mo (x!, y!, an!, s!, w!)\r
-DIM SHARED depth\r
-DIM SHARED pi\r
-\r
-DIM SHARED sh1, sh2, sv1, sv2, hp, vp\r
-DIM SHARED timerTime(0 TO 50, 0 TO 100)\r
-DIM SHARED timerValue(0 TO 50, 0 TO 100)\r
-\r
-DIM SHARED timerCplace(0 TO 50)\r
-DIM SHARED timerCtime(0 TO 50)\r
-DIM SHARED timerCvalue(0 TO 50)\r
-DIM SHARED timerLast\r
-\r
-\r
-pi = 3.14128\r
-\r
-turnon\r
-\r
-SCREEN 7, , , 1\r
-\r
-timerinit\r
-s = 50\r
-\r
-2 :\r
- s1 = SIN(timerCvalue(1) * 1.3) * .5 + 1.1\r
- s2 = COS(timerCvalue(1) * 1.3) * .5 + 1.1\r
-\r
-frm = frm + 1\r
-sv1 = 5 * s1\r
-sv2 = 2\r
-vp = SIN(timerCvalue(1) * 1.3)\r
-\r
-sh1 = 2 * s2\r
-sh2 = 1.4\r
-hp = SIN(timerCvalue(1)) * .7\r
-\r
-mo timerCvalue(2), timerCvalue(3), timerCvalue(4), timerCvalue(0), 0\r
-\r
-ellips 100, timerCvalue(6), timerCvalue(7) + 4, 14, .5\r
-ellips 100, timerCvalue(6), timerCvalue(7) + 2, 10, .5\r
-ellips 100, timerCvalue(6), timerCvalue(7), 0, .5\r
-prn timerCvalue(5), 10, "KHK", 7, 250\r
-\r
-prn timerCvalue(8), 130, "Infotehno-", 2, 0\r
-prn timerCvalue(8), 150, " loogia", 2, 0\r
-\r
-timerprocess\r
-\r
-LOCATE 1, 1\r
-'PRINT timerCtime(0)\r
-IF timerCtime(0) > 26 THEN CHAIN "ray.bas"\r
-PCOPY 0, 1\r
-LINE (0, 0)-(319, 199), 15, BF\r
-GOTO 2\r
-SYSTEM\r
-\r
-SUB ellips (x, y, s, v, t)\r
- ' Draws an ellipse if the coordinates are positive\r
- IF x > 0 THEN\r
- IF y > 0 THEN\r
- CIRCLE (x, y), s, v, , , t\r
- PAINT (x, y), v\r
- END IF\r
- END IF\r
-END SUB\r
-\r
-SUB mo (x, y, an, s, w)\r
- ' Recursive function to draw a shape with rotating and scaling properties\r
- depth = depth + 1\r
- IF s < .2 THEN GOTO 1\r
-\r
- IF depth / 2 = depth \ 2 THEN c = 1 ELSE c = 3\r
-\r
- CIRCLE (x, y), s, c\r
- PAINT (x, y), c\r
-\r
- IF w <> 1 THEN\r
- x1 = SIN(an) * s * 2.5 + x\r
- y1 = COS(an) * s * 2.5 + y\r
- IF w = 3 THEN ns = s / sv2 ELSE ns = s / sv1\r
- mo x1, y1, an + vp, ns, 3\r
- END IF\r
-\r
- IF w <> 2 THEN\r
- x1 = SIN(an - pi / 2) * s * 2.5 + x\r
- y1 = COS(an - pi / 2) * s * 2.5 + y\r
- IF w = 4 THEN ns = s / sh2 ELSE ns = s / sh1\r
- mo x1, y1, an + hp, ns, 4\r
- END IF\r
-\r
- IF w <> 3 THEN\r
- x1 = SIN(an - pi) * s * 2.5 + x\r
- y1 = COS(an - pi) * s * 2.5 + y\r
- IF w = 1 THEN ns = s / sv2 ELSE ns = s / sv1\r
- mo x1, y1, an + vp, ns, 1\r
- END IF\r
-\r
- IF w <> 4 THEN\r
- x1 = SIN(an - pi * 1.5) * s * 2.5 + x\r
- y1 = COS(an - pi * 1.5) * s * 2.5 + y\r
- IF w = 2 THEN ns = s / sh2 ELSE ns = s / sh1\r
- mo x1, y1, an + hp, ns, 2\r
- END IF\r
-\r
-1 :\r
- depth = depth - 1\r
-END SUB\r
-\r
-SUB prn (x, y, msg$, siz, col1)\r
- ' Prints text with specified size and color at given coordinates\r
- IF x < 0 THEN GOTO prn1\r
- IF x > 319 THEN GOTO prn1\r
-\r
- DIM bck(10000)\r
-\r
- GET (0, 0)-(100, 7), bck\r
- LOCATE 1, 1\r
- PRINT msg$\r
-\r
- col = col1\r
-\r
- FOR x1 = 0 TO LEN(msg$) * 8 - 1\r
- FOR y1 = 0 TO 7\r
- IF POINT(x1, y1) > 0 THEN\r
- rx = x1 * siz + x\r
- ry = y1 * siz + y\r
- IF col1 > 100 THEN col = RND * 4 + 10\r
- IF col1 > 200 THEN\r
- LINE (rx, ry)-(rx + siz - 1, ry + siz - 1), col, B\r
- ELSE\r
- LINE (rx, ry)-(rx + siz - 1, ry + siz - 1), col, BF\r
- END IF\r
- END IF\r
- NEXT y1\r
- NEXT x1\r
-\r
- PUT (0, 0), bck, PSET\r
-prn1:\r
-END SUB\r
-\r
-SUB timerAdd (element, time, value)\r
- ' Adds a new timer event for a specific element at a given time with the specified value\r
- FOR a = 0 TO 100\r
- IF (timerTime(element, a) = 0) AND (timerValue(element, a) = 0) THEN GOTO timer3\r
- NEXT a\r
-timer3:\r
-\r
- timerTime(element, a) = time\r
- timerValue(element, a) = value\r
-END SUB\r
-\r
-SUB timerinit\r
- ' Initializes timers with predefined events and values\r
- timerLast = TIMER\r
-\r
- paus = 24\r
-\r
- ' stuff size\r
- timerAdd 0, 0, 50\r
- timerAdd 0, 7, 10\r
- timerAdd 0, 20, 10\r
- timerAdd 0, 24, 0\r
- timerAdd 0, 1000, 0\r
-\r
- ' stuff speed\r
- timerAdd 1, 0, .1\r
- timerAdd 1, 1000, 1000\r
-\r
- ' stuff X & Y\r
- timerAdd 2, 0, 160\r
- timerAdd 3, 0, 100\r
-\r
- timerAdd 2, 5, 160\r
- timerAdd 3, 5, 100\r
-\r
- timerAdd 2, 9, 280\r
- timerAdd 3, 9, 160\r
-\r
- timerAdd 2, 10, 280\r
- timerAdd 3, 10, 160\r
-\r
- timerAdd 2, 20, 40\r
- timerAdd 3, 20, 160\r
-\r
- timerAdd 2, 1000, 40\r
- timerAdd 3, 1000, 160\r
-\r
- ' stuff rotations\r
- timerAdd 4, 0, .1\r
- timerAdd 4, 10, .1\r
- timerAdd 4, 22, 18\r
- timerAdd 4, 2000, 10000\r
-\r
- ' KHK message X\r
-\r
- timerAdd 5, 0, -1\r
- timerAdd 5, 5, -1\r
- timerAdd 5, 9, 50\r
- timerAdd 5, 10, 30\r
- timerAdd 5, paus, 30\r
- timerAdd 5, paus + 2, 321\r
-\r
- ' Ellips Y & radius\r
- timerAdd 6, 0, -1\r
- timerAdd 6, 4, -1\r
- timerAdd 6, 10, 30\r
- timerAdd 6, 1000, 50\r
-\r
- timerAdd 7, 0, 1\r
- timerAdd 7, 6, 1\r
- timerAdd 7, 12, 130\r
-\r
- timerAdd 7, paus, 130\r
- timerAdd 7, paus + 2, 1\r
-\r
- ' "Infotehnoloogia" message\r
-\r
- timerAdd 8, 0, 320\r
- timerAdd 8, 11, 320\r
- timerAdd 8, 20, 100\r
- timerAdd 8, paus, 100\r
- timerAdd 8, paus + 1, -1\r
-END SUB\r
-\r
-SUB timerprocess\r
- ' Processes timers to update their current values based on elapsed time\r
- timerCurrent = TIMER\r
- timerDiff = timerCurrent - timerLast\r
- timerLast = timerCurrent\r
-\r
- FOR a = 0 TO 50\r
- ctim = timerCtime(a) + timerDiff\r
- Cplace = timerCplace(a)\r
-timer2:\r
- IF timerTime(a, Cplace + 1) = -1 THEN\r
- ctim = 0\r
- Cplace = 0\r
- END IF\r
- IF timerTime(a, Cplace + 1) < ctim THEN\r
- IF timerTime(a, Cplace + 1) = 0 THEN\r
- timerCvalue(a) = timerValue(a, Cplace)\r
- GOTO timer1:\r
- END IF\r
- Cplace = Cplace + 1\r
- GOTO timer2\r
- END IF\r
-\r
- v1 = timerValue(a, Cplace)\r
- t1 = timerTime(a, Cplace)\r
- v2 = timerValue(a, Cplace + 1)\r
- t2 = timerTime(a, Cplace + 1)\r
-\r
- IF v1 = v2 THEN\r
- timerCvalue(a) = v1\r
- ELSE\r
- Tdiff1 = t2 - t1\r
- Tdiff2 = ctim - t1\r
- Vdiff = v2 - v1\r
- timerCvalue(a) = Tdiff2 / Tdiff1 * Vdiff + v1\r
- END IF\r
-timer1:\r
- timerCplace(a) = Cplace\r
- timerCtime(a) = ctim\r
- NEXT a\r
-END SUB\r
-\r
-SUB turnon\r
- ' Initializes the program by playing a sound and displaying an animation\r
- SCREEN 0\r
- SCREEN 7, , , 1\r
-\r
-\r
- SCREEN 7, , , 1\r
-\r
- FOR x = 0 TO 160 STEP 15\r
- LINE (160 - x - 5, 90 - 5)-(160 + x + 5, 110 + 5), 1, BF\r
- LINE (160 - x - 3, 90 - 3)-(160 + x + 3, 110 + 3), 3, BF\r
- LINE (160 - x, 90)-(160 + x, 110), 15, BF\r
-\r
- PCOPY 0, 1\r
- CLS\r
- SOUND 0, .5\r
- NEXT x\r
-\r
- FOR y = 10 TO 100 STEP 15\r
- CLS\r
-\r
- LINE (160 - x - 5, 90 - y - 5)-(160 + x + 5, 110 + y + 5), 1, BF\r
- LINE (160 - x - 3, 90 - y - 3)-(160 + x + 3, 110 + y + 3), 3, BF\r
- LINE (160 - x, 90 - y)-(160 + x, 110 + y), 15, BF\r
-\r
- PCOPY 0, 1\r
- SOUND 0, .5\r
- NEXT y\r
-\r
- FOR a = 1 TO 25\r
- prn RND * 250, RND * 180, STR$(INT(RND * 2)), 3, 0\r
- PCOPY 0, 1\r
- SOUND 0, 1\r
- NEXT a\r
-\r
- DIM buf(1 TO 1000)\r
- FOR b = 1 TO 30\r
- FOR a = 0 TO 195\r
- t = ABS(100 - a)\r
-\r
- IF RND * 50 < t THEN\r
- GET (1, a)-(318, a + 1), buf\r
- IF a > 100 THEN\r
- PUT (0, a), buf, PSET\r
- ELSE\r
- PUT (2, a), buf, PSET\r
- END IF\r
- END IF\r
- NEXT a\r
- PCOPY 0, 1\r
- 'SOUND 0, 1\r
- NEXT b\r
-END SUB\r
-\r
SOUND 0, 1\r
\r
' Increment frame counter\r
- frm = frm + 1\r
+ frameCounter = frameCounter + 1\r
\r
' Calculate step size based on sine wave\r
- stpSize = (SIN(frm / 10) + 2) / 3\r
+ stepSize = (SIN(frameCounter / 10) + 2) / 3\r
\r
' Calculate x and y offsets based on sine and cosine waves\r
- xOffset = SIN(frm / 30) * 50\r
- yOffset = COS(frm / 42) * 30\r
+ xOffset = SIN(frameCounter / 30) * 50\r
+ yOffset = COS(frameCounter / 42) * 30\r
\r
' Draw circles with varying arc sizes\r
- FOR a = .1 TO 10 STEP stpSize\r
- CIRCLE (160 + xOffset, 100 + yOffset), 80, 10, , , a\r
- NEXT a\r
+ FOR angleStep = .1 TO 10 STEP stepSize\r
+ ' Draw a circle at the calculated offsets\r
+ CIRCLE (160 + xOffset, 100 + yOffset), 80, 10, , , angleStep\r
+ NEXT angleStep\r
\r
' Calculate random color\r
- colr = RND * 2 + 12\r
+ randomColor = RND * 2 + 12\r
\r
' Draw lines between points calculated using sine and cosine waves\r
- FOR a = 0 TO 50\r
- f1 = (a + frm) / 12\r
- f2 = (a + frm) / 7\r
- x1 = SIN(f1) * 50\r
- y1 = COS(f1) * 30\r
- x2 = SIN(f2 + 6) * 80\r
- y2 = COS(f2 + 6) * 120\r
- LINE (x1 + 180, y1 + 150)-(x2 + 180, y2 + 150), colr\r
- NEXT a\r
+ FOR i = 0 TO 50\r
+ frequency1 = (i + frameCounter) / 12\r
+ frequency2 = (i + frameCounter) / 7\r
+\r
+ ' Calculate x and y coordinates for the first point\r
+ x1 = SIN(frequency1) * 50\r
+ y1 = COS(frequency1) * 30\r
+\r
+ ' Calculate x and y coordinates for the second point\r
+ x2 = SIN(frequency2 + 6) * 80\r
+ y2 = COS(frequency2 + 6) * 120\r
+\r
+ ' Draw a line between the two points\r
+ LINE (x1 + 180, y1 + 150)-(x2 + 180, y2 + 150), randomColor\r
+ NEXT i\r
\r
' Draw and fill circles with varying radii\r
- FOR a = 0 TO 50\r
- f1 = (a * 15 + frm) / 12\r
- f2 = (a * 15 + frm) / 7\r
- x1 = SIN(f1) * 50\r
- y1 = COS(f1) * 30\r
- x2 = SIN(f2 + 6) * 80\r
- y2 = COS(f2 + 6) * 120\r
- CIRCLE (x1 + 80, y1 + 50), a / 2, 14\r
+ FOR i = 0 TO 50\r
+ frequency1 = (i * 15 + frameCounter) / 12\r
+ frequency2 = (i * 15 + frameCounter) / 7\r
+\r
+ ' Calculate x and y coordinates for the first point\r
+ x1 = SIN(frequency1) * 50\r
+ y1 = COS(frequency1) * 30\r
+\r
+ ' Calculate x and y coordinates for the second point\r
+ x2 = SIN(frequency2 + 6) * 80\r
+ y2 = COS(frequency2 + 6) * 120\r
+\r
+ ' Draw a circle at the calculated first point\r
+ CIRCLE (x1 + 80, y1 + 50), i / 2, 14\r
+\r
+ ' Fill the circle with color\r
PAINT (x1 + 80, y1 + 50), 14\r
- NEXT a\r
+ NEXT i\r
\r
' Draw additional lines between points calculated using sine and cosine waves\r
- FOR a = 0 TO 15\r
- f1 = (a + frm) / 12\r
- f2 = (a + frm) / 7\r
- x1 = SIN(f1) * 50\r
- y1 = COS(f1) * 30\r
- x2 = SIN(f2 + 6) * 80\r
- y2 = COS(f2 + 6) * 120\r
- LINE (x1 + 180, y1 + 150)-(x2 + 180, y2 + 150), colr\r
- NEXT a\r
+ FOR i = 0 TO 15\r
+ frequency1 = (i + frameCounter) / 12\r
+ frequency2 = (i + frameCounter) / 7\r
+\r
+ ' Calculate x and y coordinates for the first point\r
+ x1 = SIN(frequency1) * 50\r
+ y1 = COS(frequency1) * 30\r
+\r
+ ' Calculate x and y coordinates for the second point\r
+ x2 = SIN(frequency2 + 6) * 80\r
+ y2 = COS(frequency2 + 6) * 120\r
+\r
+ ' Draw a line between the two points\r
+ LINE (x1 + 180, y1 + 150)-(x2 + 180, y2 + 150), randomColor\r
+ NEXT i\r
\r
' Draw random points on the screen\r
- FOR a = 0 TO 50\r
- x = RND * 320\r
- y = RND * 320\r
- PSET (x, y), RND * 15\r
- NEXT a\r
+ FOR i = 0 TO 50\r
+ xCoordinate = RND * 320\r
+ yCoordinate = RND * 320\r
+\r
+ ' Set a pixel at the calculated coordinates with a random color\r
+ PSET (xCoordinate, yCoordinate), RND * 15\r
+ NEXT i\r
\r
' Copy active page to visual page for smooth animation\r
PCOPY 0, 1\r
CLS\r
\r
' Check if frame counter exceeds 100\r
- IF frm > 100 THEN GOTO 2\r
+ IF frameCounter > 100 THEN GOTO exitLabel\r
\r
' Continue loop\r
GOTO 1\r
\r
' Exit label\r
-2\r
- ' Chain to another program\r
- CHAIN "KHKDEMO4.BAS"\r
+exitLabel:\r
+\r