Return a dictionary that represents a fish.
()
| 100 | |
| 101 | |
| 102 | def generateFish(): |
| 103 | """Return a dictionary that represents a fish.""" |
| 104 | fishType = random.choice(FISH_TYPES) |
| 105 | |
| 106 | # Set up colors for each character in the fish text: |
| 107 | colorPattern = random.choice(('random', 'head-tail', 'single')) |
| 108 | fishLength = len(fishType['right'][0]) |
| 109 | if colorPattern == 'random': # All parts are randomly colored. |
| 110 | colors = [] |
| 111 | for i in range(fishLength): |
| 112 | colors.append(getRandomColor()) |
| 113 | if colorPattern == 'single' or colorPattern == 'head-tail': |
| 114 | colors = [getRandomColor()] * fishLength # All the same color. |
| 115 | if colorPattern == 'head-tail': # Head/tail different from body. |
| 116 | headTailColor = getRandomColor() |
| 117 | colors[0] = headTailColor # Set head color. |
| 118 | colors[-1] = headTailColor # Set tail color. |
| 119 | |
| 120 | # Set up the rest of fish data structure: |
| 121 | fish = {'right': fishType['right'], |
| 122 | 'left': fishType['left'], |
| 123 | 'colors': colors, |
| 124 | 'hSpeed': random.randint(1, 6), |
| 125 | 'vSpeed': random.randint(5, 15), |
| 126 | 'timeToHDirChange': random.randint(10, 60), |
| 127 | 'timeToVDirChange': random.randint(2, 20), |
| 128 | 'goingRight': random.choice([True, False]), |
| 129 | 'goingDown': random.choice([True, False])} |
| 130 | |
| 131 | # 'x' is always the leftmost side of the fish body: |
| 132 | fish['x'] = random.randint(0, WIDTH - 1 - LONGEST_FISH_LENGTH) |
| 133 | fish['y'] = random.randint(0, HEIGHT - 2) |
| 134 | return fish |
| 135 | |
| 136 | |
| 137 | def simulateAquarium(): |
no test coverage detected