summaryrefslogtreecommitdiffstats
path: root/fish_render.py
blob: be94a2358374967a8601712305ea3baf24540689 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

class Fish(object):
    def __init__(self, x, y, width, height, color):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.color = color


class BridgeRender(object):
    WIDTH_SEGMENTS = 200
    HEIGHT_SEGMENTS = 2
    SAMPLES_PER_SEGMENT = 4 # Actual samples is this squared

    def __init__(self, fish):
        self.fish = fish

    def compute_coverage(self, x, y):
        min_x = max(x, self.fish.x - self.fish.width)
        max_x = min(x+1, self.fish.x + self.fish.width)
        min_y = max(y, self.fish.y - self.fish.height)
        max_y = min(y+1, self.fish.y + self.fish.height)

        return (max_x - min_x) * (max_y - min_y)

    def compute_color(self, x, y, base_color):
        cov = compute_coverage(x, y)
        return (cov * self.fish.color) + ((1 - cov) * base_color)