November 30, 2020, 01:41:43 AM

### Author Topic: [bb] RIPPLE EFFECT by Nate the Great [ 1+ years ago ]  (Read 675 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] RIPPLE EFFECT by Nate the Great [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : RIPPLE EFFECT
Author : Nate the Great
Posted : 1+ years ago

Description : This is a program I made that adds a ripple effect to pictures.  I just thought this looked cool

Code :
Code: BlitzBasic
1. Graphics3D 1440,900,0,1
2.
3. ShowPointer()
4.
5. tex = LoadTexture("desktoppic1.bmp") ;PUT YOUR PICTURE HERE
6.
7. Type ripples
8.         Field x#,y#,dist#
9. End Type
10.
11.
12. cam = CreateCamera()
13. TurnEntity cam,90,0,0
14. MoveEntity cam,0,0,-2.9
15. CameraZoom cam, 5
16.
17.
18. lit = CreateLight()
19. TurnEntity lit,90,0,0;135,0,0
20.
21. square = CreateMesh()
22.
23. EntityPickMode square,2
24.
25. ripsurf = CreateSurface(square)
26.
27. numverts = 50
28.
29. Dim verts(numverts,numverts)
30.
31. For x# = 0 To numverts
32.         For y# = 0 To numverts
33.                 verts(x,y) = AddVertex(ripsurf,x#/numverts-.5,0,y#/numverts-.5,x#/numverts,-y#/numverts+1)
34.         Next
35. Next
36.
37. For y = 0 To numverts-1
38.         For x = 0 To numverts-1
41.         Next
42. Next
43.
44.
45.
46. ; We have a one-sided square with no normals defined. Now apply quick and dirty fix.
47.
48.
49.
50. ;EntityColor square,100,0,0
51.
52. ;EntityShininess square,1
53. ;EntityAlpha square,.5
54.
55. ;VertexCoords(ripsurf,843,VertexX(ripsurf,843),.03,VertexZ(ripsurf,843))
56.
57. TurnEntity square,0,0,0
58.
59. EntityTexture square,tex
60.
61.
62. While Not KeyDown(1)
63.         ;TurnEntity square,1,0,0
64.
65.         If MouseHit(1) Then
66.                 CameraPick cam,MouseX(),MouseY()
67.
68.                 r.ripples = New ripples
69.                 rx# = PickedX()
70.                 ry# = PickedZ()
71.                 rdist# = .0001
72.         EndIf
73.
74.
75.         For x = 0 To numverts
76.                 For y = 0 To numverts
77.                         VertexCoords(ripsurf,verts(x,y),VertexX( ripsurf,verts(x,y)) , 0, VertexZ( ripsurf,verts(x,y)))
78.                 Next
79.         Next
80.
81.         For r.ripples = Each ripples
82.
83.                 For x = 0 To numverts
84.                         For y = 0 To numverts
85.
86.                                 dist# = Sqr(      (   VertexX( ripsurf,verts(x,y) )   -   rx#   )^2                +                 (   VertexZ( ripsurf,verts(x,y) ) - ry#)^2 )
87.
88.                                 dif# = Abs(rdist#-dist#)
89.
90.                                 If dif# < .04 Then
91.                                         num = x*40 + y
92.                                         VertexCoords(ripsurf,verts(x,y),VertexX( ripsurf,verts(x,y)) ,.04-dif#, VertexZ( ripsurf,verts(x,y)))
93.                                 EndIf
94.
95.                         Next
96.                 Next
97.
98.                 rdist# = rdist# + .005
99.                 If rdist# => 1.5 Then
100.                         Delete r.ripples
101.                 EndIf
102.         Next
103.
104.
105.         UpdateNormals square
106.
107.         UpdateWorld()
108.         RenderWorld
109.
110.         Oval MouseX()-5,MouseY()-5,10,10
111.         Flip
112. wend

Nate the Great(Posted 1+ years ago)

oops sorry you may have to change the screen resolution and add your own picture instead of mine.

Stevie G(Posted 1+ years ago)

You've listed the code twice.

Nate the Great(Posted 1+ years ago)

oh... oops sorry it is fixed now

Zeotrope(Posted 1+ years ago)

Nice work nate.Works a treat!

Nate the Great(Posted 1+ years ago)

Thanks... I think I may try to use it in a very low poly game for effects like when there is an explosion... so far it works well in game, but it causes a significant slowdown from 100 fps to 50 fps but it is worth it for me.

SimplePortal 2.3.6 © 2008-2014, SimplePortal