January 26, 2021, 05:48:03 AM

Author Topic: [bb] Gradient Line by DarkEagle [ 1+ years ago ]  (Read 402 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Gradient Line by DarkEagle [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Gradient Line
Author : DarkEagle
Posted : 1+ years ago

Description : gradient line

Code :
Code: BlitzBasic
  1. Function GradLine(x1,y1,x2,y2,r1,g1,b1,r2,g2,b2)
  2.  
  3. dx# = x2-x1
  4. dy# = y2-y1
  5.  
  6. m# = dy/dx
  7.  
  8. l# = Sqr(dx^2 + dy^2)
  9.  
  10. rinc# = (r2-r1)/l
  11. ginc# = (g2-g1)/l
  12. binc# = (b2-b1)/l
  13.  
  14. r# = r1
  15. g# = g1
  16. b# = b1
  17.  
  18. For x = x1 To x2
  19.         argb = (b Or (g Shl 8) Or (r Shl 16) Or ($ff000000))
  20.         WritePixel x,(m*x)+y1,argb
  21.         r = r + rinc
  22.         g = g + ginc
  23.         b = b + binc
  24. Next
  25.  
  26. End Function


Comments :


Sir Gak(Posted 1+ years ago)

 This can be speeded up phenomenally by using Lockbuffer and UnlockBuffer.  Using a 1000 reps loop, I measured over 32000 millseconds without LockBuffer.  When utilizing LockBuffer, the time drops to about 74 millseconds.Graphics 800,600GradLine(100,30,799,530,0,0,0,128,128,255)MouseWait()EndFunction GradLine(x1,y1,x2,y2,r1,g1,b1,r2,g2,b2)dx# = x2-x1dy# = y2-y1m# = dy/dxl# = Sqr(dx^2 + dy^2)rinc# = (r2-r1)/lginc# = (g2-g1)/lbinc# = (b2-b1)/lr# = r1g# = g1b# = b1timer#=MilliSecs()LockBuffer FrontBuffer()For loop=1 To 1000For x = x1 To x2   argb = (b Or (g Shl 8) Or (r Shl 16) Or ($ff000000))   WritePixel x,(m*x)+y1,argb   r = r + rinc   g = g + ginc   b = b + bincNextNextUnlockBuffer FrontBuffer()Print MilliSecs()-timerEnd Function


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal