Code archives/Graphics/DrawCircularGradient function

This code has been declared by its author to be Public Domain code.

Download source code

DrawCircularGradient function by WarpZone2005
I designed this code to be implemented just like the DrawOval command. It's not very fast, (over one second on my computer to draw a 512x512 gradient) but it is pixel-perfect. Not too useful for games, but great for a paint program.

Colors coming soon. Sorry if this seems redundant, but this was good practice for me. I know there are other gradient functions out there, but I had various problems using the ones I found, so I wrote my own.

Feel free to optimize teh noob's code. :)
Graphics3D 1024,768,32,2
SetBuffer BackBuffer()

Repeat
h#=Rand (256)
w#=Rand (256)
x#=Rand (256)
y#=Rand (256)
t1=MilliSecs()
DrawCircularGradient(x#,y#,h#,w#)
t2=MilliSecs()
Color 255,255,255
Text 0,580,"New gradient created.  Size is "+x#+" by "+y#+". Time To render:"+(t2-t1)+" ms"
Flip()
WaitKey()
Color 0,0,0
Text 0,580,"New gradient created.  Size is "+x#+" by "+y#+". Time To render:"+(t2-t1)+" ms"
FreeImage img

Until KeyHit(1)

Function DrawCircularGradient(x#,y#,width#,height#)
For rings=1 To width#
If Width < Height Then greyness=((width-(rings*2))/(width# / 256)) Else greyness=((height-(rings*2))/(height# / 256))
Color greyness,greyness,greyness
Oval (x#+rings,y#+rings,width#-(rings*2),height#-(rings*2),1)
Next
Text 0,0, (width# / 256)
End Function

Comments

chwaga2007
very soon, I see that :D. Thanks for the radial gradents anyways :D


Doggie2010
Looks like a black cat in a dark room lying on its' side with one eye open.


_PJ_2010
This should be a little faster
Function DrawCircularGradient(x#,y#,width#,height#)
	For r2=1 To width# Shr 1
		greyness=((width-r2)Shl 8)
		Color greyness,greyness,greyness
		Oval (x#+(r2 Shr 1),y#+(r2 Shr 1),width#-r2,height#-r2)
	Next
End Function



Code Archives Forum