-' An attempt to generate universally reusable color parette.\r
+' An attempt to generate a universally reusable color palette.\r
' By Svjatoslav Agejenko in 2001.\r
' homepage: svjatoslav.eu\r
' email: svjatoslav@svjatoslav.eu\r
- \r
\r
-\r
-DECLARE SUB getcol (a%, b%, c%, d%)\r
DEFINT A-Y\r
SCREEN 13\r
CLS\r
\r
-c = 0\r
-FOR r = 0 TO 5\r
- FOR g = 0 TO 5\r
- FOR b = 0 TO 5\r
- OUT &H3C8, c\r
- c = c + 1\r
- OUT &H3C9, r * 12\r
- OUT &H3C9, g * 12\r
- OUT &H3C9, b * 12\r
- NEXT b\r
- NEXT g\r
-NEXT r\r
-\r
-'GOTO 1\r
-\r
-FOR c = 0 TO 5\r
- FOR b = 0 TO 5\r
- FOR a = 0 TO 5\r
- LINE (a * 5 + c * 30, b * 5)-(a * 5 + 4 + c * 30, b * 5 + 4), c * 36 + b * 6 + a, BF\r
- NEXT a\r
- NEXT b\r
-NEXT c\r
-\r
-\r
+' Initialize color index\r
+colorIndex = 0\r
+\r
+' Generate colors by varying red, green, and blue components from 0 to 5\r
+FOR redComponent = 0 TO 5\r
+ FOR greenComponent = 0 TO 5\r
+ FOR blueComponent = 0 TO 5\r
+ ' Set the color for the next pixel\r
+ OUT &H3C8, colorIndex\r
+ colorIndex = colorIndex + 1\r
+\r
+ ' Output the RGB components to the palette registers\r
+ OUT &H3C9, redComponent * 12\r
+ OUT &H3C9, greenComponent * 12\r
+ OUT &H3C9, blueComponent * 12\r
+ NEXT blueComponent\r
+ NEXT greenComponent\r
+NEXT redComponent\r
+\r
+' Draw a grid of colored squares using the generated color palette\r
+FOR colorIndex = 0 TO 5\r
+ FOR blueComponent = 0 TO 5\r
+ FOR redComponent = 0 TO 5\r
+ ' Draw a square with the calculated color\r
+ LINE (redComponent * 5 + colorIndex * 30, blueComponent * 5)-_\r
+ (redComponent * 5 + 4 + colorIndex * 30, blueComponent * 5 + 4), _\r
+ colorIndex * 36 + blueComponent * 6 + redComponent, BF\r
+ NEXT redComponent\r
+ NEXT blueComponent\r
+NEXT colorIndex\r
+\r
+' Wait for user input before proceeding\r
a$ = INPUT$(1)\r
\r
-ex = -100\r
-ey = 0\r
-FOR z = 0 TO 75 STEP 15\r
- x1 = 50 - (z / 2)\r
- y1 = 50 - (z * .866025)\r
- x2 = 50 + z\r
+' Initialize coordinates for pattern drawing\r
+patternEx = -100\r
+patternEy = 0\r
+\r
+' Draw a series of patterns with varying colors\r
+FOR patternZ = 0 TO 75 STEP 15\r
+ ' Calculate the vertices of an equilateral triangle\r
+ x1 = 50 - (patternZ / 2)\r
+ y1 = 50 - (patternZ * .866025)\r
+ x2 = 50 + patternZ\r
y2 = 50\r
x3 = x1\r
y3 = 100 - y1\r
\r
- ex = ex + 100\r
- IF z = 45 THEN ex = ex - 300: ey = ey + 101\r
+ ' Move to the next starting position for the pattern\r
+ patternEx = patternEx + 100\r
+ IF patternZ = 45 THEN\r
+ patternEx = patternEx - 300\r
+ patternEy = patternEy + 101\r
+ END IF\r
\r
+ ' Draw the pattern by calculating colors based on distance from triangle vertices\r
FOR x = 0 TO 100\r
FOR y = 0 TO 100\r
+ ' Calculate color components based on distance to each vertex\r
r = 7 - (SQR((x1 - x) ^ 2 + (y1 - y) ^ 2) / 15 + 1)\r
g = 7 - (SQR((x2 - x) ^ 2 + (y2 - y) ^ 2) / 15 + 1)\r
b = 7 - (SQR((x3 - x) ^ 2 + (y3 - y) ^ 2) / 15 + 1)\r
+\r
+ ' Clamp color values within the range of 0 to 5\r
IF r < 0 THEN r = 0\r
IF g < 0 THEN g = 0\r
IF b < 0 THEN b = 0\r
IF r > 5 THEN r = 5\r
IF g > 5 THEN g = 5\r
IF b > 5 THEN b = 5\r
- c = r * 36 + g * 6 + b\r
- PSET (x + ex, y + ey), c\r
+\r
+ ' Calculate the final color index\r
+ colorIndex = r * 36 + g * 6 + b\r
+\r
+ ' Plot the pixel with the calculated color\r
+ PSET (x + patternEx, y + patternEy), colorIndex\r
NEXT y\r
NEXT x\r
-NEXT z\r
+NEXT patternZ\r
\r
+' Wait for user input before proceeding\r
a$ = INPUT$(1)\r
-1\r
-ex = -100\r
-ey = 0\r
-FOR z = 0 TO 75 STEP 15\r
- x1 = 50 - (z / 2.5)\r
- y1 = 50 - (z * .566025)\r
- x2 = 50 + z / 1.5\r
+\r
+' Reset starting position for the second pattern\r
+patternEx = -100\r
+patternEy = 0\r
+\r
+' Draw a second series of patterns using color dithering, to create\r
+' seemingly smooth color transitions while still having only 8bit colors to work with\r
+FOR patternZ = 0 TO 75 STEP 15\r
+ ' Calculate the vertices of an equilateral triangle with different scaling\r
+ x1 = 50 - (patternZ / 2.5)\r
+ y1 = 50 - (patternZ * .566025)\r
+ x2 = 50 + patternZ / 1.5\r
y2 = 50\r
x3 = x1\r
y3 = 100 - y1\r
\r
- ex = ex + 100\r
- IF z = 45 THEN ex = ex - 300: ey = ey + 101\r
+ ' Move to the next starting position for the pattern\r
+ patternEx = patternEx + 100\r
+ IF patternZ = 45 THEN\r
+ patternEx = patternEx - 300\r
+ patternEy = patternEy + 101\r
+ END IF\r
+\r
+ ' Initialize accumulators for dithering color components\r
+ rSum = 0\r
+ gSum = 0\r
+ bSum = 0\r
\r
- r1 = 0\r
- g1 = 0\r
- b1 = 0\r
+ ' Draw the pattern by calculating average colors based on distance from triangle vertices\r
FOR x = 0 TO 100\r
FOR y = 0 TO 100\r
+ ' Calculate color components based on distance to each vertex\r
r = 30 - (SQR((x1 - x) ^ 2 + (y1 - y) ^ 2) / 2 + 1)\r
g = 30 - (SQR((x2 - x) ^ 2 + (y2 - y) ^ 2) / 2 + 1)\r
b = 30 - (SQR((x3 - x) ^ 2 + (y3 - y) ^ 2) / 2 + 1)\r
- r1 = r1 + r\r
- g1 = g1 + g\r
- b1 = b1 + b\r
- r = r1 / 5\r
- g = g1 / 5\r
- b = b1 / 5\r
- r1 = r1 - (r * 5)\r
- g1 = g1 - (g * 5)\r
- b1 = b1 - (b * 5)\r
\r
- IF r < 0 THEN r = 0\r
- IF g < 0 THEN g = 0\r
- IF b < 0 THEN b = 0\r
- IF r > 5 THEN r = 5\r
- IF g > 5 THEN g = 5\r
- IF b > 5 THEN b = 5\r
- c = r * 36 + g * 6 + b\r
- PSET (x + ex, y + ey), c\r
+ ' Accumulate the color components\r
+ rSum = rSum + r\r
+ gSum = gSum + g\r
+ bSum = bSum + b\r
+\r
+ ' Calculate the average color components over a span of 5 pixels\r
+ rAvg = rSum / 5\r
+ gAvg = gSum / 5\r
+ bAvg = bSum / 5\r
+\r
+ ' Reset the sums after calculating the averages\r
+ rSum = rSum - (rAvg * 5)\r
+ gSum = gSum - (gAvg * 5)\r
+ bSum = bSum - (bAvg * 5)\r
+\r
+ ' Clamp average color values within the range of 0 to 5\r
+ IF rAvg < 0 THEN rAvg = 0\r
+ IF gAvg < 0 THEN gAvg = 0\r
+ IF bAvg < 0 THEN bAvg = 0\r
+ IF rAvg > 5 THEN rAvg = 5\r
+ IF gAvg > 5 THEN gAvg = 5\r
+ IF bAvg > 5 THEN bAvg = 5\r
+\r
+ ' Calculate the final color index\r
+ colorIndex = rAvg * 36 + gAvg * 6 + bAvg\r
+\r
+ ' Plot the pixel with the calculated color\r
+ PSET (x + patternEx, y + patternEy), colorIndex\r
NEXT y\r
NEXT x\r
-NEXT z\r
-\r
-a$ = INPUT$(1)\r
-SYSTEM\r
+NEXT patternZ\r
\r
+' Wait for user input before exiting\r
+a$ = INPUT$(1)
\ No newline at end of file