Dissolve Image?
Blitz3D Forums/Blitz3D Programming/Dissolve Image?| 
 | ||
| Hi, I am trying to break an image into pixels and then blow them away as if the image was made of dust. Any ideas on how I can apply physics to blow the pixels realistically? Thanks. | 
| 
 | ||
| Types is mainly the magic behind. A 3D array with 2 fields on the 3rd dimension would work as well (current speed) | 
| 
 | ||
| You still need to move a lot of pixels, this could be slow: 800*600=480000 pixels to be moved. I think you need to do some smart speed optimations. EG: move only a part of them at one time. | 
| 
 | ||
| Have a look at big10p's exploding mesh demo... http://www.blitzbasic.com/codearcs/codearcs.php?code=680 | 
| 
 | ||
| Ok the best option is to get sprite candy you can do this with 1 line of code , nearly http://www.x-pressive.com/SpriteCandy check the great demo to see the effect in action http://www.x-pressive.com/Downloads/SpriteCandy_Demo.exe | 
| 
 | ||
| Here a very simple image to pixel explosion-ish I did ages ago. It's doesn't use physics but it should be fairly easy to adapt it to create an explosion effect. If it's the sort of thing you're after then let me know and I'll change it to something more realistic :) "space bar" to break up and "space bar" to reconstruct. 
Graphics 640,480
SeedRnd MilliSecs()
; variables
Const block_size = 3
restore_frames = 100
restore_count = restore_frames
image = LoadImage("image.bmp")
width = ImageWidth(image)
height = ImageHeight(image)
block_state = 2
; Wooohooo one type
Type pixel
	Field i
	Field x#
	Field y#
	Field sx#
	Field sy#
	Field rsx#
	Field rsy#
	Field mx#
	Field my#
End Type
; split the image up into ickle tiny blocks
SetBuffer ImageBuffer(image)
For count1 = 1 To height Step block_size
	For count2 = 1 To width Step block_size
		picture.pixel = New pixel
		picture\i = CreateImage(block_size, block_size)
		GrabImage picture\i,count2,count1
		picture\x# = ((320 - (width / 2))) + count2
		picture\sx# = picture\x#
		picture\y# = ((240 - (height / 2))) + count1
		picture\sy# = picture\y#
		picture\mx# = Rnd(-2.0,2.0)
		picture\my# = Rnd(-2.0,2.0)
	Next
Next
SetBuffer BackBuffer()
; main stuff
While Not KeyHit(1)
	Cls	
	
	; space bar sets block state - move blocks / restore blocks
	
	If KeyHit(57) Then
		If block_state = 0 Then block_state = 1
		If block_state = 2 Then block_state = 0
	End If
	; move the blocks about
	
	If block_state = 0 Then
		For picture.pixel = Each pixel
			picture\sx# = picture\sx# + picture\mx#
			picture\sy# = picture\sy# + picture\my#
			If picture\sx# < 0 - block_size Then picture\sx# = 639
			If picture\sx# > 639 Then picture\sx# = 0 - block_size
			If picture\sy# < 0 - block_size Then picture\sy# = 479
			If picture\sy# > 479 Then picture\sy# = 0 - block_size
			
			DrawBlock picture\i, picture\sx#, picture\sy#
		Next
	End If
	
	; how much do we move each pixel each frame to restore the image ? 
	
	If block_state = 1
		restore_count = 0
		For picture.pixel = Each pixel
			picture\rsx# = ((picture\x# - picture\sx#) / restore_frames)
			picture\rsy# = ((picture\y# - picture\sy#) / restore_frames)
		Next
		block_state = 2
	End If
	
	; restore the image
	
	If block_state = 2 Then
		If restore_count < restore_frames Then
			For picture.pixel = Each pixel
				DrawBlock picture\i,picture\sx#, picture\sy#
				picture\sx# = picture\sx# + picture\rsx#
				picture\sy# = picture\sy# + picture\rsy#
			Next
			restore_count = restore_count + 1
		Else
			For picture.pixel = Each pixel
				DrawBlock picture\i, picture\x#, picture\y#
			Next
		End If
	End If
	Flip
Wend
End
 | 
| 
 | ||
| Thanks for all the info, I have got something working now with physics, it's not fast but im not looking for a real time solution anyway. I`ll post a demo when my webspace is back up. |