March 01, 2021, 11:13:09 PM

Author Topic: [bb] Deformation FX by Matt Merkulov [ 1+ years ago ]  (Read 474 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Deformation FX by Matt Merkulov [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : Deformation FX
Author : Matt Merkulov
Posted : 1+ years ago

Description : From <a href="http://blitzetcetera.org/" target="_blank">Blitz et cetera[/url] article
Image used:


Code :
Code: BlitzBasic
  1. ;Image FX:  Constriction,  whirl and ripple by Matt Merkulov
  2.  
  3. Const xsiz = 640, ysiz = 480
  4. Global ib, x2#, y2#, r, g, b
  5.  
  6. Const prec = 1,  bf = 0,  fx = 1
  7.  
  8. Const stp# = 1.0 / prec,  div = prec * prec
  9.  
  10. Graphics xsiz, ysiz, 32
  11.  
  12. i = LoadImage("image2.jpg")
  13. ib = ImageBuffer(i)
  14. For y# = 0 To ysiz - 1
  15.  For x# = 0 To xsiz - 1
  16.   r = 0: g = 0: b = 0
  17.   For xx# = 0 To .9999 Step stp#
  18.    For yy# = 0 To .9999 Step stp#
  19.     x2# = x# + xx#
  20.     y2# = y# + yy#
  21.     Select fx
  22.      Case 1;constriction
  23.       dx# = x2# - 460.0
  24.       dy# = y2# - 360.0
  25.       rad# = Sqr(dx# * dx# + dy# * dy#)
  26.       If rad# = 0 Then rad# = 1
  27.       If rad# < 100.0 Then
  28.        x2# = dx# * (.5 + 50.0 / rad#) + 460.0
  29.        y2# = dy# * (.5 + 50.0 / rad#) + 360.0
  30.       End If
  31.      Case 2;whirl
  32.       x2# = x2# - 320.0
  33.       y2# = y2# - 240.0
  34.       ang# = Sqr(x2# * x2# + y2# * y2#) * .3 - 90;"unwrapping"
  35.     ;ang# = 360 / (Sqr(x2# * x2# + y2# * y2#) * .05 + 1);"wrapping"
  36.       xx2# = x2#
  37.       x2# = x2# * Cos(ang#) + y2# * Sin(ang#)
  38.       y2# = y2# * Cos(ang#) - xx2# * Sin(ang#)
  39.       x2# = x2# + 320.0
  40.       y2# = y2# + 240.0
  41.      Case 3;ripple
  42.       dx# = x2# - 320.0
  43.       dy# = y2# - 240.0
  44.       ang# = Sqr(dx# * dx# + dy# * dy#) * 4
  45.     ;x2# = x2# - Cos(ang#) * 15
  46.       y2# = y2# - Sin(ang#) * 15
  47.     End Select
  48.     pixelcol
  49.    Next
  50.   Next
  51.   r = r / div
  52.   g = g / div
  53.   b = b / div
  54.   WritePixel x#, y#, r Shl 16 + g Shl 8 + b
  55.  Next
  56. Next
  57.  
  58. WaitKey: End
  59.  
  60. Function pixelcol()
  61. If x2# < 0 Or x2# >= xsiz Or y2# < 0 Or y2# >= ysiz Then Return
  62. xx = Int(x2# - .5)
  63. yy = Int(y2# - .5)
  64. p00 = ReadPixel(xx, yy, ib)
  65. If bf Then
  66.  p01 = ReadPixel(xx, yy + 1, ib)
  67.  p10 = ReadPixel(xx + 1, yy, ib)
  68.  p11 = ReadPixel(xx + 1, yy + 1, ib)
  69.  dx2# = x2# - xx
  70.  dx1# = 1.0 - dx2#
  71.  r1# = dx1# * (p00 Shr 16 And 255) + dx2# * (p10 Shr 16 And 255)
  72.  g1# = dx1# * (p00 Shr 8 And 255) + dx2# * (p10 Shr 8 And 255)
  73.  b1# = dx1# * (p00 And 255) + dx2# * (p10 And 255)
  74.  r2# = dx1# * (p01 Shr 16 And 255) + dx2# * (p11 Shr 16 And 255)
  75.  g2# = dx1# * (p01 Shr 8 And 255) + dx2# * (p11 Shr 8 And 255)
  76.  b2# = dx1# * (p01 And 255) + dx2# * (p11 And 255)
  77.  dx2# = y2# - yy
  78.  dx1# = 1.0 - dx2#
  79.  r = r + Int(dx1# * r1# + dx2# * r2#)
  80.  g = g + Int(dx1# * g1# + dx2# * g2#)
  81.  b = b + Int(dx1# * b1# + dx2# * b2#)
  82. Else
  83.  r = r + (p00 Shr 16 And 255)
  84.  g = g + (p00 Shr 8 And 255)
  85.  b = b + (p00 And 255)
  86. End If
  87. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal