Butterfly effect

Miscellaneous Forums/General Discussion/Butterfly effect

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.

i've been doing some research about this and i came up to this code:

read this first:
there are two universes; in universe 1 the balls are blue, in universe 2 the balls are green. both universes does not affect each other!

the green and the blue universes start at exactly the same beginning conditions, except that in the green one i moved ONE little ball ONE pixel.
and now watch, how this tiny change makes the differences of our life!!


Graphics 1024, 768, 32, 2
SetBuffer BackBuffer()
SeedRnd MilliSecs()

Type Ball1
	Field x#, y#
	Field vx#, vy#
	Field oldx#, oldy#
	Field fric#, mass#
End Type
Type Ball2
	Field x#, y#
	Field vx#, vy#
	Field oldx#, oldy#
	Field fric#, mass#
End Type

;Many balls
For i = 1 To 20
	x# = Rand(0, GraphicsWidth())
	y# = Rand(0, GraphicsHeight())
	fric# = Rnd(.9, 1)
	mass# = Rnd(1, 30)
	CreateBall1(x#, y#, fric#, mass#)
	CreateBall2(x#, y#, fric#, mass#)
Next
;The center ball
CreateBall1(GraphicsWidth() / 2, GraphicsHeight() / 2, 0, 100)
CreateBall2(GraphicsWidth() / 2, GraphicsHeight() / 2, 0, 100)
;The shifted ball
CreateBall1(100, 100, 0, 10)
CreateBall2(100, 101, 0, 10)

speed# = 1
Repeat
	Cls
	order = 1 - order
	If order Then
		UpdateBalls1(speed#)
		UpdateBalls2(speed#)
	Else
		UpdateBalls2(speed#)
		UpdateBalls1(speed#)
	EndIf
	Flip
Until KeyHit(1)
End

Function CreateBall1(x#, y#, fric#, mass#)
b.Ball1 = New Ball1
b\x# = x#
b\y# = y#
b\oldx# = b\x#
b\oldy# = b\y#
b\fric# = fric#
b\mass# = mass#
End Function

Function CreateBall2(x#, y#, fric#, mass#)
b.Ball2 = New Ball2
b\x# = x#
b\y# = y#
b\oldx# = b\x#
b\oldy# = b\y#
b\fric# = fric#
b\mass# = mass#
End Function

Function UpdateBalls1(speed# = 1)
Color 128, 128, 255
For b.Ball1 = Each Ball1
	b\vy# = 0
	b\vx# = 0
	For b2.Ball1 = Each Ball1
		xdiff# = b2\x# - b\x#
		ydiff# = b2\y# - b\y#
		dis# = Sqr(xdiff# * xdiff# + ydiff# * ydiff#)
		If Abs(dis#) > 0 Then
			b\vx# = b\vx# + (xdiff# / dis#) / (dis# * b\mass# / 10)
			b\vy# = b\vy# + (ydiff# / dis#) / (dis# * b\mass# / 10)
		End If
	Next
	tx# = b\x#
	ty# = b\y#
	b\x# = b\x# + b\x# * b\fric# - b\oldx# * b\fric# + b\vx# * speed#
	b\y# = b\y# + b\y# * b\fric# - b\oldy# * b\fric# + b\vy# * speed#
	If b\x# < 0 Then b\x# = 0
	If b\x# > GraphicsWidth() Then b\x# = GraphicsWidth()
	If b\y# < 0 Then b\y# = 0
	If b\y# > GraphicsHeight() Then b\y# = GraphicsHeight()
	b\oldx# = tx#
	b\oldy# = ty#
	
	Oval b\x# - b\mass# / 2, b\y# - b\mass# / 2, b\mass#, b\mass#
Next
End Function

Function UpdateBalls2(speed# = 1)
Color 128, 255, 128
For b.Ball2 = Each Ball2
	b\vy# = 0
	b\vx# = 0
	For b2.Ball2 = Each Ball2
		xdiff# = b2\x# - b\x#
		ydiff# = b2\y# - b\y#
		dis# = Sqr(xdiff# * xdiff# + ydiff# * ydiff#)
		If Abs(dis#) > 0 Then
			b\vx# = b\vx# + (xdiff# / dis#) / (dis# * b\mass# / 10)
			b\vy# = b\vy# + (ydiff# / dis#) / (dis# * b\mass# / 10)
		End If
	Next
	tx# = b\x#
	ty# = b\y#
	b\x# = b\x# + b\x# * b\fric# - b\oldx# * b\fric# + b\vx# * speed#
	b\y# = b\y# + b\y# * b\fric# - b\oldy# * b\fric# + b\vy# * speed#
	If b\x# < 0 Then b\x# = 0
	If b\x# > GraphicsWidth() Then b\x# = GraphicsWidth()
	If b\y# < 0 Then b\y# = 0
	If b\y# > GraphicsHeight() Then b\y# = GraphicsHeight()
	b\oldx# = tx#
	b\oldy# = ty#
	
	Oval b\x# - b\mass# / 2, b\y# - b\mass# / 2, b\mass#, b\mass#
Next
End Function


btw: the basic verlet code is not by myself....