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 |