November 28, 2020, 11:26:12 AM

Author Topic: [bb] DrawCircularGradient function by WarpZone [ 1+ years ago ]  (Read 492 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : DrawCircularGradient function
Author : WarpZone
Posted : 1+ years ago

Description : 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. :)


Code :
Code: BlitzBasic
  1. Graphics3D 1024,768,32,2
  2. SetBuffer BackBuffer()
  3.  
  4. Repeat
  5. h#=Rand (256)
  6. w#=Rand (256)
  7. x#=Rand (256)
  8. y#=Rand (256)
  9. t1=MilliSecs()
  10. DrawCircularGradient(x#,y#,h#,w#)
  11. t2=MilliSecs()
  12. Color 255,255,255
  13. Text 0,580,"New gradient created.  Size is "+x#+" by "+y#+". Time To render:"+(t2-t1)+" ms"
  14. Flip()
  15. WaitKey()
  16. Color 0,0,0
  17. Text 0,580,"New gradient created.  Size is "+x#+" by "+y#+". Time To render:"+(t2-t1)+" ms"
  18. FreeImage img
  19.  
  20. Until KeyHit(1)
  21.  
  22. Function DrawCircularGradient(x#,y#,width#,height#)
  23. For rings=1 To width#
  24. If Width < Height Then greyness=((width-(rings*2))/(width# / 256)) Else greyness=((height-(rings*2))/(height# / 256))
  25. Color greyness,greyness,greyness
  26. Oval (x#+rings,y#+rings,width#-(rings*2),height#-(rings*2),1)
  27. Next
  28. Text 0,0, (width# / 256)
  29. End Function


Comments :


chwaga(Posted 1+ years ago)

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


Doggie(Posted 1+ years ago)

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


_PJ_(Posted 1+ years ago)

 This should be a little faster
Code: [Select]
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


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal