January 16, 2021, 06:24:41 AM

### Author Topic: [bb] Image warping by Matt Merkulov [ 1+ years ago ]  (Read 485 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] Image warping by Matt Merkulov [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : Image warping
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. ;Free image transformation - point warping by Matt Merkulov
2.
3. ;Controls:
4. ; Drag mouse with left button pressed - from initial point position to resulting
5. ; Press right mouse button to render picture
6.
7. Type dot
8.  Field x#, y#, dx#, dy#
9. End Type
10.
11. Graphics 640, 480, 32, 2
12.
14. DrawBlock i, 0, 0
15.
16. For x = 0 To 639 Step 639
17.  For y = 0 To 479 Step 479
18.   d.dot = New dot
19.   dx = x
20.   dy = y
21.  Next
22. Next
23.
24. Repeat
25.  If MouseDown(1) And md = 0 Then
26.   md = 1
27.   d.dot = New dot
28.   dx = MouseX()
29.   dy = MouseY()
30.  End If
31.  If MouseDown(1) = 0 And md Then
32.   ddx = dx - MouseX()
33.   ddy = dy - MouseY()
34.   Line dx, dy, MouseX(), MouseY()
35.   md = 0
36.  End If
37.  If MouseDown(2) Then Exit
38. Forever
39.
40. For y = 0 To 479
41.  For x = 0 To 639
42.   vx# = 0
43.   vy# = 0
44.   k# = 0
45.   For d = Each dot
46.    dx# = x - dx
47.    dy# = y - dy
48.    r# = 1.0 / (dx# * dx# + dy# * dy# + .001)
49.    vx# = vx# + r# * ddx
50.    vy# = vy# + r# * ddy
51.    k# = k# + r#
52.   Next
53.   vx# = vx# / k#
54.   vy# = vy# / k#
55.   WritePixel x, y, ReadPixel(x + vx#, y + vy#, ImageBuffer(i))
56.  Next
57. Next
58. WaitKey