December 03, 2020, 07:46:04 PM

Author Topic: [bb] Very cool rain/water efect on cam by Nate the Great [ 1+ years ago ]  (Read 1038 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Very cool rain/water efect on cam
Author : Nate the Great
Posted : 1+ years ago

Description : this is a pretty cool effect for blitz plus and b3d (although im not sure why you would need rain on the camera in 2d :p )  i just threw this together so there is a major bug to look out for.  its hard to describe but look at the bottom half of the drop and you will see it.  if anyone knows how to get rid of that bug do tell please :) enjoy

Code :
Code: BlitzBasic
  1. ;VERY cool magnifying glass demo.
  2.  
  3. Graphics 640,480,0,2
  4. HidePointer()
  5. img = CreateImage(640,480)
  6. SetBuffer ImageBuffer(img)
  7. SeedRnd(22432)
  8. For x = 1 To 9000
  9. Color Rnd(255),Rnd(255),Rnd(255)
  10. Rect Rnd(640),Rnd(480),Rnd(20),Rnd(20),1
  11. Next
  12.  
  13.  
  14.  
  15.  
  16. Global dimg = CreateImage(150,150)
  17.  
  18.  
  19. SetBuffer BackBuffer()
  20.  
  21.  
  22. While Not KeyDown(1)
  23. Cls
  24.  
  25. DrawImage img,(-(MouseX())+320)/3,(-(MouseY()/1)+240)/3
  26. drop(MouseX(),MouseY(),50,1)
  27.  
  28.  
  29.  
  30. Flip False
  31. Wend
  32. End
  33.  
  34.  
  35. Function drop(x,y,r,s# = 1)
  36.  
  37. LockBuffer ImageBuffer(dimg)
  38. LockBuffer BackBuffer()
  39.  
  40. For x1 = -r To r
  41.         For y1 = -r To r
  42.                 dist# = Sqr(x1*x1 + y1*y1)
  43.                 If dist# <= r Then
  44.                        
  45.                         WritePixelFast1 x1+r,y1+r,ReadPixelFast1(x1*(dist#/r*s#)+x,y1*(dist#/r*s#)+y),ImageBuffer(dimg)
  46.                 EndIf
  47.         Next
  48. Next
  49.  
  50.  
  51. UnlockBuffer BackBuffer()
  52. UnlockBuffer ImageBuffer(dimg)
  53. Color 0,0,0
  54. Oval x-r+1,y-r+1,2*r-1,2*r-1,1
  55. DrawImage dimg,x-r,y-r
  56.  
  57. SetBuffer ImageBuffer(dimg)
  58. Color 0,0,0
  59. Rect 0,0,151,151,1
  60. SetBuffer BackBuffer()
  61.  
  62. End Function
  63.  
  64.  
  65. Function writepixelfast1(x,y,col,buffer)
  66.  
  67. If x > -1 And y > -1 Then
  68.         If x < GraphicsWidth()-1 And y < GraphicsHeight()-1 Then
  69.                 WritePixelFast x,y,col,buffer
  70.         EndIf
  71. EndIf
  72.  
  73. End Function
  74.  
  75.  
  76. Function readpixelfast1(x,y)
  77.  
  78. If x > 0 And y > 0 Then
  79.         If x < GraphicsWidth() And y < GraphicsHeight() Then
  80.                 Return(ReadPixelFast(x,y))
  81.         EndIf
  82. EndIf
  83.  
  84. Return 0
  85.  
  86. End Function


Comments :


Nate the Great(Posted 1+ years ago)

 ok figured it out :p
Code: [Select]
;VERY cool magnifying glass demo.

Graphics 640,480,0,2
HidePointer()
img = CreateImage(640,480)
SetBuffer ImageBuffer(img)
SeedRnd(22432)
For x = 1 To 9000
Color Rnd(255),Rnd(255),Rnd(255)
Rect Rnd(640),Rnd(480),Rnd(20),Rnd(20),1
Next




Global dimg = CreateImage(150,150)


SetBuffer BackBuffer()


While Not KeyDown(1)
Cls

DrawImage img,(-(MouseX())+320)/3,(-(MouseY()/1)+240)/3
drop(MouseX(),MouseY(),50,1)



Flip False
Wend
End


Function drop(x,y,r,s# = 1)

LockBuffer ImageBuffer(dimg)
LockBuffer BackBuffer()

For x1 = -r To r
For y1 = -r To r
dist# = Sqr(x1*x1 + y1*y1)
If dist# <= r Then

WritePixelFast1 x1+r,y1+r,ReadPixelFast1(x1*(dist#/r*s#)+x,y1*(dist#/r*s#)+y),ImageBuffer(dimg)
EndIf
Next
Next


UnlockBuffer BackBuffer()
UnlockBuffer ImageBuffer(dimg)
Color 0,0,0
Oval x-r+1,y-r+1,2*r-1,2*r-1,1
DrawImage dimg,x-r,y-r

SetBuffer ImageBuffer(dimg)
Color 0,0,0
Rect 0,0,151,151,1
SetBuffer BackBuffer()

End Function


Function writepixelfast1(x,y,col,buffer)

If x > -1 And y > -1 Then
If x < GraphicsWidth()-1 And y < GraphicsHeight()-1 Then
WritePixelFast x,y,col,buffer
EndIf
EndIf

End Function


Function readpixelfast1(x,y)

If x > 0 And y > 0 Then
If x < GraphicsWidth() And y < GraphicsHeight() Then
Return(ReadPixelFast(x,y))
EndIf
EndIf

Return 0

End Function



Stevie G(Posted 1+ years ago)

 Can you not edit it?


Warner(Posted 1+ years ago)

 It looks very nice!


Nate the Great(Posted 1+ years ago)

 @stevie G... what do you mean?@warnerthanks. I was very surprised at how fast it was considering most things I make seem to slow down :)  I plan on using it as the mouse in some games with some other effects as welledit @stevie g: oh you mean this kind of editing.. oops forgot about that. will do [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal