def drawWaves(self): egi.green_pen() seed = self.world._clock * 2 water = self.water egi.set_stroke(2) egi.set_pen_color(color=rgba(water[0], 0.5)) egi.unclosed_shape( self.createWave(seed=seed, amplitude=7, width=self.size.width, start=Vector2D(self.box.left, self.box.top + 10))) egi.set_pen_color(color=rgba(water[1], 0.5)) self.mainWave = self.createWave(seed=seed / 2, amplitude=3, width=self.size.width, start=Vector2D(self.box.left, self.box.top + 0)) egi.unclosed_shape(self.mainWave) egi.set_pen_color(color=rgba(water[2], 0.5)) egi.unclosed_shape( self.createWave(seed=seed / 3, amplitude=10, width=self.size.width, start=Vector2D(self.box.left, self.box.top + 0)))
def __init__(self, world=None, scale=30.0, mass=1.0): self.super = super(Hunter, self) self.super.__init__(world=world, scale=scale, mass=mass, ) print 'Hunter, do your thing!' self._stats = { 'body': 2, 'mass': 5.8, 'maxSpeed': 50, 'wanderDistance': 520, 'wanderRadius': 30 } # Set up some rendering properties # Colors self.sleepColor = rgba('8e4bb5') # purple self.awakeColor = rgba('e41414') # red self.sleepTime = (9, 12) self.awakeTime = (5, 8) self.initShape() self.varyVelocity = False self.feedRadius = 30 self.awake = True self.toggleAwake() self.sightCircle = { 'pos': self.pos.copy(), 'distance': 80, 'radius': 250 } self.sightCircle['radiusSq'] = self.sightCircle['radius']**2 self.size = 50 # Set up the states # Acceleratino forces will be self._state = 'patrol' self._states = DictWrap({ 'patrol': { 'speedMultiplier': 0.5, 'massMultiplier': 1, 'wanderInfluence': 0.2, 'feelerPercentage': 2.0, 'acceleration': self.patrolSteer } }) # Calculates stats based on our current size, using the # child/parent scales self.updateStats() self.vehicle_shape = self.fishShape # get an initial shape just in case self.vel.x = -self.maxSpeed
def getSickColor(self): parentSickColor = rgba('27c8f0') if(self.isParent): return parentSickColor return self.sickColor
def getSickColor(self): parentSickColor = rgba('27c8f0') if (self.isParent): return parentSickColor return self.sickColor
def drawWaves(self): egi.green_pen() seed = self.world._clock * 2 water = self.water egi.set_stroke(2) egi.set_pen_color(color=rgba(water[0], 0.5)) egi.unclosed_shape(self.createWave(seed= seed, amplitude = 7, width = self.size.width, start = Vector2D(self.box.left, self.box.top + 10) )) egi.set_pen_color(color=rgba(water[1], 0.5)) self.mainWave = self.createWave(seed= seed/2, amplitude = 3, width = self.size.width, start = Vector2D(self.box.left, self.box.top + 0) ) egi.unclosed_shape(self.mainWave) egi.set_pen_color(color=rgba(water[2], 0.5)) egi.unclosed_shape(self.createWave(seed= seed/3, amplitude = 10, width = self.size.width, start = Vector2D(self.box.left, self.box.top + 0) ))
def drawEye(self, color=None): if(self.dead): egi.set_pen_color(self.color) egi.cross(self.renderPosition + self.side * self.body, self.body * 5) else: egi.set_pen_color(rgba('fff', 0.5)) egi.circle(self.renderPosition + self.side * self.body, self.body)
def drawEye(self, color=None): if (self.dead): egi.set_pen_color(self.color) egi.cross(self.renderPosition + self.side * self.body, self.body * 5) else: egi.set_pen_color(rgba('fff', 0.5)) egi.circle(self.renderPosition + self.side * self.body, self.body)
def drawWalls(self): tank = '0e59cb' egi.set_pen_color(color=rgba(tank, 0.6)) egi.set_stroke(2) self.tankShape[0].y = self.mainWave[0].y self.tankShape[-1].y = self.mainWave[-1].y egi.unclosed_shape(self.tankShape)
def drawWalls(self): tank = '0e59cb' egi.set_pen_color(color=rgba(tank, 0.6)) egi.set_stroke(2) self.tankShape[0].y = self.mainWave[0].y self.tankShape[-1].y = self.mainWave[-1].y egi.unclosed_shape(self.tankShape)
def getHealthyColor(self): parentColor = rgba('f43ca0') if (self.isParent): return parentColor colors = self.regularColors return (uniform(colors[0][0], colors[1][0]), uniform(colors[0][1], colors[1][1]), uniform(colors[0][2], colors[1][2]), uniform(0.8, 1.0))
def getHealthyColor(self): parentColor = rgba('f43ca0') if(self.isParent): return parentColor colors = self.regularColors return (uniform(colors[0][0], colors[1][0]), uniform(colors[0][1], colors[1][1]), uniform(colors[0][2], colors[1][2]), uniform(0.8, 1.0))
def __init__(self, world=None): self.world = world self.pos = Vector2D() self.vel = Vector2D() self.maxAirSpeed = 500 self.maxWaterSpeed = 40 self.boundingRadius = uniform(3, 7) self.color = rgba('ffe400') self.eaten = False self.heading = Vector2D(0, 1) self.side = self.heading.perp()
def __init__(self, world=None): self.world = world self.pos = Vector2D() self.vel = Vector2D() self.maxAirSpeed = 500 self.maxWaterSpeed = 40 self.boundingRadius = uniform(3, 7) self.color = rgba('ffe400') self.eaten = False self.heading = Vector2D(0, 1) self.side = self.heading.perp()
def __init__(self, width=900, height=700, antialiased=True): self.width = width self.height = height self.antialiased = antialiased self.backgroundColor = rgba('1d1f21') # Dull grey # Create the pyglet window and context self.createWindow() # Make and clear the world self.resetWorld() # Make sure everything's in place and sized correctly self.on_resize(self.width, self.height) # Start the game loop! self.gameLoop()
def __init__(self, world=None): self.world = world self.pos = Vector2D() self.vel = Vector2D() self.scale = Vector2D() * 30 self.maxSpeed = uniform(5, 8) self.boundingRadius = uniform(25, 80) self.edges = randrange(7, 12) self.rotation = uniform(-0.05 / 3, 0.05 / 3) self.color = rgba('25a000') self.heading = Vector2D(0, 1) self.side = self.heading.perp() self.rockShape = self.getRockShape()
def __init__(self, world=None): self.world = world self.pos = Vector2D() self.vel = Vector2D() self.scale = Vector2D() * 30 self.maxSpeed = uniform(5, 8) self.boundingRadius = uniform(25, 80) self.edges = randrange(7, 12) self.rotation = uniform(-0.05/3, 0.05/3) self.color = rgba('25a000') self.heading = Vector2D(0, 1) self.side = self.heading.perp() self.rockShape = self.getRockShape()
def createWindow(self): self.win = None if(self.antialiased): config = pyglet.gl.Config(sample_buffers=1, samples=4, double_buffer=True) self.win = window.Window(width=self.width, height=self.height, vsync=True, resizable=True, config=config) else: self.win = window.Window(width=self.width, height=self.height, vsync=True, resizable=True) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) # needed so that egi knows where to draw egi.InitWithPyglet(self.win) # prep the fps display self.fps_display = clock.ClockDisplay() self.fps_display.label.color = rgba('fff', 0.05) # register key and mouse event handlers self.win.push_handlers(self.on_key_press) self.win.push_handlers(self.on_mouse_press) self.win.push_handlers(self.on_resize)
def __init__(self, world=None, scale=30.0, mass=1.0): self.super = super(Guppy, self) self.super.__init__(world=world, scale=scale, mass=mass) print 'Guppy, ' + choice(['I choose you!', 'get out there!', 'do your thang!', 'swim allll up in this!', 'not splash again!', 'evolve already! God.']) # Set up some rendering properties # Colors self.sickColor = rgba('2fc900') self.deadColor = rgba('973500') self.regularColors = [ rgba('ffae00'), rgba('ff8400') ] self.initShape() self._sicknessDomain = (0.0, 100.0) self._sickness = self._sicknessDomain[0] # self._sickness = 0 self.sicknessRate = 1 self.varyVelocity = False self.feedRadius = 20 self.food = [] self.isParent = False self.recalculateColor() # Child/parent value pairs for our stats. # Scales are calculated from these, mapped to the size self._sizes = (0.0, 20.0) self._stats = DictWrap({ 'body': (0.7, 2.0), 'mass': (1.2, 1.5), 'speed': (200, 100), 'flockingInfluence': (0.25, 0), 'wanderDistance': (40, 50), 'wanderRadius': (2.2 * self.scaleValue, 2.4 * self.scaleValue), 'neighbourDistance': (100, 300) }) # Set up the states # Acceleratino forces will be self._state = 'idle' self._states = DictWrap({ 'idle': { 'speedMultiplier': 0.5, 'massMultiplier': 1, 'wanderInfluence': 0.9, 'feelerPercentage': 1.5, 'acceleration': self.idleSteer }, 'seekFood': { 'speedMultiplier': 2.5, 'massMultiplier': 0.5, 'wanderInfluence': 0.1, 'feelerPercentage': 0.5, 'acceleration': self.feedingSteer }, 'hide': { 'speedMultiplier': 5.5, 'massMultiplier': 0.5, 'wanderInfluence': 0.1, 'feelerPercentage': 0.3, 'acceleration': self.scaredSteer }, 'dead': { 'speedMultiplier': 1.0, 'massMultiplier': 1.0, 'wanderInfluence': 0.1, 'feelerPercentage': 0.5, 'acceleration': self.deadSteer } }) self._size = self._sizes[0] self.maxCenterForce = 250 # Calculates stats based on our current size, using the # child/parent scales self.updateStats() self.vehicle_shape = self.fishShape # get an initial shape just in case
def __init__(self, world=None, scale=30.0, mass=1.0): self.super = super(Guppy, self) self.super.__init__(world=world, scale=scale, mass=mass) print 'Guppy, ' + choice([ 'I choose you!', 'get out there!', 'do your thang!', 'swim allll up in this!', 'not splash again!', 'evolve already! God.' ]) # Set up some rendering properties # Colors self.sickColor = rgba('2fc900') self.deadColor = rgba('973500') self.regularColors = [rgba('ffae00'), rgba('ff8400')] self.initShape() self._sicknessDomain = (0.0, 100.0) self._sickness = self._sicknessDomain[0] # self._sickness = 0 self.sicknessRate = 1 self.varyVelocity = False self.feedRadius = 20 self.food = [] self.isParent = False self.recalculateColor() # Child/parent value pairs for our stats. # Scales are calculated from these, mapped to the size self._sizes = (0.0, 20.0) self._stats = DictWrap({ 'body': (0.7, 2.0), 'mass': (1.2, 1.5), 'speed': (200, 100), 'flockingInfluence': (0.25, 0), 'wanderDistance': (40, 50), 'wanderRadius': (2.2 * self.scaleValue, 2.4 * self.scaleValue), 'neighbourDistance': (100, 300) }) # Set up the states # Acceleratino forces will be self._state = 'idle' self._states = DictWrap({ 'idle': { 'speedMultiplier': 0.5, 'massMultiplier': 1, 'wanderInfluence': 0.9, 'feelerPercentage': 1.5, 'acceleration': self.idleSteer }, 'seekFood': { 'speedMultiplier': 2.5, 'massMultiplier': 0.5, 'wanderInfluence': 0.1, 'feelerPercentage': 0.5, 'acceleration': self.feedingSteer }, 'hide': { 'speedMultiplier': 5.5, 'massMultiplier': 0.5, 'wanderInfluence': 0.1, 'feelerPercentage': 0.3, 'acceleration': self.scaredSteer }, 'dead': { 'speedMultiplier': 1.0, 'massMultiplier': 1.0, 'wanderInfluence': 0.1, 'feelerPercentage': 0.5, 'acceleration': self.deadSteer } }) self._size = self._sizes[0] self.maxCenterForce = 250 # Calculates stats based on our current size, using the # child/parent scales self.updateStats() self.vehicle_shape = self.fishShape # get an initial shape just in case
def __init__(self, world=None, scale=30.0, mass=1.0): self.super = super(Hunter, self) self.super.__init__( world=world, scale=scale, mass=mass, ) print 'Hunter, do your thing!' self._stats = { 'body': 2, 'mass': 5.8, 'maxSpeed': 50, 'wanderDistance': 520, 'wanderRadius': 30 } # Set up some rendering properties # Colors self.sleepColor = rgba('8e4bb5') # purple self.awakeColor = rgba('e41414') # red self.sleepTime = (9, 12) self.awakeTime = (5, 8) self.initShape() self.varyVelocity = False self.feedRadius = 30 self.awake = True self.toggleAwake() self.sightCircle = { 'pos': self.pos.copy(), 'distance': 80, 'radius': 250 } self.sightCircle['radiusSq'] = self.sightCircle['radius']**2 self.size = 50 # Set up the states # Acceleratino forces will be self._state = 'patrol' self._states = DictWrap({ 'patrol': { 'speedMultiplier': 0.5, 'massMultiplier': 1, 'wanderInfluence': 0.2, 'feelerPercentage': 2.0, 'acceleration': self.patrolSteer } }) # Calculates stats based on our current size, using the # child/parent scales self.updateStats() self.vehicle_shape = self.fishShape # get an initial shape just in case self.vel.x = -self.maxSpeed