I guess I will get to dithering later, first I wanted to make the gradient.
Quiz: Can anyone explain what's happening in the first column?
_TITLE "Making the Gradient"
DEFLNG A-Z
CONST w = 800
CONST h = 600
SCREEN _NEWIMAGE(w, h, 32)
d = 1
k1 = _RGB32(128, 0, 0)
k2 = _RGB(0, 128, 255)
stepper = 300
WHILE 1
FOR y = 0 TO h - 1 STEP stepper
FOR x = 0 TO w - 1 STEP stepper
IF y MOD 2 * stepper THEN
IF x MOD 2 * stepper THEN
IF x MOD 4 * stepper = 3 * stepper THEN c1 = k1: c2 = k2 ELSE c1 = k2: c2 = k1
horzGradRec x, y, stepper, stepper, c1, c2
gradCirc x + stepper / 2, y + stepper / 2, stepper \ 3, k2, k1
ELSE
vertGradRec x, y, stepper, stepper, c2, c1
gradCirc x + stepper / 2, y + stepper / 2, stepper \ 3, k1, k2
END IF
ELSE
IF x MOD 2 * stepper THEN
vertGradRec x, y, stepper, stepper, c2, c1
gradCirc x + stepper / 2, y + stepper / 2, stepper \ 3, k1, k2
ELSE
IF x MOD 4 * stepper = 2 * stepper THEN c1 = k1: c2 = k2 ELSE c1 = k2: c2 = k1
horzGradRec x, y, stepper, stepper, c2, c1
gradCirc x + stepper / 2, y + stepper / 2, stepper \ 3, k2, k1
END IF
END IF
NEXT
NEXT
stepper = stepper - 2 * d
IF stepper < 10 OR stepper > 300 THEN d = d * -1
_DISPLAY
_LIMIT 8
WEND
'c1 color to left, c2 color to right
SUB horzGradRec (x0, y0, w, h, c1, c2)
FOR cx = 0 TO w
midInk c1, c2, cx / w
LINE (x0 + cx, y0)-STEP(0, h), , BF
NEXT
END SUB
SUB vertGradRec (x0, y0, w, h, c1, c2)
FOR cy = 0 TO h
midInk c1, c2, cy / h
LINE (x0, y0 + cy)-STEP(w, 0), , BF
NEXT
END SUB
'let c1 be outer most color c2 the inner most
SUB gradCirc (x0, y0, r, c1, c2)
FOR cr = r TO 0 STEP -1
midInk c2, c1, cr / r
fcirc x0, y0, cr
NEXT
END SUB
' let fr## be the fraction from 1st color to 2nd color 0 means all color 1, 1 means all color 2
SUB midInk (c1, c2, fr##)
r1 = _RED(c1): g1 = _GREEN(c1): b1 = _BLUE(c1)
r2 = _RED(c2): g2 = _GREEN(c2): b2 = _BLUE(c2)
COLOR _RGB(r1 + (r2 - r1) * fr##, g1 + (g2 - g1) * fr##, b1 + (b2 - b1) * fr##)
END SUB
SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
DIM Radius AS LONG, RadiusError AS LONG
DIM X AS LONG, Y AS LONG
Radius = ABS(R)
RadiusError = -Radius
X = Radius
Y = 0
IF Radius = 0 THEN PSET (CX, CY): EXIT SUB
' Draw the middle span here so we don't draw it twice in the main loop,
' which would be a problem with blending turned on.
LINE (CX - X, CY)-(CX + X, CY), , BF
WHILE X > Y
RadiusError = RadiusError + Y * 2 + 1
IF RadiusError >= 0 THEN
IF X <> Y + 1 THEN
LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
END IF
X = X - 1
RadiusError = RadiusError - X * 2
END IF
Y = Y + 1
LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
WEND
END SUB