I thought I posted this years ago, but couldn't find it. So I dug through my local files and found it and now I am posting it.
It should be self explanatory.
REM ****************************************************************************
REM Extended 2D Commands [E2DC]
REM Author: Phaelax (unless otherwise noted)
REM
REM =[ Current Commands ]=
REM ----------------------------------------------------------------------------
REM * E2DC_Fill_Circle(x, y, radius)
REM * E2DC_Fill_Circle_Gradient_Vertical(x, y, radius, color1, color2)
REM * E2DC_Rounded_Box_Fill(1, y1, x2, y2, radius)
REM * E2DC_Rounded_Box_Fill_Alpha(1, y1, x2, y2, radius, color)
REM * E2DC_Rounded_Box_Outline(x1, y1, x2, y2, radius)
REM * E2DC_Rounded_Box_Fill_Gradient_Vertical(x1, y1, x2, y2, radius, color1, color2)
REM * E2DC_Fill_Circle_Alpha(x, y, radius, color)
REM * E2DC_Circle_AA(x, y, radius, color)
REM * E2DC_Circle_AA_Alpha(x, y, radius, color)
REM * E2DC_Rounded_Box_AA_Outline(x1, y1, x2, y2, radius, color)
REM * E2DC_Rounded_Box_AA_Alpha_Outline(x1, y1, x2, y2, radius, color)
REM * E2DC_Fill_Circle_Gradient_Radial(cx1, cy1, r1, cx2, cy2, r2, color1, color2)
REM * E2DC_Get_LO_Color(baseColor, targetColor, percent)
REM * E2DC_ARGB(a, r, g, b)
REM * E2DC_Dot(x, y, color)
REM * E2DC_Pick(x, y)
REM * E2DC_Distance#(a, b)
REM * E2DC_Line_AA_ALPHA(x1, y1, x2, y2, color)
REM ****************************************************************************
REM **************************************************
REM Xiaolin Wu's line algorithm.
REM **************************************************
function E2DC_Line_AA_ALPHA(x1, y1, x2, y2, color as dword)
local dx as float
local dy as float
local xend as float
local yend as float
local xgap as float
local ygap as float
local xpxl1 as float
local ypxl1 as float
local xpxl2 as float
local ypxl2 as float
local intery as float
local interx as float
red = rgbr(color)
green = rgbg(color)
blue = rgbb(color)
dx = x2-x1
dy = y2-y1
if abs(dx) > abs(dy)
rem handle horizontal lines
if x2 < x1
ax = x1
x1 = x2
x2 = ax
ay = y1
y1 = y2
y2 = ay
endif
gradient# = dy / dx
rem handle first endpoint
xend = ceil(x1)
yend = y1 + gradient# * (xend-x1)
xgap = 1.0 - fract#(x1 + 0.5)
xpxl1 = xend : `used in main loop
ypxl1 = int(yend)
f# = 1-fract#(yend)*xgap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl1, ypxl1, xpxl1+1, ypxl1+1, c, c, c, c
rem brightness: fract#(yend)*xgap
f# = fract#(yend)*xgap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl1, ypxl1+1, xpxl1+1, ypxl1+2, c, c, c, c
intery = yend + gradient# : `first y-intersection for main loop
rem handle second endpoint
xend = ceil(x2)
yend = y2 + gradient# * (xend-x2)
xgap = 1.0 - fract#(x2 + 0.5)
xpxl2 = xend : `used in main loop
ypxl2 = int(yend)
f# = 1-fract#(yend)*xgap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl2, ypxl2, xpxl2+1, ypxl2+1, c, c, c, c
f# = fract#(yend)*xgap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl2, ypxl2+1, xpxl2+1, ypxl2+2, c, c, c, c
rem main loop
a = xpxl1+1
b = xpxl2-1
for x = a to b
f# = 1-fract#(intery) : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box x, intery, x+1, intery+1, c, c, c, c
f# = fract#(intery) : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box x, intery+1, x+1, intery+2, c, c, c, c
intery = intery + gradient#
next x
else
rem handle vertical lines
if y2 < y1
ax = x1
x1 = x2
x2 = ax
ay = y1
y1 = y2
y2 = ay
endif
gradient# = dx / dy
rem handle first endpoint
yend = ceil(y1)
xend = x1 + gradient# * (yend-y1)
ygap = 1.0 - fract#(y1 + 0.5)
xpxl1 = int(xend)
ypxl1 = yend
f# = 1-fract#(xend)*ygap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl1, ypxl1, xpxl1+1, ypxl1+1, c, c, c, c
intery = intery + gradient#
f# = fract#(xend)*ygap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl1, ypxl1+1, xpxl1+1, ypxl1+2, c, c, c, c
interx = xend + gradient# : `first y-intersection for main loop
rem handle second endpoint
yend = ceil(y2)
xend = x2 + gradient# * (yend-y2)
ygap = fract#(y2 + 0.5)
xpxl2 = int(xend)
ypxl2 = yend
f# = 1-fract#(xend)*ygap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl2, ypxl2, xpxl2+1, ypxl2+1, c, c, c, c
f# = fract#(xend)*ygap : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box xpxl2, ypxl2+1, xpxl2+1, ypxl2+2, c, c, c, c
rem main loop
a = ypxl1+1
b = ypxl2-1
for y = a to b
f# = 1-fract#(interx) : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box interx, y, interx+1, y+1, c, c, c, c
f# = fract#(interx) : `brightness
alpha = 255*f#
c = E2DC_ARGB(alpha, red, green, blue)
box interx+1, y, interx+2, y+1, c, c, c, c
interx = interx + gradient#
next y
endif
endfunction
REM **************************************************
REM Draws a filled-in circle
REM **************************************************
function E2DC_Fill_Circle(x,y,r)
for yy = y-r to y
for xx = x-r to x
d# = (xx-x)*(xx-x) + (yy-y)*(yy-y)
if d# <= r*r
box xx,yy,x+(x-xx)+1,yy+1
if yy <> y then box xx,y+(y-yy),x+(x-xx)+1,y+(y-yy)+1
exit
endif
next xx
next yy
endfunction
REM **************************************************
REM Draws a filled-in circle with a vertical gradient
REM **************************************************
function E2DC_Fill_Circle_Gradient_Vertical(x0,y0,r, color1 as dword, color2 as dword)
x1 = x0-r
y1 = y0-r
x2 = x0+r
y2 = y0+r
diameter# = r+r
for y = y1 to y2
for x = x1 to x0
d# = (x-x0)^2 + (y-y0)^2
if d# <= r*r
p# = (y-y0 + r) / diameter#
c = E2DC_Get_LO_Color(color1, color2, p#)
w = x0 + x0-x
box x,y,w,y+1, c,c,c,c
exit
endif
next x
next y
endfunction
REM **************************************************
REM Author: OBese87 [Aug. 19 2009]
REM Edited: Phaelax [June 11 2010]
REM
REM Draws a box with rounded corners and filled with
REM the current drawing color
REM **************************************************
function E2DC_Rounded_Box_Fill(ax,ay,bx,by,r)
dots = r*6.28
deg2dot# = 360 / (dots*1.0)
dotsperqtr# = dots / 4.0
L = abs(bx-ax)-r*2
H = abs(by-ay)
for corner = 2 to 3
select corner
case 0:x=bx-r:y=by-r:endcase
case 1:x=bx-r:y=ay+r:endcase
case 2:x=ax+r:y=ay+r:endcase
case 3:x=ax+r:y=by-r:endcase
endselect
qtr = corner*dotsperqtr#
for o = qtr to qtr+dotsperqtr#
u = sin(o*deg2dot#)*r
v = cos(o*deg2dot#)*r
x2 = L - u*2
box x+u, y+v, x+u+x2, y+v+1
next o
next corner
box ax, ay+r, bx, by-r
endfunction
REM **************************************************
REM Author: OBese87 [Aug. 19 2009]
REM Edited: Phaelax [June 11 2010]
REM
REM Draws a box with rounded corners and filled with
REM the current drawing color
REM **************************************************
function E2DC_Rounded_Box_Fill_Alpha(ax,ay,bx,by,r,color)
dots = r*6.28
deg2dot# = 360 / (dots*1.0)
dotsperqtr# = dots / 4.0
L = abs(bx-ax)-r*2
H = abs(by-ay)
for corner = 2 to 3
select corner
case 0:x=bx-r:y=by-r:endcase
case 1:x=bx-r:y=ay+r:endcase
case 2:x=ax+r:y=ay+r:endcase
case 3:x=ax+r:y=by-r:endcase
endselect
qtr = corner*dotsperqtr#
for o = qtr to qtr+dotsperqtr#
u = sin(o*deg2dot#)*r
v = cos(o*deg2dot#)*r
x2 = L - u*2
box x+u, y+v, x+u+x2, y+v+1,color,color,color,color
next o
next corner
box ax, ay+r, bx, by-r,color,color,color,color
endfunction
REM **************************************************
REM Author: OBese87 [Aug. 19 2009]
REM
REM Draws an outline of a box with rounded corners
REM **************************************************
function E2DC_Rounded_Box_Outline(ax,ay,bx,by,r)
width = 1
box ax+r,ay,bx-r+1,ay+width
box bx,ay+r,bx+width,by-r
box ax+r,by,bx-r,by+width
box ax,ay+r,ax+width,by-r
dots = r*6.28
deg2dot# = 360.0 / dots
dotsperqtr# = dots / 4.0
L = bx-ax
for corner = 0 to 3
select corner
case 0:x=bx-r:y=by-r:endcase
case 1:x=bx-r:y=ay+r:endcase
case 2:x=ax+r:y=ay+r:endcase
case 3:x=ax+r:y=by-r:endcase
endselect
qtr = corner*dotsperqtr#
for o=qtr to qtr+dotsperqtr#
u = sin(o*deg2dot#)*r
v = cos(o*deg2dot#)*r
box x+u, y+v, x+u+width, y+v+width
next o
next corner
endfunction
REM **************************************************
REM Draws a box with rounded corners and filled
REM with a vertical gradient
REM **************************************************
function E2DC_Rounded_Box_Fill_Gradient_Vertical(cx as integer, cy as integer, x2 as integer, y2 as integer, r as integer, color1 as dword, color2 as dword)
height# = y2-cy
offsetX = cx
offsetY = cy
cx = cx - offsetX
cy = cy - offsetY
x2 = x2 - offsetX
y2 = y2 - offsetY
cx = cx+r
cy = cy+r
ow = x2-cx-r
oh = y2-cy-r
x = r
xx = r
y = -1
yy = -1
t# = 0
while x > y
inc y
cur_dist# = E2DC_Distance#(r, y)
if cur_dist# < t# then dec x
p# = ((cy-x) - (cx-r)) / height#
c = E2DC_Get_LO_Color(color1, color2, p#)
ink c, 0
box cx-y+offsetX, cy-x+offsetY, cx+y+ow+offsetX, cy-x+1+offsetY
p# = ((cy-y) - (cx-r)) / height#
c = E2DC_Get_LO_Color(color1, color2, p#)
ink c, 0
box cx-x+offsetX, cy-y+offsetY, cx+x+ow+offsetX, cy-y+1+offsetY
p# = ((cy+y+oh)-(cx-r)) / height#
c = E2DC_Get_LO_Color(color1, color2, p#)
ink c, 0
box cx-x+offsetX, cy+y+oh+offsetY, cx+x+ow+offsetX, cy+y+oh+1+offsetY
p# = ((cy+x+oh)-(cx-r)) / height#
c = E2DC_Get_LO_Color(color1, color2, p#)
ink c, 0
box cx-y+offsetX, cy+x+oh+offsetY, cx+y+ow+offsetX, cy+x+oh+1+offsetY
t# = cur_dist#
endwhile
c1 = E2DC_Get_LO_Color(color1, color2, (cy-(cx-r))/height#)
c2 = E2DC_Get_LO_Color(color1, color2, ((y2-r)-(cx-r))/height#)
box cx-r+offsetX, cy+offsetY, x2+offsetX, y2-r+offsetY, c2, c1, c2, c1
endfunction
REM **************************************************
REM Draws a filled-in circle with specified color
REM The main difference here is the alpha channel of
REM the color will be used when drawing
REM **************************************************
function E2DC_Fill_Circle_Alpha(x,y,r,color)
for yy = y-r to y
for xx = x-r to x
d# = (xx-x)*(xx-x) + (yy-y)*(yy-y)
if d# <= r*r
box xx,yy,x+(x-xx)+1,yy+1
if yy <> y then box xx,y+(y-yy),x+(x-xx)+1,y+(y-yy)+1,color,color,color,color
exit
endif
next xx
next yy
endfunction
REM **************************************************
REM Draws an anti-aliased circle
REM Based on Xiaolin Wu method
REM This method assume the background color is black
REM **************************************************
function E2DC_Circle_AA(cx as integer, cy as integer, r as integer, color as dword)
local alpha1 as dword
local alpha2 as dword
x = r
xx = r
y = -1
yy = -1
t# = 0
lock pixels
while x > y
inc y
cur_dist# = E2DC_Distance#(r, y)
if cur_dist# < t# then dec x
rem anti-aliased pixels inside the circle
c = 127*cur_dist# : alpha1 = E2DC_Get_LO_Color(rgb(0,0,0), color, c/255.0)
rem anit-aliased pixels outside the circle
c = 127 - c : alpha2 = E2DC_Get_LO_Color(rgb(0,0,0), color, c/255.0)
rem octant 1
E2DC_Dot(cx-y, cy-x, color)
E2DC_Dot(cx-y, cy-x-1, alpha2)
E2DC_Dot(cx-y, cy-x+1, alpha1)
rem octant 2
E2DC_Dot(cx-x, cy-y, color)
E2DC_Dot(cx-x-1, cy-y, alpha2)
E2DC_Dot(cx-x+1, cy-y, alpha1)
rem octant 3
E2DC_Dot(cx-x, cy+y, color)
E2DC_Dot(cx-x-1, cy+y, alpha2)
E2DC_Dot(cx-x+1, cy+y, alpha1)
rem octant 4
E2DC_Dot(cx-y, cy+x, color)
E2DC_Dot(cx-y, cy+x+1, alpha2)
E2DC_Dot(cx-y, cy+x-1, alpha1)
rem octant 5
E2DC_Dot(cx+y, cy+x, color)
E2DC_Dot(cx+y, cy+x-1, alpha1)
E2DC_Dot(cx+y, cy+x+1, alpha2)
rem octant 6
E2DC_Dot(cx+x, cy+y, color)
E2DC_Dot(cx+x-1, cy+y, alpha1)
E2DC_Dot(cx+x+1, cy+y, alpha2)
rem octant 7
E2DC_Dot(cx+x, cy-y, color)
E2DC_Dot(cx+x-1, cy-y, alpha1)
E2DC_Dot(cx+x+1, cy-y, alpha2)
rem octant 8
E2DC_Dot(cx+y, cy-x, color)
E2DC_Dot(cx+y, cy-x-1, alpha2)
E2DC_Dot(cx+y, cy-x+1, alpha1)
t# = cur_dist#
endwhile
unlock pixels
endfunction
REM **************************************************
REM Draws an anti-aliased circle with alpha values
REM Based on Xiaolin Wu method
REM Unlike the above method, this uses true alpha
REM values but is slower
REM **************************************************
function E2DC_Circle_AA_Alpha(cx as integer, cy as integer, r as integer, color as dword)
local alpha1 as dword
local alpha2 as dword
red = rgbr(color)
green = rgbg(color)
blue = rgbb(color)
x = r
xx = r
y = -1
yy = -1
t# = 0
while x > y
inc y
cur_dist# = E2DC_Distance#(r, y)
if cur_dist# < t# then dec x
rem anti-aliased pixels inside the circle
c = 127*cur_dist# : alpha1 = E2DC_ARGB(c, red, green, blue)
rem anit-aliased pixels outside the circle
c = 127 - c : alpha2 = E2DC_ARGB(c, red, green, blue)
rem octant 1
box cx-y, cy-x,cx-y+1, cy-x+1, color, color, color, color
box cx-y, cy-x-1,cx-y+1, cy-x, alpha2, alpha2, alpha2, alpha2
box cx-y, cy-x+1,cx-y+1, cy-x+2, alpha1, alpha1, alpha1, alpha1
rem octant 2
box cx-x, cy-y,cx-x+1, cy-y+1, color, color, color, color
box cx-x-1, cy-y, cx-x, cy-y+1, alpha2, alpha2, alpha2, alpha2
box cx-x+1, cy-y,cx-x+2, cy-y+1, alpha1, alpha1, alpha1, alpha1
rem octant 3
box cx-x, cy+y,cx-x+1, cy+y+1, color, color, color, color
box cx-x-1, cy+y, cx-x, cy+y+1, alpha2, alpha2, alpha2, alpha2
box cx-x+1, cy+y,cx-x+2, cy+y+1, alpha1, alpha1, alpha1, alpha1
rem octant 4
box cx-y, cy+x, cx-y+1, cy+x+1, color, color, color, color
box cx-y, cy+x+1,cx-y+1, cy+x+2, alpha2, alpha2, alpha2, alpha2
box cx-y, cy+x-1,cx-y+1, cy+x, alpha1, alpha1, alpha1, alpha1
rem octant 5
box cx+y, cy+x,cx+y+1, cy+x+1, color, color, color, color
box cx+y, cy+x-1,cx+y+1, cy+x, alpha1, alpha1, alpha1, alpha1
box cx+y, cy+x+1,cx+y+1, cy+x+2, alpha2, alpha2, alpha2, alpha2
rem octant 6
box cx+x, cy+y,cx+x+1, cy+y+1, color, color, color, color
box cx+x-1, cy+y,cx+x, cy+y+1, alpha1, alpha1, alpha1, alpha1
box cx+x+1, cy+y,cx+x+2, cy+y+1, alpha2, alpha2, alpha2, alpha2
rem octant 7
box cx+x, cy-y, cx+x+1, cy-y+1, color, color, color, color
box cx+x-1, cy-y,cx+x, cy-y+1, alpha1, alpha1, alpha1, alpha1
box cx+x+1, cy-y,cx+x+2, cy-y+1, alpha2, alpha2, alpha2, alpha2
rem octant 8
box cx+y, cy-x,cx+y+1, cy-x+1, color, color, color, color
box cx+y, cy-x-1,cx+y+1, cy-x, alpha2, alpha2, alpha2, alpha2
box cx+y, cy-x+1,cx+y+1, cy-x+2, alpha1, alpha1, alpha1, alpha1
t# = cur_dist#
endwhile
endfunction
REM **************************************************
REM Draws an outline of a box with anti-aliased
REM rounded corners as based on Xialon Wu's method
REM This method assume the background color is black
REM **************************************************
function E2DC_Rounded_Box_AA_Outline(cx as integer, cy as integer, x2 as integer, y2 as integer, r as integer, color as dword)
local alpha1 as dword
local alpha2 as dword
cx = cx+r
cy = cy+r
ow = x2-cx-r
oh = y2-cy-r
x = r
xx = r
y = -1
yy = -1
t# = 0
ink color,0
box cx, cy-r, x2-r, cy-r+1
box cx, y2, x2-r, y2+1
box cx-r, cy, cx-r+1, y2-r
box x2, cy, x2+1, y2-r
lock pixels
while x > y
inc y
cur_dist# = E2DC_Distance#(r, y)
if cur_dist# < t# then dec x
rem anti-aliased pixels inside the circle
c = 127*cur_dist# : alpha1 = E2DC_Get_LO_Color(rgb(0,0,0), color, c/255.0)
rem anit-aliased pixels outside the circle
c = 127 - c : alpha2 = E2DC_Get_LO_Color(rgb(0,0,0), color, c/255.0)
rem octant 1
E2DC_Dot(cx-y, cy-x, color)
if cy-x > cy-r then E2DC_Dot(cx-y, cy-x-1, alpha2)
E2DC_Dot(cx-y, cy-x+1, alpha1)
rem octant 2
E2DC_Dot(cx-x, cy-y, color)
if cx-x > cx-r then E2DC_Dot(cx-x-1, cy-y, alpha2)
E2DC_Dot(cx-x+1, cy-y, alpha1)
rem octant 3
E2DC_Dot(cx-x, cy+y+oh, color)
if cx-x > cx-r then E2DC_Dot(cx-x-1, cy+y+oh, alpha2)
E2DC_Dot(cx-x+1, cy+y+oh, alpha1)
rem octant 4
E2DC_Dot(cx-y, cy+x+oh, color)
if cy+x+oh < y2 then E2DC_Dot(cx-y, cy+x+1+oh, alpha2)
E2DC_Dot(cx-y, cy+x-1+oh, alpha1)
rem octant 5
E2DC_Dot(cx+y+ow, cy+x+oh, color)
if cy+x+oh < y2 then E2DC_Dot(cx+y+ow, cy+x+1+oh, alpha2)
E2DC_Dot(cx+y+ow, cy+x-1+oh, alpha1)
rem octant 6
E2DC_Dot(cx+x+ow, cy+y+oh, color)
if cx+x+ow < x2 then E2DC_Dot(cx+x+1+ow, cy+y+oh, alpha2)
E2DC_Dot(cx+x-1+ow, cy+y+oh, alpha1)
rem octant 7
E2DC_Dot(cx+x+ow, cy-y, color)
if cx+x+ow < x2 then E2DC_Dot(cx+x+1+ow, cy-y, alpha2)
E2DC_Dot(cx+x-1+ow, cy-y, alpha1)
rem octant 8
E2DC_Dot(cx+y+ow, cy-x, color)
if cy-x > cy-r then E2DC_Dot(cx+y+ow, cy-x-1, alpha2)
E2DC_Dot(cx+y+ow, cy-x+1, alpha1)
t# = cur_dist#
endwhile
unlock pixels
endfunction
REM **************************************************
REM Draws an anti-aliased circle with alpha values
REM Based on Xiaolin Wu method
REM **************************************************
function E2DC_Rounded_Box_AA_Alpha_Outline(cx as integer, cy as integer, x2 as integer, y2 as integer, r as integer, color as dword)
local alpha1 as dword
local alpha2 as dword
cx = cx+r
cy = cy+r
ow = x2-cx-r-1
oh = y2-cy-r-1
x = r
xx = r
y = -1
yy = -1
t# = 0
red = rgbr(color)
green = rgbg(color)
blue = rgbb(color)
box cx, cy-r, x2-r, cy-r+1, color, color, color, color
box cx, y2-1, x2-r, y2, color, color, color, color
box cx-r, cy, cx-r+1, y2-r, color, color, color, color
box x2-1, cy, x2, y2-r, color, color, color, color
while x > y
inc y
cur_dist# = E2DC_Distance#(r, y)
if cur_dist# < t# then dec x
c = 127*cur_dist# : alpha1 = E2DC_ARGB(c,red, green, blue)
c = 127 - c : alpha2 = E2DC_ARGB(c,red, green, blue)
rem octant 1
box cx-y, cy-x, cx-y+1, cy-x+1, color, color, color, color
if cy-x > cy-r then box cx-y, cy-x-1, cx-y+1, cy-x, alpha2, alpha2, alpha2, alpha2
box cx-y, cy-x+1, cx-y+1, cy-x+2, alpha1, alpha1, alpha1, alpha1
rem octant 2
box cx-x, cy-y, cx-x+1, cy-y+1, color, color, color, color
if cx-x > cx-r then box cx-x-1, cy-y, cx-x, cy-y+1, alpha2, alpha2, alpha2, alpha2
box cx-x+1, cy-y, cx-x+2, cy-y+1, alpha1, alpha1, alpha1, alpha1
rem octant 3
box cx-x, cy+y+oh, cx-x+1, cy+y+oh+1, color, color, color, color
if cx-x > cx-r then box cx-x-1, cy+y+oh, cx-x, cy+y+oh+1, alpha2, alpha2, alpha2, alpha2
box cx-x+1, cy+y+oh, cx-x+2, cy+y+oh+1, alpha1, alpha1, alpha1, alpha1
rem octant 4
box cx-y, cy+x+oh, cx-y+1, cy+x+oh+1, color, color, color, color
if cy+x+oh < y2-1 then box cx-y, cy+x+1+oh, cx-y+1, cy+x+2+oh, alpha2, alpha2, alpha2, alpha2
box cx-y, cy+x-1+oh, cx-y+1, cy+x+oh, alpha1, alpha1, alpha1, alpha1
rem octant 5
box cx+y+ow, cy+x+oh, cx+y+1+ow, cy+x+1+oh, color, color, color, color
box cx+y+ow, cy+x-1+oh, cx+y+1+ow, cy+x+oh, alpha1, alpha1, alpha1, alpha1
if cy+x+oh < y2-1 then box cx+y+ow, cy+x+1+oh, cx+y+1+ow, cy+x+2+oh, alpha2, alpha2, alpha2, alpha2
rem octant 6
box cx+x+ow, cy+y+oh, cx+x+1+ow, cy+y+1+oh, color, color, color, color
box cx+x-1+ow, cy+y+oh, cx+x+ow, cy+y+1+oh, alpha1, alpha1, alpha1, alpha1
if cx+x+ow < x2-1 then box cx+x+1+ow, cy+y+oh, cx+x+2+ow, cy+y+1+oh, alpha2, alpha2, alpha2, alpha2
rem octant 7
box cx+x+ow, cy-y, cx+x+1+ow, cy-y+1, color, color, color, color
box cx+x-1+ow, cy-y, cx+x+ow, cy-y+1, alpha1, alpha1, alpha1, alpha1
if cx+x+ow < x2-1 then box cx+x+1+ow, cy-y, cx+x+2+ow, cy-y+1, alpha2, alpha2, alpha2, alpha2
rem octant 8
box cx+y+ow, cy-x, cx+y+1+ow, cy-x+1, color, color, color, color
if cy-x > cy-r then box cx+y+ow, cy-x-1, cx+y+1+ow, cy-x, alpha2, alpha2, alpha2, alpha2
box cx+y+ow, cy-x+1, cx+y+1+ow, cy-x+2, alpha1, alpha1, alpha1, alpha1
t# = cur_dist#
endwhile
endfunction
REM **************************************************
REM Fills a circle with center [cx1,cy1] and radius r1
REM with a radial gradient starting from [cx2,cy2] and
REM a radius of r2.
REM **************************************************
function E2DC_Fill_Circle_Gradient_Radial(cx1,cy1,r1,cx2,cy2,r2,gradient1,gradient2)
for x = cx1-r1 to cx1+r1
for y = cy1-r1 to cy1+r1
if (x-cx1)^2 + (y-cy1)^2 <= r1^2
p# = ((cx2-x)^2 + (cy2-y)^2+0.0) / r2^2
if p# > 1 then p#=1.0
ink E2DC_Get_LO_Color(gradient1, gradient2, p#), 0
box x,y,x+1,y+1
endif
next y
next x
endfunction
REM **************************************************
REM Fills a circle with center [cx1,cy1] and radius r1
REM with a radial gradient starting from [cx2,cy2] and
REM a radius of r2.
REM **************************************************
function E2DC_Fill_Circle_Gradient_Radial_Alpha(cx1,cy1,r1,cx2,cy2,r2,gradient1,gradient2)
for x = cx1-r1 to cx1+r1
for y = cy1-r1 to cy1+r1
if (x-cx1)^2 + (y-cy1)^2 <= r1^2
p# = ((cx2-x)^2 + (cy2-y)^2+0.0) / r2^2
if p# > 1 then p#=1.0
color = E2DC_Get_LO_Color(gradient1, gradient2, p#)
box x,y,x+1,y+1, color,color,color,color
endif
next y
next x
endfunction
REM **************************************************
REM Returns a linear interpolated color between base
REM color and target color. Percent ranges from 0 to 1
REM **************************************************
function E2DC_Get_LO_Color(base as dword, target as dword, percent# as float)
br = rgbr(base)
bg = rgbg(base)
bb = rgbb(base)
ba = base >> 24
tr = rgbr(target)
tg = rgbg(target)
tb = rgbb(target)
ta = target >> 24
tr = br + (tr-br)*percent#
tg = bg + (tg-bg)*percent#
tb = bb + (tb-bb)*percent#
ta = ba + (ta-ba)*percent#
color = E2DC_ARGB(ta,tr,tg,tb)
endfunction color
REM **************************************************
REM Returns a color with an alpha value
REM **************************************************
function E2DC_ARGB(a,r,g,b)
local c as dword
c = (a*16777216)+(r*65536)+(g*256)+b
endfunction c
REM **************************************************
REM Draws a point to screen
REM **************************************************
function E2DC_Dot(x as integer, y as integer, color as dword )
if x > 0 and x < screen width() and y > 0 and y < screen height()
offset = get pixels pointer()
pitch = get pixels pitch()
bitsPerPixel = bitmap depth(0)/8
pointer = offset + y*pitch + x*bitsPerPixel
*pointer = color
endif
endfunction
REM **************************************************
REM Gets the color drawn on screen at [x,y]
REM **************************************************
function E2DC_Pick(x as integer, y as integer)
pointer = get pixels pointer() + y*get pixels pitch() + x*(bitmap depth(0)/8)
c = *pointer
endfunction c
REM **************************************************
REM Returns fractional part of distance
REM * Needed for Xiaolin Wu functions
REM **************************************************
function E2DC_Distance#(a, b)
real# = sqrt(a^2 - b^2)
d# = ceil(real#) - real#
endfunction d#
REM **************************************************
REM Just a little helper function
REM **************************************************
function fract#(x as float)
a# = x - int(x)
endfunction a#
"You're not going crazy. You're going sane in a crazy world!" ~Tick