--- /dev/null
+' Program render bump-map animation.\r
+' By Svjatoslav Agejenko.\r
+' Email: svjatoslav@svjatoslav.eu\r
+' Homepage: http://www.svjatoslav.eu\r
+\r
+' Changelog:\r
+' ?, Initial version\r
+' 2024.08, Improved program readability using AI\r
+\r
+DECLARE SUB makeSurface ()\r
+DECLARE SUB animate ()\r
+DECLARE SUB makeDot (x!, y!)\r
+DECLARE SUB paintImage ()\r
+SCREEN 13\r
+\r
+' surface height map\r
+DIM SHARED imgHeight(0 TO 50, 0 TO 50)\r
+\r
+PAINT (0, 0), 1\r
+\r
+makeSurface\r
+paintImage\r
+animate\r
+\r
+SUB animate\r
+\r
+ frame = 0\r
+1\r
+ ' Increment the frame counter\r
+ frame = frame + 5\r
+\r
+ ' Calculate light position based on sine functions\r
+ lightX = SIN(frame / 100) * 20 + 25\r
+ lightY = SIN(frame / 71.32) * 20 + 25\r
+ lightX = lightX + SIN(frame / 34) * 10\r
+ lightY = lightY + SIN(frame / 45) * 10\r
+\r
+ ' Calculate brightness for each pixel based on distance and angle from light\r
+ FOR y = 2 TO 48\r
+ FOR x = 2 TO 48\r
+ distance = SQR((x - lightX) ^ 2 + (y - lightY) ^ 2)\r
+ brightness = (30 - distance) / 4\r
+\r
+ ' Calculate surface inclination relative to light location\r
+ value = imgHeight(x - 1, y) - imgHeight(x, y)\r
+ brightnessX = (lightX - x) * value\r
+\r
+ value = imgHeight(x, y - 1) - imgHeight(x, y)\r
+ brightnessY = (lightY - y) * value\r
+\r
+ brightness = brightness + (brightnessX + brightnessY) / (distance / 2)\r
+\r
+ ' Clamp brightness within valid range\r
+ IF brightness < 0 THEN brightness = 0\r
+ IF brightness > 15 THEN brightness = 15\r
+\r
+ ' Set pixel color based on brightness\r
+ PSET (x + 150, y), 16 + brightness\r
+ NEXT x\r
+ NEXT y\r
+\r
+ ' Draw light source as a circle\r
+ CIRCLE (lightX + 150, lightY), 2, 12\r
+\r
+ ' Loop back to the start of animation\r
+ GOTO 1\r
+\r
+END SUB\r
+\r
+SUB makeDot (x, y)\r
+\r
+ ' Create a dot with Gaussian distribution\r
+ FOR x1 = -10 TO 10\r
+ FOR y1 = -10 TO 10\r
+ dist = SQR(x1 * x1 + y1 * y1)\r
+ power = 4 - dist\r
+ IF power < 0 THEN power = 0\r
+\r
+ ' Calculate image coordinates\r
+ imgX = x1 + x\r
+ imgY = y1 + y\r
+\r
+ ' Ensure coordinates are within bounds\r
+ IF imgX < 0 THEN imgX = 0\r
+ IF imgY < 0 THEN imgY = 0\r
+ IF imgX > 50 THEN imgX = 50\r
+ IF imgY > 50 THEN imgY = 50\r
+\r
+ ' Add power to the height map\r
+ imgHeight(imgX, imgY) = imgHeight(imgX, imgY) + power\r
+ NEXT y1\r
+ NEXT x1\r
+\r
+END SUB\r
+\r
+SUB makeSurface\r
+\r
+ ' Generate random dots on the surface\r
+ FOR x = 0 TO 10\r
+ CALL makeDot(RND * 50, RND * 50)\r
+ NEXT x\r
+\r
+ ' Add some structured dots to create a pattern\r
+ FOR x = 0 TO 45 STEP 2\r
+ CALL makeDot(x, x / 2 + 5)\r
+ NEXT x\r
+\r
+ FOR x = 5 TO 30 STEP 2\r
+ CALL makeDot(x, -x / 1.2 + 30)\r
+ NEXT x\r
+\r
+END SUB\r
+\r
+SUB paintImage\r
+\r
+ ' Paint the image based on height map\r
+ FOR x = 0 TO 50\r
+ FOR y = 0 TO 50\r
+ clr = imgHeight(x, y) + 16\r
+ PSET (x, y), clr\r
+ NEXT y\r
+ NEXT x\r
+\r
+END SUB
\ No newline at end of file
+++ /dev/null
-' Program render bump-map animation.\r
-' By Svjatoslav Agejenko.\r
-' Email: svjatoslav@svjatoslav.eu\r
-' Homepage: http://www.svjatoslav.eu\r
-\r
-' Changelog:\r
-' ?, Initial version\r
-' 2024.08, Improved program readability using AI\r
-\r
-DECLARE SUB makeSurface ()\r
-DECLARE SUB animate ()\r
-DECLARE SUB makeDot (x!, y!)\r
-DECLARE SUB paintImage ()\r
-SCREEN 13\r
-\r
-' surface height map\r
-DIM SHARED imgHeight(0 TO 50, 0 TO 50)\r
-\r
-PAINT (0, 0), 1\r
-\r
-makeSurface\r
-paintImage\r
-animate\r
-\r
-SUB animate\r
-\r
- frame = 0\r
-1\r
- ' Increment the frame counter\r
- frame = frame + 5\r
-\r
- ' Calculate light position based on sine functions\r
- lightX = SIN(frame / 100) * 20 + 25\r
- lightY = SIN(frame / 71.32) * 20 + 25\r
- lightX = lightX + SIN(frame / 34) * 10\r
- lightY = lightY + SIN(frame / 45) * 10\r
-\r
- ' Calculate brightness for each pixel based on distance and angle from light\r
- FOR y = 2 TO 48\r
- FOR x = 2 TO 48\r
- distance = SQR((x - lightX) ^ 2 + (y - lightY) ^ 2)\r
- brightness = (30 - distance) / 4\r
-\r
- ' Calculate surface inclination relative to light location\r
- value = imgHeight(x - 1, y) - imgHeight(x, y)\r
- brightnessX = (lightX - x) * value\r
-\r
- value = imgHeight(x, y - 1) - imgHeight(x, y)\r
- brightnessY = (lightY - y) * value\r
-\r
- brightness = brightness + (brightnessX + brightnessY) / (distance / 2)\r
-\r
- ' Clamp brightness within valid range\r
- IF brightness < 0 THEN brightness = 0\r
- IF brightness > 15 THEN brightness = 15\r
-\r
- ' Set pixel color based on brightness\r
- PSET (x + 150, y), 16 + brightness\r
- NEXT x\r
- NEXT y\r
-\r
- ' Draw light source as a circle\r
- CIRCLE (lightX + 150, lightY), 2, 12\r
-\r
- ' Loop back to the start of animation\r
- GOTO 1\r
-\r
-END SUB\r
-\r
-SUB makeDot (x, y)\r
-\r
- ' Create a dot with Gaussian distribution\r
- FOR x1 = -10 TO 10\r
- FOR y1 = -10 TO 10\r
- dist = SQR(x1 * x1 + y1 * y1)\r
- power = 4 - dist\r
- IF power < 0 THEN power = 0\r
-\r
- ' Calculate image coordinates\r
- imgX = x1 + x\r
- imgY = y1 + y\r
-\r
- ' Ensure coordinates are within bounds\r
- IF imgX < 0 THEN imgX = 0\r
- IF imgY < 0 THEN imgY = 0\r
- IF imgX > 50 THEN imgX = 50\r
- IF imgY > 50 THEN imgY = 50\r
-\r
- ' Add power to the height map\r
- imgHeight(imgX, imgY) = imgHeight(imgX, imgY) + power\r
- NEXT y1\r
- NEXT x1\r
-\r
-END SUB\r
-\r
-SUB makeSurface\r
-\r
- ' Generate random dots on the surface\r
- FOR x = 0 TO 10\r
- CALL makeDot(RND * 50, RND * 50)\r
- NEXT x\r
-\r
- ' Add some structured dots to create a pattern\r
- FOR x = 0 TO 45 STEP 2\r
- CALL makeDot(x, x / 2 + 5)\r
- NEXT x\r
-\r
- FOR x = 5 TO 30 STEP 2\r
- CALL makeDot(x, -x / 1.2 + 30)\r
- NEXT x\r
-\r
-END SUB\r
-\r
-SUB paintImage\r
-\r
- ' Paint the image based on height map\r
- FOR x = 0 TO 50\r
- FOR y = 0 TO 50\r
- clr = imgHeight(x, y) + 16\r
- PSET (x, y), clr\r
- NEXT y\r
- NEXT x\r
-\r
-END SUB
\ No newline at end of file