Code archives/Graphics/Liquid Fun

This code has been declared by its author to be Public Domain code.

Download source code

Liquid Fun by djr2cool2002
Drag you mouse through some liquid
SetBuffer BackBuffer()

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

Dim WaveMap(4,MAXWIDTH,MAXHEIGHT)




While Not KeyDown(1)

	Cls	
	UpdateWaveMap()
	Color 255,0,0
	Plot MouseX(),MouseY()
	If MouseDown(1) Then WaveMap(CurrentTexture,MouseX(),MouseY())=DEPTH
	
	Flip 

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
			c = 100-WaveMap(CurrentTexture,x,y) And 255
			Color 0,0,c
			Plot x,y
		Next
	Next
			
	TempValue=CurrentTexture
	CurrentTexture=NextTexture
	NextTexture=TempValue
End Function

Comments

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


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


puki2006
Um, I wouldn't call it fast.


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


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


Perturbatio2006
for those interested, the same code in BMax:



Code Archives Forum