From: Svjatoslav Agejenko Date: Wed, 8 Jan 2025 21:02:13 +0000 (+0200) Subject: Improved program readability using new AI X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=375da1d4929069ce9191af8a2a4dd34eb32006b9;p=qbasicapps.git Improved program readability using new AI --- diff --git a/Fractals/fractal circles.bas b/Fractals/fractal circles.bas index 3aa1541..71561b5 100755 --- a/Fractals/fractal circles.bas +++ b/Fractals/fractal circles.bas @@ -1,5 +1,7 @@ -' Program to render spiral resembling fractal made out of circles. -' By Svjatoslav Agejenko. +DECLARE SUB drawFractal (x!, y!, angle AS SINGLE, size AS SINGLE, w AS INTEGER) +' Program Title: Spiral Fractal Renderer +' Description: Renders a spiral fractal made up of circles using recursion in QBasic. +' Author: Svjatoslav Agejenko ' Email: svjatoslav@svjatoslav.eu ' Homepage: http://www.svjatoslav.eu ' @@ -7,88 +9,112 @@ ' 2003.12, Initial version ' 2024.08, Improved program readability using AI -DECLARE SUB drawFractal (x!, y!, angle!, size!, w!) -DIM SHARED depth -DIM SHARED pi +' Declare shared variables to be used across the program +DIM SHARED depth AS INTEGER +DIM SHARED pi AS SINGLE -DIM SHARED scaleH1, scaleH2, scaleV1, scaleV2, hp, vp +' Define scaling factors for horizontal and vertical directions +DIM SHARED scaleH1 AS SINGLE, scaleH2 AS SINGLE, scaleV1 AS SINGLE, scaleV2 AS SINGLE +DIM SHARED hp AS SINGLE, vp AS SINGLE -pi = 3.14128 +' Initialize constants +pi = 3.14159 -SCREEN 12 +SCREEN 12 ' Set the screen mode to 12 for better graphics quality -scaleV1 = 5 -scaleV2 = 2 -vp = .2 +' Define scaling factors and direction variables +scaleV1 = 5 ' Vertical scale factor for one direction +scaleV2 = 2 ' Vertical scale factor for another direction +vp = .2 ' Vertical angle increment -scaleH1 = 2 -scaleH2 = 1.4 -hp = .2 +scaleH1 = 2 ' Horizontal scale factor for one direction +scaleH2 = 1.4 ' Horizontal scale factor for another direction +hp = .2 ' Horizontal angle increment +' Start the fractal drawing process from the center of the screen drawFractal 320, 240, pi - .9, 50, 0 +' Wait for user input to exit the program gracefully a$ = INPUT$(1) -SYSTEM +SYSTEM ' Terminate the program -SUB drawFractal (x, y, angle, size, w) - depth = depth + 1 - IF size < .2 THEN GOTO 1 +SUB drawFractal (x, y, angle AS SINGLE, size AS SINGLE, w AS INTEGER) + depth = depth + 1 ' Increment the recursion depth + + IF size < .2 THEN GOTO 1 ' Base case for recursion termination ' Determine color based on the current depth - IF depth / 2 = depth \ 2 THEN - c = 15 + IF depth MOD 2 = 0 THEN + c = 15 ' White ELSE - c = 10 + c = 10 ' Light green END IF - CIRCLE (x, y), size, c - PAINT (x, y), c + CIRCLE (x, y), size, c ' Draw a circle at the current position and size with specified color + PAINT (x, y), c ' Fill the circle to create a solid shape - ' Recursive calls for different directions + ' Recursive calls for different directions based on the parameter w IF w <> 1 THEN + ' Calculate new coordinates after rotating angle + vp degrees x1 = SIN(angle) * size * 2.5 + x y1 = COS(angle) * size * 2.5 + y + + ' Determine scaling factor based on the direction IF w = 3 THEN newSize = size / scaleV2 ELSE newSize = size / scaleV1 END IF - drawFractal x1, y1, angle + vp, newSize, 3 + + drawFractal x1, y1, angle + vp, newSize, 3 ' Recursive call to the same subroutine with updated parameters END IF IF w <> 2 THEN - x1 = SIN(angle - pi / 2) * size * 2.5 + x - y1 = COS(angle - pi / 2) * size * 2.5 + y + ' Calculate new coordinates after rotating angle - pi/2 degrees + x1 = SIN(angle - .5 * pi) * size * 2.5 + x + y1 = COS(angle - .5 * pi) * size * 2.5 + y + + ' Determine scaling factor based on the direction IF w = 4 THEN newSize = size / scaleH2 ELSE newSize = size / scaleH1 END IF - drawFractal x1, y1, angle + hp, newSize, 4 + + drawFractal x1, y1, angle + hp, newSize, 4 ' Recursive call to the same subroutine with updated parameters END IF IF w <> 3 THEN + ' Calculate new coordinates after rotating angle - pi degrees x1 = SIN(angle - pi) * size * 2.5 + x y1 = COS(angle - pi) * size * 2.5 + y + + ' Determine scaling factor based on the direction IF w = 1 THEN newSize = size / scaleV2 ELSE newSize = size / scaleV1 END IF - drawFractal x1, y1, angle + vp, newSize, 1 + + drawFractal x1, y1, angle + vp, newSize, 1 ' Recursive call to the same subroutine with updated parameters END IF IF w <> 4 THEN - x1 = SIN(angle - pi * 1.5) * size * 2.5 + x - y1 = COS(angle - pi * 1.5) * size * 2.5 + y + ' Calculate new coordinates after rotating angle - pi*3/2 degrees + x1 = SIN(angle - 1.5 * pi) * size * 2.5 + x + y1 = COS(angle - 1.5 * pi) * size * 2.5 + y + + ' Determine scaling factor based on the direction IF w = 2 THEN newSize = size / scaleH2 ELSE newSize = size / scaleH1 END IF - drawFractal x1, y1, angle + hp, newSize, 2 + + drawFractal x1, y1, angle + hp, newSize, 2 ' Recursive call to the same subroutine with updated parameters END IF - 1 - depth = depth - 1 +1 + depth = depth - 1 ' Decrement recursion depth after all recursive calls are made END SUB +