REM ***********************************************
REM Title: Radial Gradient
REM Author: Phaelax
REM Downloaded from: http://dbcc.zimnox.com/
REM ***********************************************
 
sync on
 
repeat
   cls
 
   if mouseclick() = 1
      mx = mousex()
      my = mousey()
   endif
 
   gradientFillCircle(150,150,50,mx,my,25,rgb(225,225,225),rgb(48,48,48))
 
   rem draw outline of circle
   ink rgb(255,0,0),0
   circle 150,150,50
 
   sync
until spacekey()
 
 
REM **************************************************
REM Fills 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 gradientFillCircle(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 getTransitionalColor(gradient1,gradient2,p#),0
            box x,y,x+1,y+1
         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 getTransitionalColor(base, target, percent#)
   br = rgbr(base)
   bg = rgbg(base)
   bb = rgbb(base)
   tr = rgbr(target)
   tg = rgbg(target)
   tb = rgbb(target)
   tr = br + (tr-br)*percent#
   tg = bg + (tg-bg)*percent#
   tb = bb + (tb-bb)*percent#
   color = rgb(tr,tg,tb)
endfunction color