import random class Fish: def __init__(self, name): self.name = name self.x = random.randint(0, 800) self.y = random.randint(0, 600) self.z = random.random() self.speed = 0 self.direction = "left" self.rotation = 0 print("Hi, I am a fish named", self.name) fish1 = Fish("Nemo") fish1 fish2 = Fish("Dori") fish2.name fish2.x, fish2.y fish1.x, fish1.y fish2.z from Graphics import Picture, Window window = Window(300, 200) pic = Picture("fish1.gif") pic.draw(window) pic.outline = None import random from Graphics import Picture, Window, Color class Fish: def __init__(self, filename): self.filename = filename self.picture = Picture(filename) self.picture.outline = None self.x = random.randint(0, 500) self.y = random.randint(0, 500) self.z = random.random() self.speed = 2 self.direction = "right" self.rotation = 0 def putInOcean(self, ocean): self.ocean = ocean self.picture.draw(ocean) self.picture.moveTo(self.x, self.y) def step(self): if self.direction == "left": self.x = self.x + self.speed else: self.x = self.x - self.speed if self.x > ocean.width: ## flip image self.direction = "left" if self.x < 0: ## flip image self.direction = "right" self.picture.moveTo(self.x, self.y) ocean = Window(500, 500) ocean.setBackground(Color(0, 0, 255)) fish = Fish("fish1.gif") fish.putInOcean(ocean) while True: fish.step() ocean.step() fish.step()