示例#1
0
	def init( self ):
		''''''


		self.move( ( breve.randomExpression( breve.vector( 50, 0, 50 ) ) - breve.vector( 25, 0, 25 ) ) )
		self.setVelocity( ( breve.randomExpression( breve.vector( 2, 0, 2 ) ) - breve.vector( 1, 0, 1 ) ) )
		self.setColor( breve.randomExpression( breve.vector( 1, 1, 1 ) ) )
	def __init__( self ):
		breve.BraitenbergVehicle.__init__(self)
	
		'''Adds wheels and sensors.'''
		self.lWheel = self.addWheel (breve.vector( -0.5, 0, -1.5 ))
		self.rWheel = self.addWheel (breve.vector( -0.5, 0, 1.5 ))
		self.lFrontSensor = self.addSensor (breve.vector( 2.2, 0.1, -1.4 ), breve.vector( 0.5, 0, 1 ), 1.57000000, 1.6, "BraitenbergOlfactions", "linear")
		self.rFrontSensor = self.addSensor (breve.vector( 2.2, 0.1, 1.4 ),breve.vector( -0.5, 0, 1 ),  1.57000000, 1.6, "BraitenbergOlfactions", "linear")

		self.lBlockSensor = self.addBlockSensor (breve.vector( 2.2, 0.1, -1.4 ), breve.vector( 0.5, 0, 1 ), 1.57000000, 1.6, "linear")
		self.rBlockSensor = self.addBlockSensor (breve.vector( 2.2, 0.1, 1.4 ),breve.vector( -0.5, 0, 1 ),  1.57000000, 1.6, "linear")
		
		'''Links the sensors to the wheels.'''
		self.lFrontSensor.link(self.lWheel)
		self.rFrontSensor.link(self.rWheel)

		'''Block sensors.'''
		self.lBlockSensor.link(self.rWheel)
		self.rBlockSensor.link(self.lWheel)
		
		self.lWheel.setNaturalVelocity(0)
		self.rWheel.setNaturalVelocity(0)
		
		self.lFrontSensor.setBias(6)
		self.rFrontSensor.setBias(6)
		self.lBlockSensor.setBias(3)
		self.rBlockSensor.setBias(3)
    def init(self):
        """"""

        print """ola"""
        breve.createInstances(breve.myAgents, 40)
        breve.createInstances(breve.Floor, 1).setSize(breve.vector(50, 0.100000, 50))
        self.pointCamera(breve.vector(0, 0, 0), breve.vector(0, 40, 80))
示例#4
0
文件: Painter.py 项目: B-Rich/breve
	def init( self ):
		brush = None

		self.disableText()
		self.vel = ( 1.000000 + breve.randomExpression( 9 ) )
		self.acc = breve.randomExpression( 1000 )
		self.radius = ( 1.000000 + breve.randomExpression( 5 ) )
		if ( self.getArgumentCount() == 2 ):
			self.file = self.getArgument( 1 )

		else:
			self.file = 'images/jon.png'

		self.image = breve.createInstances( breve.Image, 1 ).load( self.file )
		self.blur = 0.992000
		if ( self.blur > 0.992000 ):
			self.blur = 0.992000

		self.blur = 1.000000
		self.setBackgroundColor( breve.vector( 0, 0, 0 ) )
		self.enableBlur()
		self.setBlurFactor( self.blur )
		self.radius = ( self.radius * ( self.image.getWidth() / 300.000000 ) )
		self.vel = ( self.vel * ( self.image.getWidth() / 300.000000 ) )
		self.acc = ( self.acc * ( self.image.getWidth() / 300.000000 ) )
		self.shape = breve.createInstances( breve.Sphere, 1 ).initWith( self.radius )
		brush = breve.createInstances( breve.Image, 1 ).load( 'images/brush.png' )
		breve.createInstances( breve.Painters, 200 ).setBitmapImage( brush )
		self.zoom = ( self.image.getWidth() + 10 )
		self.offsetCamera( breve.vector( 0, 0, self.zoom ) )
		self.setZClip( ( self.zoom + 100 ) )
示例#5
0
	def initJoints( self ):
		self.legJoints = breve.createInstances( breve.RevoluteJoints, NBR_LEGS)
		map(self.addDependency, self.legJoints)

		bodyOffsets = []
		for i in range(0, NBR_LEGS):
			if( i < NBR_LEGS / 2):
				widthOffset = self.bodyWidth / 2.0
			else:
				widthOffset = -self.bodyWidth / 2.0

			lengthOffset = -self.bodyLength / 2.0 + self.bodyLength / NBR_LEGS + (i % (NBR_LEGS / 2)) * (self.bodyLength / (NBR_LEGS / 2 - 1))

			bodyOffsets = bodyOffsets + [breve.vector( widthOffset, lengthOffset, 0.2 )]

		#bodyOffsets = [ breve.vector( self.bodyWidth / 2.0 - self.bodyWidth * i // (NBR_LEGS / 2), -self.bodyLength / 2.0 + i * self.bodyLength / (NBR_LEGS / 2), 0.2 ) for i in range( 0, NBR_LEGS )] 

		legOffset = breve.vector( 0, 0, self.legLength / 2.0)
		
		#bodyOffset specifies the point the joints links to on the body, 
		#and upperLegOffset specifies the point on the leg to link to.
		for i in range(0, NBR_LEGS):
			self.legJoints[i].link( ROTATION_NORMAL, bodyOffsets[i], -legOffset, self.legs[ i ], self.bodyLink )
		
		self.legJoints.setDoubleSpring( 700, 0.800000, -0.800000 )

		[ joint.setStrengthLimit( 600 ) for joint in self.legJoints ] #400 innan

		self.allJoints = self.legJoints
		self.setRoot( self.bodyLink )
	def addBlockSensor( self, location , axis, ang, viewAngle, function, name = "BlockSensor"):
		'''Adds a sensor at location on the vehicle.  This method returns the sensor which is created, a OBJECT(BraitenbergSensor).  You'll use the returned object to connect it to the vehicle's wheels.'''

		''' This sensor only interacts  with blocks. '''
		joint = None
		sensor = None

		sensor = breve.createInstances( breve.BraitenbergBlockSensor, 1 )
		sensor.setShape( self.sensorShape )
		
		activationFunction = breve.createInstances(breve.BraitenbergActivationObject, 1)
		activationFunction.setType(function)
		sensor.setActivationObject( activationFunction )
		sensor.activationObject.setName( name)
		
		'''Sets the angle of the sensor'''
		sensor.setSensorAngle(viewAngle)
		
		joint = breve.createInstances( breve.FixedJoint, 1 )
		joint.setRelativeRotation( axis, ang )
			
		joint.link( location, breve.vector( 0, 0, 0 ), sensor, self.bodyLink )
		joint.setDoubleSpring( 300, 0.010000, -0.010000 )
		self.addDependency( joint )
		self.addDependency( sensor )
		sensor.setColor( breve.vector( 0, 0, 0 ) )
		self.sensors.append( sensor )
		return sensor
	def init( self ):
		self.vertices[ 0 ] = breve.vector( 0.1, 0, 0 )
		self.vertices[ 1 ] = breve.vector( -0.1, 0, 0 )
		self.vertices[ 2 ] = breve.vector( 0, 0.5, 0 )

		self.addFace( [ self.vertices[ 0 ], self.vertices[ 1 ], self.vertices[ 2 ] ] )
		self.finishShape( 1.000000 )
	def iterate( self ):
		'''Calculates the signal strength according to the closest source that it finds within the it's range.'''
		i = None
		objects = 0
		angle = 0
		strength = 0
		total = 0
		transDir = breve.vector()
		dist = breve.vector()

		minDist=None
		
		transDir = ( self.getRotation() * self.direction )
		'''Only detects blocks.'''
		for i in breve.allInstances( "BraitenbergBlocks" ):
			dist = ( i.getLocation() - self.getLocation() )
			angle = breve.breveInternalFunctionFinder.angle( self, dist, transDir )
			'''It's inside the angle and it's closer than any other block analyzed so far.'''
			if angle < self.sensorAngle :
				t = breve.length(self.getLocation() - i.getLocation())
				
				'''Updates the min distance.'''
				if minDist == None or t < minDist:
					minDist = t
					
				strength = breve.length( ( self.getLocation() - i.getLocation() ) )
				strength = ( 1.000000 / ( strength * strength ) )

				total = strength

		total = ( ( 50 * total ) * self.bias )
		self.wheels.activate( total )
	def init( self ):
		self.setBackgroundColor( breve.vector( 0, 0, 0 ) )
		self.setDisplayTextColor( breve.vector( 1, 1, 1 ) )
		self.setIterationStep(1.0)

		self.object1 = breve.createInstances( breve.CustomObject, 1)
		self.object2 = breve.createInstances( breve.CustomObject, 1)
		self.object3 = breve.createInstances( breve.CustomObject, 1)

		self.object1.pushInterpreter.pushVector( breve.vector(1, 2, 3) )
		self.object2.pushInterpreter.pushVector( breve.vector(100, 200, 300) )

		# first run
		self.object1.pushInterpreter.clearStacks()
		self.object1.pushInterpreter.run( self.object1.pushCode )
		print self.object1.pushInterpreter.getVectorStackTop()

		self.object2.pushInterpreter.clearStacks()
		self.object2.pushInterpreter.run( self.object1.pushCode )
		print self.object2.pushInterpreter.getVectorStackTop()

		print self.object3.pushCode.getList()
		# crossover
		self.crossover_push(self.object3, self.object1, self.object2)

		print self.object1.pushCode.getList(), self.object1.pushCode.getSize()
		print self.object2.pushCode.getList(), self.object2.pushCode.getSize()
		print self.object3.pushCode.getList(), self.object3.pushCode.getSize()

		# second run
		'''self.object1.pushInterpreter.clearStacks()
示例#10
0
	def dropDead(self, corpse=True):
		if corpse:
			c = breve.createInstances( breve.Corpse, 1 )
			c.move( self.getLocation() )
			c.setColor (self.getColor() )
			c.energy = self.energy
			#c.lastScale = self.lastScale
			c.shape = self.shape
			c.setShape( c.shape )
			c.myPoint( breve.vector( 0, 1, 0 ), self.getVelocity())
			
			self.lastScale = 1
			self.shape = breve.createInstances( breve.myCustomShape, 1 )
			self.setShape( self.shape )
			self.adjustSize()


		self.setColor(breve.vector(0,0,0))
		#just to don't overlap the animation 
		self.changePos(-9999,9999)
		self.changeVel(0,0)
		self.changeAccel(0,0)
		self.age = 0
		self.energy = 1
		self.isAlive = False
		self.controller.pollPredators.append(self)
		self.controller.numDeadPredators += 1
    def init( self ):
        self.vehicle = breve.createInstances( breve.BraitenbergVehicle, 1 )
        self.watch( self.vehicle )
        self.vehicle.move(breve.vector(2,1,10))
        self.vehicle.rotate(breve.vector(0,1,0),3.14)
        self.block = breve.createInstances( breve.BraitenbergSound,1)
        self.block.move( breve.vector(2,1,15))
        self.block = breve.createInstances( breve.BraitenbergSound,1)
        self.block.move( breve.vector(-20,1,15))
        


        #Wheels and Sensors
        front_left = self.vehicle.addWheel(breve.vector(0,0,-1.5))
        front_right = self.vehicle.addWheel(breve.vector(0,0,1.5))
        
        leftSoundSensor = self.vehicle.addSensor(breve.vector(2.2, 0.1, -1.4),breve.vector( 0.75, 0, 1 ), 1, "Sounds")
        rightSoundSensor = self.vehicle.addSensor(breve.vector(2.2, 0.1, 1.4),breve.vector( -0.75, 0, 1 ), 1, "Sounds")
        leftSoundSensor.setActivationType("gauss")
        rightSoundSensor.setActivationType("gauss")
        leftSoundSensor.setGauss(0.20, 0.101)
        rightSoundSensor.setGauss(0.20, 0.101)
        leftSoundSensor.link(front_right)
        rightSoundSensor.link(front_left)
        
        front_left.setNaturalVelocity(1.2)
        front_right.setNaturalVelocity(1.2)
        
        leftSoundSensor.setBias(0.12)
        rightSoundSensor.setBias(0.12)
        
            
        breve.myBraitenbergControl = myBraitenbergControl
示例#12
0
	def iterate( self ):
		i = None
		lights = 0
		angle = 0
		strength = 0
		total = 0
		transDir = breve.vector()
		toLight = breve.vector()

		transDir = ( self.getRotation() * self.direction )
		for i in breve.allInstances( "BraitenbergLights" ):
			toLight = ( i.getLocation() - self.getLocation() )
			angle = breve.breveInternalFunctionFinder.angle( self, toLight, transDir )
			if ( angle < self.sensorAngle ):
				strength = breve.length( ( self.getLocation() - i.getLocation() ) )
				strength = ( 1.000000 / ( strength * strength ) )
				if ( self.activationMethod and self.activationObject ):
					strength = self.activationObject.callMethod( self.activationMethod, [ strength ] )


				if ( strength > 10 ):
					strength = 10

				total = ( total + strength )
				lights = ( lights + 1 )




		if ( lights != 0 ):
			total = ( total / lights )

		total = ( ( 50 * total ) * self.bias )
		self.wheels.activate( total )
示例#13
0
	def initShape( self, chromosomes ):
		self.bodyWidth = 4
		self.bodyDepth = 1 
		self.bodyHeight = 4

		footWidth = 2.5
		self.footHeight = 0.3

		self.legLength = 2
		self.legWidth = 0.5

		self.startingHeight = 2 * self.legLength + self.bodyHeight

		lowerLegShape = breve.Cube().initWith( breve.vector( self.legWidth , self.legWidth , self.legLength )) 
		upperLegShape = breve.Cube().initWith( breve.vector( self.legWidth , self.legWidth , self.legLength ))
		footShape = breve.Cube().initWith( breve.vector( footWidth, footWidth, self.footHeight ))
		bodyShape = breve.Cube().initWith( breve.vector( self.bodyWidth, self.bodyDepth, self.bodyHeight ) )
	
		self.bodyLink = breve.Link()
		self.lowerLegs = breve.createInstances( breve.Links, NBR_LEGS )
		self.upperLegs = breve.createInstances( breve.Links, NBR_LEGS )
		self.feet = breve.createInstances( breve.Links, NBR_LEGS )

		[ link.setShape(upperLegShape) for link in self.upperLegs ]
		[ link.setShape(lowerLegShape) for link in self.lowerLegs ]
		[ link.setShape(footShape) for link in self.feet ]

		self.bodyLink.setShape( bodyShape )

		#Used for resetting the walker position
		self.allLinks = [self.bodyLink] + self.upperLegs + self.lowerLegs + self.feet
示例#14
0
	def initJoints( self ):
		self.upperLegJoints = breve.createInstances( breve.RevoluteJoints, NBR_LEGS)
		self.lowerLegJoints = breve.createInstances( breve.RevoluteJoints, NBR_LEGS)
		self.footJoints = breve.createInstances( breve.RevoluteJoints, NBR_LEGS)

		self.allJoints = self.upperLegJoints + self.lowerLegJoints + self.footJoints
		map(self.addDependency, self.allJoints)

		left = breve.vector( self.bodyWidth / 2.0, 0, self.bodyHeight/2 )
		right = breve.vector( -self.bodyWidth / 2.0, 0, self.bodyHeight/2 )
		bodyOffsets = [left, right]

		legOffset = breve.vector( 0, 0, self.legLength/2.0)
		footOffset = breve.vector( 0, 0, self.footHeight/2.0)
		
		#bodyOffset specifies the point the joints links to on the body, 
		#and upperLegOffset specifies the point on the leg to link to.
		for i in range(0, NBR_LEGS):
			self.upperLegJoints[i].link( ROTATION_NORMAL, bodyOffsets[i], -legOffset, self.upperLegs[ i ], self.bodyLink )
			self.lowerLegJoints[i].link( ROTATION_NORMAL, legOffset, -legOffset, self.lowerLegs[ i ], self.upperLegs[ i ] )
			self.footJoints[i].link( ROTATION_NORMAL, legOffset + footOffset, breve.vector( 0, 0, 0 ), self.feet[ i ], self.lowerLegs[ i ] )
		
		self.upperLegJoints.setDoubleSpring( 700, 0.800000, -0.800000 )
		self.lowerLegJoints.setDoubleSpring( 700, 0.800000, -0.800000 )
		self.footJoints.setDoubleSpring( 999, 0.400000, -0.400000 ) #kolla

		[ joint.setStrengthLimit( 500 ) for joint in self.allJoints ] #400 innan
		self.setRoot( self.bodyLink )
示例#15
0
	def init( self ):
		self.setShape( breve.createInstances( breve.PolygonCone, 1 ).initWith( 3, 0.500000, 0.060000 ) )
		self.move( ( breve.randomExpression( breve.vector( 10, 10, 10 ) ) - breve.vector( 5, -5, 5 ) ) )
		self.setVelocity( ( breve.randomExpression( breve.vector( 20, 20, 20 ) ) - breve.vector( 10, 10, 10 ) ) )
		self.setColor( breve.randomExpression( breve.vector( 1, 1, 1 ) ) )
		self.handleCollisions( 'Terrain', 'land' )
		self.setNeighborhoodSize( 3.000000 )
示例#16
0
 def init(self):
     self.shape = breve.createInstances(breve.Cube, 1).initWith(breve.vector(1000, 5, 1000))
     self.move(breve.vector(0, -2.500000, 0))
     self.setShape(self.shape)
     self.setColor(breve.vector(0.350000, 0.800000, 0.450000))
     self.catchShadows()
     self.setTextureImage(breve.createInstances(breve.Image, 1).load("images/noise.png"))
示例#17
0
文件: ctf.py 项目: firebitsbr/ctf-28
    def goToJail(self):
        """
        Puts the player in jail.
        """
        # if we're in jail we don't need to go to jail
        if self.in_jail:
            return

        # set out in_jail flag to true
        self.in_jail = True

        # stick yourself in a random spot in red prison.
        # Add one to the capture count
        if self.team == 1:
            self.jailed_location = self.controller.getRedJailLocation()
            self.jailed_location += breve.randomExpression(breve.vector(1, 0, 1))
            self.jailed_location -= breve.vector(.5, -.5, .5)
            self.controller.changePrisoners(RED_TEAM, 1)
        # stick yourself in a random spot in red prison.
        # Add one to the capture count
        else:
            self.jailed_location = self.controller.getBlueJailLocation()
            self.jailed_location += breve.randomExpression(breve.vector(1, 0, 1))
            self.jailed_location -= breve.vector(.5, -.5, .5)
            self.controller.changePrisoners(BLUE_TEAM, 1)

        # Move to that location
        self.move(self.jailed_location)
示例#18
0
文件: ctf.py 项目: firebitsbr/ctf-28
    def __init__(self):
        """
        Initalizes all of the variables for the CTFPlayer.
        Then initalizes it.
        """
        # Parent constructor call. Necissary.
        CTFMobile.__init__(self)

        # Variable initalization
        self.shape = None
        self.velocity = 0.0
        self.angle = 0.0
        self.heading = breve.vector()
        self.turning_left = False
        self.turning_right = False
        self.at_edge = False
        self.carrying = None
        self.team_home = breve.vector()
        self.in_jail = False
        self.jailed_location = breve.vector()
        self.id_number = 0

        # Initalization and instance storage.
        self.init()
        CTFPlayer.players.append(self)
示例#19
0
文件: ctf.py 项目: firebitsbr/ctf-28
    def resetWorld(self):
        """
        Resets the state of the world for a new match.
        """
        # Generate the randomness for the flag position
        location_randomizer = breve.randomExpression(breve.vector(0, 0, WORLD_SIZE/2))
        location_randomizer -= breve.vector(0, 0, WORLD_SIZE/4)

        # Reset flag locations
        self.blue_flag.move(breve.vector(-1*WORLD_SIZE/2+5, 1, 0) + location_randomizer)
        self.blue_flag.resetFlag()

        self.red_flag.move(breve.vector(WORLD_SIZE/2-5, 1, 0) + location_randomizer)
        self.red_flag.resetFlag()

        # Reset all of the player locations
        # This call varies from traditional breve python syntax. To iterate over all
        # objects of a certian class the call is usually:
        # for item in breve.allInstances(CTFPlayer)
        # But since CTFPlayer is a pure python subclass it is not added to the 
        # breve object counter properly. We have to handle our own player count.
        for item in CTFPlayer.players:
            item.resetPlayer()

        # set the pause timer, reset the iteration count
        # reset the red and blue caputer count
        # Display the winners of the match properly.
        self.pause_track = PAUSE_TIME
        self.iterations = 1
        self.red_players_captured = 0
        self.blue_players_captured = 0
        self.total_red_flag_time = 0.0
        self.total_blue_flag_time = 0.0
        self.setDisplayText(self.winners_str % \
                (self.red_wins, self.blue_wins, self.ties), -.3, .8, 3)
示例#20
0
	def changeDrivers( self ):
		newDriver = 0
		newOffset = breve.vector()

		if self.locked:
			return

		newOffset = ( breve.randomExpression( breve.vector( 30, 6, 30 ) ) + breve.vector( -15, 1, -15 ) )
		if ( breve.length( newOffset ) < 9 ):
			newOffset = ( ( 9 * newOffset ) / breve.length( newOffset ) )

		self.panCameraOffset( newOffset, 30 )
		self.seats[ self.currentSeat ].setDistance( breve.length( self.wigglyThing.getLocation() ) )
		self.currentSeat = ( self.currentSeat + 1 )
		if ( self.currentSeat > 3 ):
			self.breedNewMonkeys()
			self.pickDrivers()


		newDriver = self.seats[ self.currentSeat ].getNumber()
		if self.wigglyThing:
			breve.deleteInstances( self.wigglyThing )


		self.wigglyThing = breve.createInstances( breve.Creature, 1 )
		self.wigglyThing.initWith( self.seats[ self.currentSeat ].getGenome() )
		self.wigglyThing.move( breve.vector( 0, 3, 0 ) )
		self.watch( self.wigglyThing )
		self.schedule( 'changeDrivers', ( self.getTime() + 20.000000 ) )
		self.displayCurrentDriver()
示例#21
0
	def init( self ):
		self.setShape( breve.createInstances( breve.Sphere, 1 ).initWith( 0.100000 ) )
		self.move( ( breve.randomExpression( breve.vector( 10, 10, 10 ) ) - breve.vector( 5, -5, 5 ) ) )
		self.setVelocity( ( breve.randomExpression( breve.vector( 20, 20, 20 ) ) - breve.vector( 10, 10, 10 ) ) )
		self.setColor( breve.randomExpression( breve.vector( 1, 1, 1 ) ) )
		self.handleCollisions( 'Floor', 'land' )
		self.setNeighborhoodSize( 3.000000 )
示例#22
0
	def initializeRandomly( self ):
		self.pushCode.makeRandomCode( self.pushInterpreter, 80 )
		self.move( ( breve.randomExpression( breve.vector( 10, 0, 10 ) ) - breve.vector( 5, 3, 5 ) ) )
		self.setVelocity( breve.vector( 0, 0, 0 ) )
		self.hue = breve.randomExpression( 1.000000 )
		self.setColor( self.controller.getRgbColor( breve.vector( ( self.hue * 360 ), 1, 1 ) ) )
		self.energy = ( 0.800000 + breve.randomExpression( 0.200000 ) )
示例#23
0
	def iterate( self ):
		location = breve.vector()
		velocity = breve.vector()
		birdLocation = breve.vector()
		topDiff = 0

		self.updateNeighbors()
		for self.item in self.birds:
			self.item.fly( self.birds )
			location = ( location + self.item.getLocation() )


		location = ( location / self.birds )
		topDiff = 0.000000
		for self.item in self.birds:
			if ( topDiff < breve.length( ( location - self.item.getLocation() ) ) ):
				topDiff = breve.length( ( location - self.item.getLocation() ) )



		if self.cameraControl:
			self.aimCamera( location )
			self.zoomCamera( ( ( 0.500000 * topDiff ) + 10 ) )


		breve.Control.iterate( self )
	def fly(self):
		pos = self.getLocation()
		self.changePos(pos.x, pos.y)
		self.myPoint( breve.vector( 0, 1, 0 ), self.getVelocity())

		vel = self.getVelocity()
		vel_x = vel.x
		vel_y = vel.y
		self.changeVel(vel_x, vel_y)

		self.pushInterpreter.run( self.pushCode )
		accel = self.pushInterpreter.getVectorStackTop()
		if ( ( ( ( ( breve.breveInternalFunctionFinder.isinf( self, accel.x ) or breve.breveInternalFunctionFinder.isnan( self, accel.x ) ) or breve.breveInternalFunctionFinder.isinf( self, accel.y ) ) or breve.breveInternalFunctionFinder.isnan( self, accel.y ) ) or breve.breveInternalFunctionFinder.isinf( self, accel.z ) ) or breve.breveInternalFunctionFinder.isnan( self, accel.z ) ):
				accel = breve.vector( 0.000000, 0.000000, 0.000000 )
		self.changeAccel(accel.x, accel.y)
		
		# eat
		neighbors = self.getNeighbors()
		for neighbor in neighbors:
			if neighbor.isA( 'Bird' ) and neighbor.isAlive:
				norm = ((self.pos_x-neighbor.pos_x)**2 + (self.pos_y-neighbor.pos_y)**2)**0.5
				if norm <= max(neighbor.lastScale,3):
					self.eat(neighbor) 

		self.addEnergy(-0.01-0.005*self.tail)
		self.adjustSize()
		self.age += 1
		#if self.energy < 0.5 or self.age > 300:
		if self.energy < 0.5:
			self.dropDead()
示例#25
0
	def init( self ):
		number = 0
		item = None

		self.locked = 0
		self.enableLighting()
		self.enableSmoothDrawing()
		self.enableFastPhysics()
		self.setFastPhysicsIterations( 5 )
		self.floor = breve.createInstances( breve.Floor, 1 )
		self.floor.catchShadows()
		self.floor.setET( 0.900000 )
		self.floor.setMu( 1.000000 )
		self.setBackgroundTextureImage( breve.createInstances( breve.Image, 1 ).load( 'images/clouds.png' ) )
		self.enableReflections()
		self.setBackgroundColor( breve.vector( 0.400000, 0.600000, 0.900000 ) )
		self.monkeys = breve.createInstances( breve.Monkeys, 15 )
		for item in self.monkeys:
			item.setNumber( number )
			number = ( number + 1 )


		self.pickDrivers()
		self.lockMenu = self.addMenu( '''Lock Driver''', 'toggleDriverLock' )
		self.addMenuSeparator()
		self.addMenu( '''Save Current Genome''', 'saveCurrentGenome' )
		self.addMenu( '''Load Into Current Genome''', 'loadIntoCurrentGenome' )
		self.schedule( 'changeDrivers', ( self.getTime() + 20.000000 ) )
		self.displayCurrentDriver()
		self.wigglyThing = breve.createInstances( breve.Creature, 1 )
		self.wigglyThing.initWith( self.seats[ 0 ].getGenome() )
		self.wigglyThing.move( breve.vector( 0, 3, 0 ) )
		self.offsetCamera( breve.vector( -3, 3, 13 ) )
		self.watch( self.wigglyThing )
	def init( self ):
		self.vehicle = breve.createInstances( breve.BraitenbergVehicle, 1 )
		self.vehicle.move(breve.vector(2,1,10))
		self.vehicle.rotate(breve.vector(0,1,0),3.14)
		self.watch( self.vehicle )

		self.block = breve.createInstances( breve.BraitenbergSound,1)
		self.block.move( breve.vector(2,1,15))
		self.block = breve.createInstances( breve.BraitenbergSound,1)
		self.block.move( breve.vector(-18,1,15))


		'''Adds wheels and sensors.'''
		lWheel = self.vehicle.addWheel (breve.vector( 0, 0, -1.5 ))
		rWheel = self.vehicle.addWheel (breve.vector( 0, 0, 1.5 ))

		#Correct values
		lFrontSensor = self.vehicle.addSensor (breve.vector( 2.2, 0.1, -1.4 ), breve.vector( 0.75, 0, 1 ),1, "Sounds")
		rFrontSensor = self.vehicle.addSensor (breve.vector( 2.2, 0.1, 1.4 ),breve.vector( -0.75, 0, 1 ),1, "Sounds")
		lFrontSensor.setActivationType("gauss")
		rFrontSensor.setActivationType("gauss")
		
		'''Links the sensors to the wheels.'''
		lFrontSensor.link(rWheel)
		rFrontSensor.link(lWheel)

		#Correct values
		lWheel.setNaturalVelocity(1.16)
		rWheel.setNaturalVelocity(1.16)

		#Correct values
		lFrontSensor.setBias(0.005)
		rFrontSensor.setBias(0.005)
	
		breve.myBraitenbergControl = myBraitenbergControl
示例#27
0
文件: Creatures.py 项目: B-Rich/breve
	def init( self ):
		self.startTexture = breve.createInstances( breve.Image, 1 ).load( 'images/star.png' )
		self.flag = breve.createInstances( breve.Mobile, 1 )
		self.flag.disablePhysics()
		self.flag.setBitmapImage( self.startTexture )
		self.flag.setColor( breve.vector( 1, 1, 0 ) )
		self.flag.setLabel( 'Start' )
		self.flag.disableShadows()
		self.setMountainSkybox()
		self.blockTexture = breve.createInstances( breve.Image, 1 ).load( 'images/noise.png' )
		self.floor = breve.createInstances( breve.Floor, 1 )
		self.floor.setTextureImage( breve.createInstances( breve.Image, 1 ).load( 'images/ground.png' ) )
		self.floor.setColor( breve.vector( 0.800000, 0.800000, 0.800000 ) )
		self.enableFastPhysics()
		self.setFastPhysicsIterations( 30 )
		self.enableShadowVolumes()
		self.parser = breve.createInstances( breve.MorphologyParser, 1 )
		self.ga = self.controller.dearchiveXml( 'breveCreatures.xml' )

		if ( not self.ga ):
			print '''Making new GA'''
			self.ga = breve.createInstances( breve.SimsGA, 1 )
			self.ga.setFitnessTestDuration( 45 )
			self.ga.setIndividualClass( 'SimsGAIndividual' )
			self.ga.setPopulationSize( 25 )
			self.ga.setCrossoverPercent( 30 )
			self.ga.setMutationPercent( 30 )


		self.addDependency( self.ga )
		self.updateText()
示例#28
0
	def initShape( self, chromosomes ):
		self.bodyWidth = chromosomes[BODY_WIDTH]
		self.bodyLength = self.bodyWidth # might remove

		footWidth = chromosomes[FOOT_WIDTH]
		self.footHeight = FOOT_HEIGHT

		self.upperLegLength = chromosomes[UPPER_LEG_WIDTH]
		self.lowerLegLength = chromosomes[LOWER_LEG_WIDTH]

		self.startingHeight = self.upperLegLength + self.lowerLegLength + self.footHeight + 5

		lowerLegShape = breve.Cube().initWith( breve.vector( LEG_WIDTH , LEG_WIDTH , self.lowerLegLength )) 
		upperLegShape = breve.Cube().initWith( breve.vector( LEG_WIDTH , LEG_WIDTH , self.upperLegLength ))
		footShape = breve.Cube().initWith( breve.vector( footWidth, footWidth, self.footHeight ))
		bodyShape = breve.Cube().initWith( breve.vector( self.bodyWidth, self.bodyWidth, 0.400000 ) )
	
		self.bodyLink = breve.Link()
		self.lowerLegs = breve.createInstances( breve.Links, NBR_LEGS )
		self.upperLegs = breve.createInstances( breve.Links, NBR_LEGS )
		self.feet = breve.createInstances( breve.Links, NBR_LEGS )

		[ link.setShape(upperLegShape) for link in self.upperLegs ]
		[ link.setShape(lowerLegShape) for link in self.lowerLegs ]
		[ link.setShape(footShape) for link in self.feet ]

		self.bodyLink.setShape( bodyShape )

		#Used for resetting the walker position
		self.allLinks = [self.bodyLink] + self.upperLegs + self.lowerLegs + self.feet
	def addBlockSensor( self, location , axis, ang, function, lowerBound = -1000, upperBound = 1000):
		'''Adds a sensor at location on the vehicle.  This method returns the sensor which is created, a OBJECT(BraitenbergSensor).  You'll use the returned object to connect it to the vehicle's wheels.'''

		''' This sensor only interacts  with blocks. '''
		joint = None
		sensor = None

		sensor = breve.createInstances( breve.BraitenbergBlockSensor, 1 )
		sensor.setShape( self.sensorShape )
		
		activationFunction = breve.createInstances(breve.BraitenbergActivationObject, 1)
		activationFunction.setType(function)
		activationFunction.setLowerBound(lowerBound)
		activationFunction.setUpperBound(upperBound)
		sensor.setActivationObject( activationFunction )
		
		joint = breve.createInstances( breve.RevoluteJoint, 1 )
		joint.setRelativeRotation( axis, ang )
			
		joint.link( breve.vector( 1, 0, 0 ), location, breve.vector( 0, 0, 0 ), sensor, self.bodyLink )
		joint.setDoubleSpring( 300, 0.010000, -0.010000 )
		self.addDependency( joint )
		self.addDependency( sensor )
		sensor.setColor( breve.vector( 0, 0, 0 ) )
		self.sensors.append( sensor )
		return sensor
	def iterate( self ):
		i = None
		lights = 0
		angle = 0
		strength = 0
		total = 0
		transDir = breve.vector()
		toLight = breve.vector()

		transDir = ( self.getRotation() * self.direction )
		'''It's by the sensorType string that we distinguish between a sound, olfaction or light sensor. '''
		for i in breve.allInstances( self.sensorType ):
			toLight = ( i.getLocation() - self.getLocation() )
			angle = breve.breveInternalFunctionFinder.angle( self, toLight, transDir )
			if ( angle < self.sensorAngle ):
				strength = breve.length( ( self.getLocation() - i.getLocation() ) )
				strength = ( 1.000000 / ( strength * strength ) )
				if ( self.activationObject ):
					strength = self.activationObject.activate(strength)

				if ( strength > 10 ):
					strength = 10

				total = ( total + strength )
				lights = ( lights + 1 )

		if ( lights != 0 ):
			total = ( total / lights )

		total = ( ( 50 * total ) * self.bias )
		self.wheels.activate( total )
示例#31
0
    def dropDead(self, corpse=True):
        if corpse:
            c = breve.createInstances(breve.Corpse, 1)
            c.move(self.getLocation())
            c.setColor(self.getColor())
            c.energy = self.energy
            #c.lastScale = self.lastScale
            c.adjustSize()
            c.myPoint(breve.vector(0, 1, 0), self.getVelocity())

        self.setColor(breve.vector(0, 0, 0))
        #just to don't overlap the animation
        self.changePos(-500, 500)
        self.pushInterpreter.clearStacks()
        self.age = 0
        self.energy = 1
        self.isAlive = False
        self.controller.pollPredators.append(self)
        self.controller.num_dead_predators += 1
    def getAngle(self, otherMobile):
        tempVector = breve.vector()

        if (breve.length(self.getVelocity()) == 0):
            return 0

        tempVector = (otherMobile.getLocation() - self.getLocation())
        return breve.breveInternalFunctionFinder.angle(self,
                                                       self.getVelocity(),
                                                       tempVector)
示例#33
0
	def __init__( self ):
		breve.Link.__init__( self )
		self.bias = 0
		self.direction = breve.vector()
		self.sensorAngle = 0
		self.wheels = breve.objectList()
		self.lowerBound = 0.0 #default
		self.upperBound = 10.0 #default
		self.upperX = () #default
		BraitenbergBallSensor.init( self )
    def iterate(self):
        location = breve.vector()
        topDiff = 0
        highLoc = breve.vector()

        self.updateNeighbors()
        for self.item in self.birds:
            self.item.fly()
            location = (location + self.item.getLocation())
            if (breve.length(self.item.getLocation()) > breve.length(highLoc)):
                highLoc = self.item.getLocation()

        location = (location / breve.length(self.birds))
        topDiff = 0.000000
        for self.item in self.birds:
            if (topDiff < breve.length((location - self.item.getLocation()))):
                topDiff = breve.length((location - self.item.getLocation()))

        self.aimCamera(location)
        breve.Control.iterate(self)
示例#35
0
文件: Creatures.py 项目: pemby/breve
    def checkPenetration(self):
        link = None

        self.running = 1
        if self.body.checkSelfPenetration():
            breve.deleteInstances(breve.allInstances("breve.Links"))

        breve.allInstances("SineJoints").activate()
        self.startlocation = breve.vector(0, 0, 0)
        for link in breve.allInstances("Links"):
            link.setStartLocation()
            self.startlocation = (self.startlocation + link.getLocation())

        if breve.length(breve.allInstances("Links")):
            self.startlocation = (self.startlocation /
                                  breve.length(breve.allInstances("Links")))

        self.flag.move(
            (self.startlocation - breve.vector(0,
                                               (self.startlocation.y - 2), 0)))
示例#36
0
	def addWheel( self, location ):
		'''Adds a wheel at location on the vehicle. This method returns the wheel which is created, a OBJECT(BraitenbergWheel).  You'll use the returned object to connect it to the vehicle's sensors.'''

		joint = None
		wheel = None

		wheel = breve.createInstances( breve.BraitenbergWheel, 1 )
		wheel.setShape( self.wheelShape )
		joint = breve.createInstances( breve.RevoluteJoint, 1 )
		joint.setRelativeRotation( breve.vector( 1, 0, 0 ), 1.570800 )
		joint.link( breve.vector( 0, 0, 1 ), location, breve.vector( 0, 0, 0 ), wheel, self.bodyLink )
		wheel.setET( 0.800000 )
		wheel.setJoint( joint )
		joint.setStrengthLimit( ( joint.getStrengthHardLimit() / 2 ) )
		wheel.setColor( breve.vector( 0.600000, 0.600000, 0.600000 ) )
		wheel.setMu( 100000 )
		self.addDependency( joint )
		self.addDependency( wheel )
		self.wheels.append( wheel )
		return wheel
示例#37
0
文件: Control.py 项目: pemby/breve
    def setDisplayMessage(self,
                          theString,
                          messageNumber,
                          xLoc,
                          yLoc,
                          textColor=breve.vector(0.000000, 0.000000,
                                                 0.000000)):
        '''Sets a text string in the simulation display.  xLoc and yLoc  represent the location of the text.  The coordinate system used goes from (-1, -1) to (1, 1) with (-1, -1) at the lower left hand  corner, (0, 0) in the center of the window and (1, 1) in  the top right hand corner.  The color of the text is set to textColor. <p> Up to 8 messages can be displayed in the simulation window.   messageNumber specifies which message "slot" to modify.   Subsequent calls to this method with the same slot number erase previous entries.'''

        breve.breveInternalFunctionFinder.cameraSetText(
            self, theString, messageNumber, xLoc, yLoc, textColor)
示例#38
0
    def dearchive(self):
        if (not self.realWorldPointer):
            self.realWorldPointer = breve.breveInternalFunctionFinder.addStationary(
                self,
                self.controller.getGenericShape().getPointer(),
                breve.vector(0, 0, 0), breve.matrix(1, 0, 0, 0, 1, 0, 0, 0, 1))

        if self.shadowCatcher:
            self.catchShadows()

        return breve.Real.dearchive(self)
示例#39
0
    def getCurrentCritterFitness(self):
        t = breve.vector()
        link = None

        for link in breve.allInstances("Links"):
            t = (t + link.getLocation())

        if breve.length(breve.allInstances("Links")):
            t = (t / breve.length(breve.allInstances("Links")))

        return breve.length((t - self.startlocation))
示例#40
0
	def initializeRandomly( self, x, y, gener):
		self.changePos(x,y)
		vel_x = random.uniform(-self.maxVel, self.maxVel)
		vel_y = random.uniform(-self.maxVel, self.maxVel)
		self.changeVel(vel_x, vel_y)
		self.changeAccel(0,0)

		self.gener = gener
		self.setNewColor()

		self.pushInterpreter.pushVector( breve.vector(self.vel_x,self.vel_y,0) )
示例#41
0
    def dropDead(self, corpse=True):
        if corpse:
            c = breve.createInstances(breve.Corpse, 1)
            c.move(self.getLocation())
            c.setColor(self.getColor())
            c.energy = self.energy
            #c.lastScale = self.lastScale
            c.adjustSize()
            c.myPoint(breve.vector(0, 1, 0), self.getVelocity())

        self.setColor(breve.vector(0, 0, 0))
        #just to don't overlap the animation
        self.changePos(-9999, 9999)
        self.changeVel(0, 0)
        self.changeAccel(0, 0)
        self.age = 0
        self.energy = 1
        self.isAlive = False
        self.controller.pollPreys.append(self)
        self.controller.numDeadPreys += 1
	def dropDead( self ):
		c = None

		self.controller.incrementDeaths()
		c = breve.createInstances( breve.Corpse, 1 )
		c.move( self.getLocation() )
		c.point( breve.vector( 0, 1, 0 ), self.getVelocity() )
		breve.deleteInstances( self.pushCode )
		breve.deleteInstances( self.pushInterpreter )
		breve.deleteInstances( self.shape )
		breve.deleteInstances( self )
示例#43
0
 def __init__(self):
     breve.Object.__init__(self)
     self.archiveBitmapImage = None
     self.archiveLightmapImage = None
     self.archiveLocation = breve.vector()
     self.archiveRotation = breve.matrix()
     self.archiveTextureImage = None
     self.archiveTextureScaleX = 0
     self.archiveTextureScaleY = 0
     self.collisionHandlerList = breve.objectList()
     self.collisionShape = None
     self.color = breve.vector()
     self.displayShape = None
     self.e = 0
     self.lines = breve.objectList()
     self.menus = breve.objectList()
     self.mu = 0
     self.neighborhoodSize = 0
     self.realWorldPointer = None
     Real.init(self)
示例#44
0
	def init( self ):
		floor = None

		self.addMenu( '''Smoosh The Birdies''', 'squish' )
		self.addMenuSeparator()
		self.obedientMenu = self.addMenu( '''Flock Obediently''', 'flockObediently' )
		self.normalMenu = self.addMenu( '''Flock Normally''', 'flockNormally' )
		self.wackyMenu = self.addMenu( '''Flock Wackily''', 'flockWackily' )
		self.enableLighting()
		self.enableSmoothDrawing()
		self.moveLight( breve.vector( 0, 20, 20 ) )
		self.breveTexture = breve.createInstances( breve.Image, 1 ).load( 'images/breve.png' )
		self.cloudTexture = breve.createInstances( breve.Image, 1 ).load( 'images/clouds.png' )
		floor = breve.createInstances( breve.Floor, 1 )
		floor.catchShadows()
		self.birds = breve.createInstances( breve.Birds, 80 )
		self.birds.setBitmapImage( self.breveTexture )
		self.flockNormally()
		self.setBackgroundTextureImage( self.cloudTexture )
		self.offsetCamera( breve.vector( 5, 1.500000, 6 ) )
		self.enableShadows()
示例#45
0
    def catchShadows(self):
        '''Informs this object that it should display shadows (and/or reflections)  of Mobile objects.  The shadows and reflections will always be shown on the plane of the object pointing upwards on the Y axis--that is to say, the plane with normal (0, 1, 0).  If the object does not have a plane with normal (0, 1, 0), the shadows and reflections will not be displayed correctly.  This method must be used in conjunction with the method  OBJECTMETHOD(Control:enable-shadows). <P> Before using this method, you should also refer to an improved shadowing technique outlined in OBJECTMETHOD(Control.tz:enable-shadow-volumes).  '''

        if (not self.realWorldPointer):
            raise Exception(
                '''method 'catch-shadows' cannot be called before Stationary object is registered.'''
            )

        self.shadowCatcher = 1
        breve.breveInternalFunctionFinder.setShadowCatcher(
            self, self.realWorldPointer, breve.vector(0, 1, 0))
        self.controller.setShadowCatcher()
示例#46
0
文件: Creatures.py 项目: pemby/breve
 def __init__(self):
     breve.PhysicalControl.__init__(self)
     self.blockTexture = None
     self.body = None
     self.flag = None
     self.floor = None
     self.ga = None
     self.parser = None
     self.running = 0
     self.startTexture = None
     self.startlocation = breve.vector()
     VirtualCreatures.init(self)
	def __init__( self ):
		breve.Control.__init__( self )
		self.birds = breve.objectList()
		self.cloudTexture = None
		self.item = None
		self.normalMenu = None
		self.obedientMenu = None
		self.selection = None
		self.vision = None
		self.visionDirection = breve.vector()
		self.wackyMenu = None
		Swarm.init( self )
示例#48
0
	def init( self ):
		self.setShape( breve.createInstances( breve.Shape, 1 ).initWithSphere( 0.400000 ) )
		self.setColor( breve.vector( 1, 0, 0 ) )
		self.enablePhysics()
		self.setE(1)
		self.handleCollisions('BraitenbergTarget', 'accelerate')
		self.handleCollisions('BraitenbergVehicle', 'accelerate')
		self.handleCollisions('BraitenbergWheel', 'accelerate')
		self.handleCollisions('BraitenbergBallSensor', 'accelerate')
		self.handleCollisions('Mobile', 'accelerate')
		self.handleCollisions('Stationary', 'accelerate')
		self.handleCollisions('Link', 'accelerate')
示例#49
0
    def adjustSize(self):
        newScale = 0
        radius = 0

        radius = breve.breveInternalFunctionFinder.sqrt(self, self.energy)
        newScale = ((radius * 2) + 0.000010)
        if (newScale == self.lastScale):
            return

        newScale = (newScale / self.lastScale)
        self.shape.scale(breve.vector(newScale, newScale, newScale))
        self.lastScale = ((radius * 2) + 0.000010)
    def randomizeLocation(self):
        '''Move the Wanderer to a random location within the wander space.'''

        randomVector = breve.vector()

        self.move(
            (self.wanderMag *
             ((2 * breve.randomExpression(self.wanderVec)) - self.wanderVec)))
        randomVector = (breve.randomExpression(
            (2 * self.wanderVec)) - self.wanderVec)
        randomVector = (randomVector / breve.length(randomVector))
        self.setVelocity((self.topVelocity * randomVector))
示例#51
0
    def addLine(self,
                otherObject,
                theColor=breve.vector(0.000000, 0.000000, 0.000000),
                theStyle="----------------"):
        '''Adds a line to be drawn from this object to otherObject.  The line can be removed  later using METHOD(remove-line). <P> The optional argument theColor specifies the color of the line.  The default color is the vector (0, 0, 0), black. <P> The optional argument theStyle specifies a pattern for the line.  theStyle is a  string of 16 spaces and/or dashes which specify the line pattern to be drawn. A dotted line, for example, would use the pattern "- - - - - - - - ".  A thickly dashed line would use the pattern "--------		".  If no style is given, a  solid line is drawn.  <P> If a line to otherObject already exists, its color and/or style will be updated.'''

        line = None

        self.removeLine(otherObject)
        line = breve.createInstances(breve.Line, 1)
        line.connect(self, otherObject, theColor, theStyle)
        self.lines.append(line)
示例#52
0
	def setPatchColorsToChemicalConcentrations( self ):
		color = breve.vector()

		color = breve.vector( 0, 0, 0 )
		breve.breveInternalFunctionFinder.matrix3DSetAll( self, self.tempMatrix, 0.000000 )
		if self.redChemicalMatrix:
			breve.breveInternalFunctionFinder.patchGridCopyColorFrom3DMatrix( self, self.gridPointer, self.redChemicalMatrix.getMatrixPointer(), 0, 1.000000 )
			breve.breveInternalFunctionFinder.matrix3DAddScaled( self, self.tempMatrix, self.redChemicalMatrix.getMatrixPointer(), 0.330000 )


		if self.greenChemicalMatrix:
			breve.breveInternalFunctionFinder.patchGridCopyColorFrom3DMatrix( self, self.gridPointer, self.greenChemicalMatrix.getMatrixPointer(), 1, 1.000000 )
			breve.breveInternalFunctionFinder.matrix3DAddScaled( self, self.tempMatrix, self.greenChemicalMatrix.getMatrixPointer(), 0.330000 )


		if self.blueChemicalMatrix:
			breve.breveInternalFunctionFinder.patchGridCopyColorFrom3DMatrix( self, self.gridPointer, self.blueChemicalMatrix.getMatrixPointer(), 2, 1.000000 )
			breve.breveInternalFunctionFinder.matrix3DAddScaled( self, self.tempMatrix, self.blueChemicalMatrix.getMatrixPointer(), 0.330000 )


		breve.breveInternalFunctionFinder.patchGridCopyColorFrom3DMatrix( self, self.gridPointer, self.tempMatrix, 3, 1.000000 )
示例#53
0
    def myPoint(self, theVertex, theLocation):
        v = breve.vector()
        a = 0

        v = self.cross(theVertex, theLocation)
        a = breve.breveInternalFunctionFinder.angle(self, theVertex,
                                                    theLocation)
        if (breve.length(v) == 0.000000):
            self.rotate(theVertex, 0.100000)
            return

        self.rotate(v, a)
 def mostEnergizedNeighbor(self):
     neighbors = self.getNeighbors()
     me_x = 0
     me_y = 0
     energy = 0
     for neighbor in neighbors:
         if neighbor.isA('Predator') and neighbor.isAlive:
             if neighbor.energy > energy:
                 me_x = neighbor.pos_x - self.pos_x
                 me_y = neighbor.pos_y - self.pos_y
                 energy = neighbor.energy
     self.pushInterpreter.pushVector(breve.vector(me_x, me_y, 0))
示例#55
0
    def register(self,
                 theShape,
                 theLocation=breve.vector(0.000000, 0.000000, 0.000000),
                 theRotation=breve.matrix(1.000000, 0.000000, 0.000000,
                                          0.000000, 1.000000, 0.000000,
                                          0.000000, 0.000000, 1.000000)):
        '''Registers a stationary object using shape theShape at the location specified by theLocation.'''

        self.setShape(theShape)
        self.move(theLocation)
        self.setRotationMatrix(theRotation)
        return self
	def init( self ):
		number = 0
		item = None

		self.locked = 0
		self.setRandomSeedFromDevRandom()
		self.enableFastPhysics()
		self.setIntegrationStep( 0.004000 )
		self.enableLighting()
		self.moveLight( breve.vector( 0, 10, 0 ) )
		self.setBackgroundColor( breve.vector( 0.400000, 0.600000, 0.900000 ) )
		self.setMountainSkybox()
		self.terrain = breve.createInstances( breve.Terrain, 1 )
		self.terrain.generate( 0.340000, 40 )
		self.terrain.setScale( 6 )
		self.terrain.setValleyColor( breve.vector( 0.350000, 0.800000, 0.450000 ) )
		self.terrain.setPeakColor( breve.vector( 1.000000, 1.000000, 1.000000 ) )
		self.enableShadowVolumes()
		self.walker = breve.createInstances( breve.Creature, 1 )
		self.walker.move( breve.vector( 0, 6, 0 ) )
		self.offsetCamera( breve.vector( 3, 13, -13 ) )
		self.watch( self.walker )
		self.monkeys = breve.createInstances( breve.Monkeys, 15 )
		for item in self.monkeys:
			item.setNumber( number )
			number = ( number + 1 )


		self.pickDrivers()
		self.lockMenu = self.addMenu( '''Lock Driver''', 'toggleDriverLock' )
		self.addMenuSeparator()
		self.addMenu( '''Save Current Genome''', 'saveCurrentGenome' )
		self.addMenu( '''Load Into Current Genome''', 'loadIntoCurrentGenome' )
		self.schedule( 'changeDrivers', ( self.getTime() + 20.000000 ) )
		self.displayCurrentDriver()
示例#57
0
文件: Creatures.py 项目: pemby/breve
    def createNode(self, root, n):
        rootNode = None
        nodeParams = breve.objectList()
        size = breve.vector()
        scaleFactor = 0

        self._linkCount = (self._linkCount + 1)
        if ((n > 6) or (self._linkCount > 20)):
            return 0

        nodeParams = root.getParameters()
        scaleFactor = (((6 + 1) -
                        ((0.500000 +
                          (0.450000 * breve.length(nodeParams[10]))) * n)) /
                       (6 + 1))
        rootNode = breve.createInstances(breve.CreaturesLink, 1)
        rootNode.move(breve.vector(0, 15, 0))
        rootNode.setColor((scaleFactor * breve.vector(1, 1, 1)))
        size = ((6 * breve.vector(breve.length(nodeParams[0]),
                                  breve.length(nodeParams[1]),
                                  breve.length(nodeParams[2]))) +
                breve.vector(0.300000, 0.300000, 0.300000))
        rootNode.setColor(
            breve.vector(breve.length(nodeParams[3]),
                         breve.length(nodeParams[4]),
                         breve.length(nodeParams[5])))
        rootNode.setShape(
            breve.createInstances(breve.Cube, 1).initWith(
                (scaleFactor * size)))
        rootNode.setTextureImage(self.controller.getBlockTexture())
        return rootNode
    def init(self):
        self.n = 0
        while (self.n < 10):
            breve.createInstances(breve.BraitenbergLight, 1).move(
                breve.vector((20 * breve.breveInternalFunctionFinder.sin(
                    self, ((self.n * 6.280000) / 10))), 1,
                             (20 * breve.breveInternalFunctionFinder.cos(
                                 self, ((self.n * 6.280000) / 10)))))
            self.n = (self.n + 1)

        self.vehicle = breve.createInstances(breve.BraitenbergVehicle, 1)
        self.watch(self.vehicle)
        self.vehicle.move(breve.vector(0, 2, 18))
        self.leftWheel = self.vehicle.addWheel(
            breve.vector(-0.500000, 0, -1.500000))
        self.rightWheel = self.vehicle.addWheel(
            breve.vector(-0.500000, 0, 1.500000))
        self.leftWheel.setNaturalVelocity(0.000000)
        self.rightWheel.setNaturalVelocity(0.000000)
        self.rightSensor = self.vehicle.addSensor(
            breve.vector(2.000000, 0.400000, 1.500000))
        self.leftSensor = self.vehicle.addSensor(
            breve.vector(2.000000, 0.400000, -1.500000))
        self.leftSensor.link(self.rightWheel)
        self.rightSensor.link(self.leftWheel)
        self.leftSensor.setBias(15.000000)
        self.rightSensor.setBias(15.000000)
        self.video = breve.createInstances(breve.Image, 1)
        self.video.setSize(176, 144)
        self.depth = breve.createInstances(breve.Image, 1)
        self.depth.setSize(176, 144)
        self.startTime = self.getRealTime()
示例#59
0
    def collide(self, food):
        newLoc = breve.vector()

        if food.getOwner():
            return

        if (self.justCollided > 0):
            self.justCollided = 2
            return

        self.justCollided = 2
        if self.carrying:
            newLoc = food.getLocation()
            newLoc = (newLoc + (breve.randomExpression(breve.vector(2, 2, 2)) -
                                breve.vector(1, 1, 1)))
            self.carrying.move(newLoc)
            self.carrying.setOwner(0)
            self.carrying = 0
            return

        food.setOwner(self)
        self.carrying = food
示例#60
0
	def separation(self):
		neighbors = self.getNeighbors()
		s_x = 0
		s_y = 0
		for neighbor in neighbors:
			if neighbor.isA( 'Predator' ) and neighbor.isAlive:
				d = (self.pos_x-neighbor.pos_x)**2+(self.pos_y-neighbor.pos_y)**2
				if 0 < d < self.radius:
					v_x = (self.pos_x - neighbor.pos_x) / d**2
					v_y = (self.pos_y - neighbor.pos_y) / d**2
					s_x += v_x*self.lastScale**2
					s_y += v_y*self.lastScale**2
		self.pushInterpreter.pushVector( breve.vector(s_x,s_y,0) )