Fluid/Path-building thingy-jig

Blitz3D Forums/Blitz3D Programming/Fluid/Path-building thingy-jig

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

thanks.
this is so awesome for texture generation!
Press T to make a texture. You can fiddle with the constants too... for a long long time.
SeedRnd MilliSecs()
Graphics 800, 600, 0, 1


Global MAXX	= GraphicsWidth()
Global MAXY	= GraphicsHeight()

Const GRIDX			= 40
Const GRIDY			= 30
Const CELL			= 20
Const MIDCELL		= 10

Const NUM_PARTICLES = 4000
Const PARTICLE_TURN = 15
Const PARTICLE_SPEED= 3
Const GRID_TURN 	= 1

Const COLOR_ADD     = 30
Const TEX_SIZE      = 128


Dim grid(GRIDX, GRIDY)

For y = 0 To GRIDY - 1
For x = 0 To GRIDX - 1
	grid(x, y) = Rand(360)
Next
Next


Type p_dat
	Field x#, y#
	Field ang
End Type

Local p.p_dat

For n=0 To NUM_PARTICLES - 1
	p = New p_dat
	p\x = Rnd(0,MAXX-1)
	p\y = Rnd(0,MAXY-1)
	p\ang = Rnd(360)
Next

Repeat

	; Move particles
	For p.p_dat = Each p_dat
		gx = Int(p\x / CELL)
		gy = Int(p\y / CELL)
		
		g=grid(gx, gy)
		p\ang=anglemoveto(p\ang,g,PARTICLE_TURN)
		grid(gx, gy)=anglemoveto(g,p\ang,GRID_TURN)
		
		
		h# = Sin(p\ang) * PARTICLE_SPEED
		v# = Cos(p\ang) * PARTICLE_SPEED
		
		p\x = p\x + h#
		p\y = p\y + v#
		
		If Int(p\x) < 0 Then
			p\x = p\x + MAXX
		ElseIf Int(p\x) >= MAXX Then
			p\x = p\x - MAXX
		EndIf
		If Int(p\y) < 0 Then
			p\y = p\y + MAXY
		ElseIf Int(p\y) >= MAXY Then
			p\y = p\y - MAXY
		EndIf
	Next
	
	If KeyHit(28) Then
		Cls
	EndIf

	
	If KeyHit(57) Then
		For y = 0 To GRIDY - 1
		For x = 0 To GRIDX - 1
			grid(x, y) = turn * 90
		Next
		Next
		turn = turn + 1
		If turn>3 Then turn=0
	End If

	If KeyHit(19) Then
		Cls
		For y = 0 To GRIDY - 1
		For x = 0 To GRIDX - 1
			grid(x, y) = Rnd(360)
		Next
		Next
	End If
	
	;make texture
	If KeyHit(20) Then
		image=CreateImage(maxx,maxy)
		GrabImage image,0,0
		ResizeImage image,TEX_SIZE,TEX_SIZE
		Cls
		For y=0 To maxy/TEX_SIZE
			For x=0 To maxx/TEX_SIZE
				DrawImage image,x*TEX_SIZE,y*TEX_SIZE
			Next
		Next
		FlushKeys
		WaitKey
		FlushKeys
		Cls
	EndIf
	
	;draw
	LockBuffer
	For p = Each p_dat
		b=ReadPixel(p\x,p\y) And $FF
		If b<255-COLOR_ADD Then
			WritePixel p\x, p\y, b+COLOR_ADD
		EndIf
	Next
	UnlockBuffer
	
Until KeyHit(1)
End




;makes the angle a little closer to the targetangle and returns it
Function AngleMoveTo#(anglenow#,angletar#,amount#)

	amount=amount*Sgn(angletar-anglenow)

	If Abs(angletar-anglenow)>180 Then
		anglenow=anglenow-amount
	Else
		anglenow=anglenow+amount
	EndIf
	
	If anglenow<0 Then
		anglenow=anglenow+360
	ElseIf anglenow>360 Then
		anglenow=anglenow-360
	EndIf

	Return anglenow
End Function


Heres some textures I made. Isn't the top one freaky as hell? It looks like a zombie