Ooops
January 26, 2021, 06:04:09 AM

Author Topic: [bb] Liquid Fun by djr2cool [ 1+ years ago ]  (Read 525 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Liquid Fun by djr2cool [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Liquid Fun
Author : djr2cool
Posted : 1+ years ago

Description : Drag you mouse through some liquid

Code :
Code: BlitzBasic
  1. SetBuffer BackBuffer()
  2.  
  3. Global CurrentTexture=1,NextTexture=0,TempValue=0
  4.  
  5. Const MAXWIDTH = 175
  6. Const MAXHEIGHT = 125
  7.  
  8.  
  9. ;Change these to get different results
  10. Global DEPTH=-800
  11. Global VISCOSITY=128  ;low the number the more water like, hight the number is more like oil
  12.  
  13. Dim WaveMap(4,MAXWIDTH,MAXHEIGHT)
  14.  
  15.  
  16.  
  17.  
  18. While Not KeyDown(1)
  19.  
  20.         Cls    
  21.         UpdateWaveMap()
  22.         Color 255,0,0
  23.         Plot MouseX(),MouseY()
  24.         If MouseDown(1) Then WaveMap(CurrentTexture,MouseX(),MouseY())=DEPTH
  25.        
  26.         Flip
  27.  
  28. Wend
  29.  
  30. Function UpdateWaveMap()
  31.         For y = 1 To MAXHEIGHT-1
  32.                 For x = 1 To MAXWIDTH-1
  33.                         n=(WaveMap(CurrentTexture,x-1,y)+WaveMap(CurrentTexture,x+1,y)+WaveMap(CurrentTexture,x,y-1)+WaveMap(CurrentTexture,x,y+1))/2 - WaveMap(NextTexture,x,y)
  34.                         n=n-n/VISCOSITY
  35.                         WaveMap(NextTexture,x,y)=n
  36.                         c = 100-WaveMap(CurrentTexture,x,y) And 255
  37.                         Color 0,0,c
  38.                         Plot x,y
  39.                 Next
  40.         Next
  41.                        
  42.         TempValue=CurrentTexture
  43.         CurrentTexture=NextTexture
  44.         NextTexture=TempValue
  45. End Function


Comments :


Ked(Posted 1+ years ago)

 Its good... kinda slow... but good nonetheless!   Sorry im so uh... "critical"....


Curtastic(Posted 1+ years ago)

 just change the plot to writepixel and use lockbuffer and its really fast, and cool :)


puki(Posted 1+ years ago)

 Um, I wouldn't call it fast.


Curtastic(Posted 1+ years ago)

 oh also take out cls and flip and setbuffer, lol then its lightning fast. really!


DjBigWorm(Posted 1+ years ago)

 This is pretty cool.  I like it thank you for sharing:)


Perturbatio(Posted 1+ years ago)

 for those interested, the same code in BMax:
Code: [Select]
Graphics 640,480,32

Global CurrentTexture=1,NextTexture=0,TempValue=0
Const MAXWIDTH = 175
Const MAXHEIGHT = 125

'Change these to get different results
Global DEPTH=-800
Global VISCOSITY=128  'low the number the more water like, hight the number is more like oil
Global WaveMap[4+1,MAXWIDTH+1,MAXHEIGHT+1]


While Not KeyDown(KEY_ESCAPE)

Cls
UpdateWaveMap()
If MouseDown(1) Then WaveMap(CurrentTexture,MouseX(),MouseY())=DEPTH
Flip False

Wend


Function UpdateWaveMap()
For y = 1 To MAXHEIGHT-1
For x = 1 To MAXWIDTH-1
n=(WaveMap(CurrentTexture,x-1,y)+WaveMap(CurrentTexture,x+1,y)+WaveMap(CurrentTexture,x,y-1)+WaveMap(CurrentTexture,x,y+1))/2 - WaveMap(NextTexture,x,y)
  n=n-n/VISCOSITY
WaveMap(NextTexture,x,y)=n
blue = 100-WaveMap(CurrentTexture,x,y) & 255

SetColor 0,0,blue
SetAlpha 0.9
Plot x,y

Next
Next

TempValue=CurrentTexture
CurrentTexture=NextTexture
NextTexture=TempValue
End Function


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal