Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP Monad Research
Message
 
To
19/01/2009 11:25:26
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01375100
Message ID:
01378622
Views:
19
Mike
I don't have an answer for your question beyond the mentioned advice of using rand(-1) in the beginning in order to obtain a random seed as the help tells.
But I'm having fun with your program by adding some changes: the rand(-1) at the beginning, randomizing the radious of the circles, changing their colors with a timer that has a random interval and by un-commenting the mapping of z line in your code.
I hope this somehow amuses you too and my apologies if it doesn't.
clear 
set decimals to 6

* For da loop
public lquit, lrestart, ndotcolor, nstep
lquit = .F.
lrestart = .T.
nstep = 0

SetupScreen()

* Setup Initial Conditions
public oAbsoluteMatter
RAND(-1)

_screen.BorderStyle = 0
_screen.FillStyle = 0 

ndotcolor1 = rand() *   16777215 
ndotcolor2 = rand() *   16777215 

_screen.FillColor = ndotcolor1 && iif(this.nType = 1, rgb(255, 0, 0), rgb(0, 0, 255))
_screen.ForeColor = ndotcolor2 && iif(this.nType = 1, rgb(255, 0, 0), rgb(0, 0, 255))

* Perform rules
do while not lquit
	if lRestart
		GetColors()

		oAbsoluteMatter = .NULL.
		oAbsoluteMatter = createobject("collection")
		rand(0)
		for ln1 = 1 to 30
			oAbsoluteMatter.Add(createobject("absoluteMatter", 1, ranstr() , ranstr() , ranstr() , ;
				ranstr() , ranstr() , ranstr() ))
		endfor 
		lRestart = .F.
	endif
        
	_screen.Caption = "VFP Monads Step: " + transform(nstep)

	RefreshScreen()	

	for each oA in oAbsoluteMatter
		oA.DoStuff()
	endfor 	
	nstep = nstep + 1
enddo
* end of program

function ranstr
return rand() * 100000 - 50000

*class definitions
define class absoluteMatter as Custom
	nType = 0
	nX = 0
	nY = 0
	nZ = 0
	nDx = 0
	nDy = 0
	nDz = 0

	procedure Init(tnType, tnX, tnY, tnZ, tnDx, tnDy, tnDz)
	
		this.nType = tnType
		this.nX = tnX
		this.nY = tnY
		this.nZ = tnZ
		this.nDx = tnDx
		this.nDy = tnDy
		this.nDz = tnDz
		
	endproc 
	
	procedure DoStuff

		* draw us visuall on the screen
*		?str(this.nType) + str(this.nX) + str(this.nY)
		_screen.Circle(GetRandRadious(), this.nX / n_scale + x_offset, this.nY / n_scale + y_offset)
* This is for mapping z
		_screen.Circle(GetRandRadious(), this.nZ / n_scale + x_offset, this.nY / n_scale + y_offset)

	
		* move inertially
		this.nX = this.nX + this.nDx
		this.nY = this.nY + this.nDy
		this.nZ = this.nZ + this.nDz
		
		* see if there's anything to interact with
			for each oB in oAbsoluteMatter
				lnDx = oB.nDx
				lnDy = oB.nDy
				lnDz = oB.nDz
				oB.nDx = this.nDx
				oB.nDy = this.nDy
				oB.nDz = this.nDz
				this.nDx = lnDx
				this.nDy = lnDy
				this.nDz = lnDz
			endfor 
	
	endproc
enddefine


function SetupScreen
	public n_scale, x_offset, y_offset
	n_scale = 5000
	x_offset =	_screen.Width / 2
	y_offset =	_screen.Height / 2


	* Buttons
	if type("_screen.cmdZoomIn") = "O"
		_screen.RemoveObject("cmdZoomIn")
	endif 	
	_screen.AddObject("cmdZoomIn", "zoomin")
	_screen.cmdZoomIn.Caption = "+"
	_screen.cmdZoomIn.Visible = .T.

	if type("_screen.cmdZoomOut") = "O"
		_screen.RemoveObject("cmdZoomOut")
	endif 	
	_screen.AddObject("cmdZoomOut", "zoomout")
	_screen.cmdZoomOut.Caption = "-"
	_screen.cmdZoomOut.Top = 60
	_screen.cmdZoomOut.Visible = .T.

	if type("_screen.cmdQuit") = "O"
		_screen.RemoveObject("cmdQuit")
	endif 	
	_screen.AddObject("cmdQuit", "quit")
	_screen.cmdQuit.Caption = "exit"
	_screen.cmdQuit.Top = 80
	_screen.cmdQuit.Visible = .T.


	if type("_screen.cmdUp") = "O"
		_screen.RemoveObject("cmdUp")
	endif 
	_screen.AddObject("cmdUp", "mup")
	_screen.cmdUp.Caption = ""
	_screen.cmdUp.Visible = .T.
	_screen.cmdUp.Width = 40
	_screen.cmdUp.Top = 20
	_screen.cmdUp.Left = 40

	if type("_screen.cmdDown") = "O"
		_screen.RemoveObject("cmdDown")
	endif 
	_screen.AddObject("cmdDown", "mdown")
	_screen.cmdDown.Caption = ""
	_screen.cmdDown.Visible = .T.
	_screen.cmdDown.Width = 40
	_screen.cmdDown.Top = 40
	_screen.cmdDown.Left = 40

	if type("_screen.cmdLeft") = "O"
		_screen.RemoveObject("cmdLeft")
	endif 	
	_screen.AddObject("cmdLeft", "mleft")
	_screen.cmdLeft.Caption = ""
	_screen.cmdLeft.Visible = .T.
	_screen.cmdLeft.Width = 40
	_screen.cmdLeft.Top = 30
	_screen.cmdLeft.Left = 0

	if type("_screen.cmdRight") = "O"
		_screen.RemoveObject("cmdRight")
	endif
	_screen.AddObject("cmdRight", "mright")
	_screen.cmdRight.Caption = ""
	_screen.cmdRight.Visible = .T.
	_screen.cmdRight.Width = 40
	_screen.cmdRight.Top = 30
	_screen.cmdRight.Left = 80

	if type("_screen.cmdRestart") = "O"
		_screen.RemoveObject("cmdRestart")
	endif 	
	_screen.AddObject("cmdRestart", "restart")
	_screen.cmdRestart.Caption = "restart"
	_screen.cmdRestart.Top = 100
	_screen.cmdRestart.Visible = .T.

	if type("_screen.tmrColorTimer") = "O"
		_screen.RemoveObject("tmrColorTimer")
	endif 
	_screen.AddObject("tmrColorTimer", "ColorTimer")
	_screen.tmrColorTimer.interval = GetRandInterval()
	_screen.tmrColorTimer.enabled = .t.

return

function RefreshScreen
*	clear 
	doevents
	*_screen.Line(0, y_offset, _screen.Width, y_offset)
	*_screen.Line(x_offset, 0, x_offset, _screen.Height)
return 

FUNCTION GetRandRadious()
	gnLower = 2
	gnUpper = 10
	return INT((gnUpper - gnLower + 1) * RAND( ) + gnLower)
ENDFUNC
FUNCTION GetRandInterval()
	gnLower = 100
	gnUpper = 10000
	return INT((gnUpper - gnLower + 1) * RAND( ) + gnLower)
ENDFUNC
FUNCTION GetColors()
	ndotcolor1 = rand() *   16777215 
	ndotcolor2 = rand() *   16777215 
	IF ndotcolor2 = ndotcolor2
		ndotcolor2 = rand() *   16777215 
	ENDIF 
	_screen.FillColor = ndotcolor1 && iif(this.nType = 1, rgb(255, 0, 0), rgb(0, 0, 255))
	_screen.ForeColor = ndotcolor2 && iif(this.nType = 1, rgb(255, 0, 0), rgb(0, 0, 255))
ENDFUNC 

define class zoomin as CommandButton
	procedure click
		n_scale = n_scale - 25000
	return 
enddefine
define class zoomout as CommandButton
	procedure click
		n_scale = n_scale + 25000
	return 
enddefine
define class mup as CommandButton
	procedure click
		y_offset = y_offset + 100
	return 
enddefine
define class mdown as CommandButton
	procedure click
		y_offset = y_offset - 100
	return 
enddefine
define class mright as CommandButton
	procedure click
		x_offset = x_offset - 100
	return 
enddefine
define class mleft as CommandButton
	procedure click
		x_offset = x_offset + 100
	return 
enddefine
define class quit as CommandButton
	procedure click
		lquit = .t.
	return 
enddefine
define class restart as CommandButton
	procedure click
		lrestart = .t.
	return 
enddefine

define class ColorTimer as timer
	procedure timer
		GetColors()
		this.Interval = GetRandInterval()
	return 
enddefine
>I use an algorithm that manipulate monads.
>
>I begin with 50+ randomly placed monads.
>
>They always seem to break into groups of two.
>
>The rules, the initial conditions, and some of the results I've gotten are accessible here:
>
>http://cloudmusiccompany.com/science/research.htm
>
>My question is, why do the monads split into clusters of two?

...Y soy feliz, bien feliz, asi lo grito;
Mira, que el mundo sepa, que se sepa:
Soy feliz....                       

...And I'm happy, quite happy, so do I yell it;
Look, so the world knows it, so be known:
I'm happy...
 

Ismael Rivera "Oye cosita linda"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform