hw9 - self.yVel = yVel return self.yVel def update(self):...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import cTurtle import random class Boid: def __init__(self): self.xPos = random.random() self.yPos = random.random() self.xVel = random.random()-.9 self.yVel = random.random()-.9 self.turtle = cTurtle.Turtle() self.turtle.setWorldCoordinates (0,0,1,1) self.turtle.up() self.turtle.goto(self.xPos, self.yPos) self.turtle.resizemode("user") self.turtle.shape("circle") self.turtle.color("blue") self.turtle.tracer(4) def getXPos(self): print (self.xPos) def setXPos(self, xPos): self.xPos = xPos return self.xPos def getYPos(self): return self.yPos def setYPos (self, yPos): self.yPos = yPos return self.yPos def getXVel(self): return self.xVel def setXVel (self, xVel): self.xVel = xVel return self.xVel def getYVel(self): return self.yVel def setYVel (self, yVel):
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: self.yVel = yVel return self.yVel def update(self): self.xPos = self.xPos + self.xVel if self.xPos <0: self.xPos =0 self.yPos = self.yPos + self.yVel if self.yPos >1: self.yPos = 1 self.turtle.goto(self.xPos, self.yPos) def applyWallAversion (self): if self.xPos<.01: self.xVel = self.xVel + (0.01-self.xPos) if self.xPos<.99: self.xVel = self.xVel + (0.99-self.xPos) if self.yPos<.01: self.yVel = self.yVel + (0.01-self.yPos) if self.yPos>.99: self.yVel = self.yVel + (0.99 - self.yPos) def boidsSimulation (numBoids, numSteps): boidList = for boid in range (numBoids): boidList.append(Boid) for steps in range (numSteps): for boids in boidList: Boid.update(Boid)...
View Full Document

This note was uploaded on 04/26/2011 for the course CPS 324 taught by Professor Safa during the Spring '11 term at Dickinson.

Page1 / 2

hw9 - self.yVel = yVel return self.yVel def update(self):...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online