RedWorld fundamental object in the RedUniverse toolkit
base for all other worlds like RedWorld1, RedWorld2, RedWorld3. implements simplified physical laws.
see also: RedObject, RedUniverse
class methods:
*new(dim, gravity, maxVel, damping)
create a new world. see class source for defaults.
instance methods:
add(redObj)
manually add an object to this world. usually never needed.
remove(redObj)
manually remove an object from this world.
contain(redObj)
wrap an object around world dimensions. ie world without borders - going out on the right side
brings the object back on the left.
contains(redObj)
check if an object is within world dimensions. used for detecting wall bounce. returns boolean.
neighbours(redObj)
returns an Array of objects that are in the surrounding locations.
only useful when working with discrete worlds. eg cellular automata.
note: subclasses will treat the neighbourhood at world borders differently. eg RedWorld3 filters out.
surroundingLocations(redObj)
returns an Array of RedVector objects representing the surrounding locations.
only useful when working with discrete worlds. eg cellular automata.
note: subclasses will treat the neighbourhood at world borders differently. eg RedWorld3 filters out.
instance variables:
<>dim
size of this world (RedVector of any dimension). ie the world can have any number of dimensions.
<>gravity
world gravity (RedVector of any dimension) for each dimension.
<>maxVel
scalar with maximum velocity. ie 'speed of light' for this world.
<>damping
scalar. the cost of running into walls etc.
<>objects
array of all objects currently in this world.
<>surroundings
an Array containing arrays with a size that matches the current world dimensions.
only useful when working with discrete worlds. eg cellular automata.
<>surroundingArea
an Integer specifying how far the surroundings will be. a 1 (default) lists only the adjacent locations.
eg a 1 gives 8 locations in the surroundings array if the world is 2D, while 2 gives 24 and 3 48
in a 3D world 1 gives 26, 2 124 and 3 342.
a= RedWorld.new
b= RedObject(a)
a.dump
RedUniverse.worlds
RedUniverse.remove(a)
RedUniverse.worlds
//--
a= RedWorld(RedVector[100, 100])
b= RedObject(a, RedVector[50, 50])
c= RedObject(a, RedVector[51, 50])
a.surroundings //adjacent locations excluding [0, 0]
a.surroundingLocations(b) //the neighbourhood of object b
a.neighbours(b) //yes c is nearby
a.surroundingArea= 2 //look farther away
a.surroundingLocations(b) //bigger neighbourhood of object b
//--
a= RedWorld(RedVector[50]) //a 1d world
b= RedObject(a, RedVector[0])
a.surroundings //adjacent locations excluding [0, 0, 0]
a.surroundingLocations(b) //the neighbourhood of object b
//--
a= RedWorld(RedVector[25, 25, 25]) //a 3d world
b= RedObject(a, RedVector[0, 0, 0])
a.surroundings //adjacent locations excluding [0, 0, 0]
a.surroundingLocations(b) //the neighbourhood of object b