Ooops
January 23, 2021, 04:27:00 AM

Author Topic: [bb] Lens effect by BlitzSupport [ 1+ years ago ]  (Read 524 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Lens effect by BlitzSupport [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Lens effect
Author : BlitzSupport
Posted : 1+ years ago

Description : Converted from source submitted in the early days of Blitz 2D -- I've lost the contributor's details, but the code had Mali/Finesse listed as the original author...
 
Change "brick.bmp" to a suitable small tile image on your PC...


Code :
Code: BlitzBasic
  1. ; -----------------------------
  2. ; This MUST be included!!!
  3. ; -----------------------------
  4. lensDiameter = 60
  5. ; -----------------------------
  6. Dim Tfm  (lensDiameter * lensDiameter * 2)
  7. Dim Org  (lensDiameter * lensDiameter * 2, 3)
  8. Dim Dest (lensDiameter * lensDiameter * 2, 3)
  9. ; -----------------------------
  10.  
  11.  
  12. ; -----------------------------
  13. ;  Lens effect by maLi/FiNESSE,
  14. ;  ported to Blitz by someone
  15. ;  whose name I don't have
  16. ;  anymore (sorry!), converted
  17. ;  to use Read/WritePixelFast
  18. ;  by blitzsupport@guildhallleisure.com
  19. ; -----------------------------
  20.  
  21. Graphics 640, 480
  22. backpicture = LoadImage ("brick.bmp")
  23.  
  24. SetBuffer BackBuffer()
  25. MoveMouse GraphicsWidth () / 2, GraphicsHeight () / 2
  26.  
  27. CreateLens (lensDiameter, 15)
  28.  
  29. Repeat
  30.  
  31.         Cls
  32.         TileImage backpicture
  33.        
  34.         x = MouseX ()
  35.         y = MouseY ()
  36.        
  37.         If x => GraphicsWidth  () - lensDiameter Then x = GraphicsWidth  () - lensDiameter
  38.         If y >= GraphicsHeight () - lensDiameter Then y = GraphicsHeight () - lensDiameter
  39.  
  40.         DrawLens (x, y, lensDiameter)
  41.  
  42.         Flip
  43.  
  44. Until KeyDown (1)
  45.  
  46. End
  47.  
  48. Function CreateLens (diameter, magnification)
  49.         r = Int (diameter / 2)
  50.         s# = Sqr# (r * r - magnification * magnification)
  51.         For y = -r To -r + (diameter)
  52.                 For x = -r To r + (diameter - 1)
  53.                         If (x * x + y * y) >= (s * s)
  54.                                 a = x
  55.                                 b = y
  56.                         Else
  57.                                 z = Sqr# (r * r - x * x - y * y)
  58.                                 a = Int (x * magnification / z + 0.5)
  59.                                 b = Int (y * magnification / z + 0.5)
  60.                         EndIf
  61.                         Tfm (1 + (y + r) * diameter + (x + r)) = (b + r) * diameter + (a + r)
  62.                 Next
  63.         Next
  64. End Function
  65.  
  66. Function DrawLens (x, y, diameter)
  67.         LockBuffer BackBuffer ()
  68.         For i = x To (x + diameter) - 1
  69.                 For j = y To (y + diameter) - 1
  70.                         rgb = ReadPixelFast (i, j)
  71.                         Org (cx, 1) = rgb Shr 16 And %11111111
  72.                         Org (cx, 2) = rgb Shr 8 And %11111111
  73.                         Org (cx, 3) = rgb And %11111111
  74.                         cx = cx + 1
  75.                 Next
  76.         Next
  77.         cx = 1
  78.         For i = x To (x + diameter) - 1
  79.                 For j = y To (y + diameter) - 1
  80.                         Dest (cx, 1) = Org (Tfm (cx), 1)
  81.                         Dest (cx, 2) = Org (Tfm (cx), 2)
  82.                         Dest (cx, 3) = Org (Tfm (cx), 3)
  83.                         WritePixelFast i, j, Dest (cx, 3) Or (Dest (cx, 2) Shl 8) Or (Dest (cx, 1) Shl 16)
  84.                         Plot (i, j)
  85.                         cx = cx + 1
  86.                 Next
  87.         Next
  88.         UnlockBuffer BackBuffer ()
  89. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal