[bb] Image warping by Matt Merkulov [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:40

Previous topic - Next topic

BlitzBot

Title : Image warping
Author : Matt Merkulov
Posted : 1+ years ago

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


Code :
Code (blitzbasic) Select
;Free image transformation - point warping by Matt Merkulov

;Controls:
; Drag mouse with left button pressed - from initial point position to resulting
; Press right mouse button to render picture

Type dot
 Field x#, y#, dx#, dy#
End Type

Graphics 640, 480, 32, 2

i = LoadImage("image2.jpg")
DrawBlock i, 0, 0

For x = 0 To 639 Step 639
 For y = 0 To 479 Step 479
  d.dot = New dot
  dx = x
  dy = y
 Next
Next

Repeat
 If MouseDown(1) And md = 0 Then
  md = 1
  d.dot = New dot
  dx = MouseX()
  dy = MouseY()
 End If
 If MouseDown(1) = 0 And md Then
  ddx = dx - MouseX()
  ddy = dy - MouseY()
  Line dx, dy, MouseX(), MouseY()
  md = 0
 End If
 If MouseDown(2) Then Exit
Forever

For y = 0 To 479
 For x = 0 To 639
  vx# = 0
  vy# = 0
  k# = 0
  For d = Each dot
   dx# = x - dx
   dy# = y - dy
   r# = 1.0 / (dx# * dx# + dy# * dy# + .001)
   vx# = vx# + r# * ddx
   vy# = vy# + r# * ddy
   k# = k# + r#
  Next
  vx# = vx# / k#
  vy# = vy# / k#
  WritePixel x, y, ReadPixel(x + vx#, y + vy#, ImageBuffer(i))
 Next
Next
WaitKey


Comments : none...