Example #1
0
    def build_flake(self):
        # Spoke line
        spoke = randint(1, 6)
        first_line = Lines(self.hexes,
                           start=helpfunc.get_random_center(),
                           direction=0,
                           length=spoke,
                           color=white())
        self.line.append(first_line)

        # 2nd line
        spoke2 = randint(0, spoke)
        if first_line.get_line():
            second_line = Lines(self.hexes,
                                start=choice(first_line.get_line()),
                                direction=1,
                                length=spoke2,
                                color=rgb_to_hsv((250, 250, 255)))
            self.line.append(second_line)

            # 3rd line
            spoke3 = randint(0, spoke2)
            if second_line.get_line():
                third_line = Lines(self.hexes,
                                   start=choice(second_line.get_line()),
                                   direction=5,
                                   length=spoke3,
                                   color=rgb_to_hsv((245, 245, 255)))
                self.line.append(third_line)
Example #2
0
    def set_colors(self):

        skies = [(0, 0, 200), (50, 50, 255), (0, 0, 255), (0, 0, 100),
                 (100, 100, 255)]
        grounds = [(255, 255, 0), (200, 255, 0), (0, 25, 0), (200, 200, 0),
                   (100, 200, 0)]

        self.sky_color = rgb_to_hsv(skies[self.scene])
        self.ground_color = rgb_to_hsv(grounds[self.scene])
Example #3
0
    def next_frame(self):

        while True:
            if not self.candles:
                for h in range(NUM_HEXES):
                    self.candles += [
                        Candle(self.hexes, (h, 0, 5), 9),  # center candle
                        Candle(self.hexes, (h, -3, 5), 6),  # left candle
                        Candle(self.hexes, (h, 3, 2), 6)
                    ]  # center candle

            candle_gray = 255 * self.tot_candles() / (20.0 * NUM_HEXES)

            wind = randint(0, 5) if one_in(5) else 10

            self.hexes.black_all_cells()
            # self.hexes.set_all_cells(rgb_to_hsv((0, 0, candle_gray)))  # Set background to blue-ish

            for candle in self.candles:
                candle.draw_candle(
                    rgb_to_hsv((candle_gray, candle_gray, candle_gray)), wind)
                if not candle.burn_candle():
                    self.candles.remove(candle)

            yield self.speed
Example #4
0
    def beacon_shader(self,p):

        # use progress
        if self.show:
            color_hsv = rgb_to_hsv(self.color)  

            if self.all:
                dist_x = 1-abs(p['point'][0])
                dist_y = 1-abs(p['point'][1])
                dist_z = 1-abs(p['point'][2])
                if dist_x < 0.02:
                    return hsv (color_hsv[0], color_hsv[1], 1-dist_x)
                if dist_y < 0.02: 
                    return hsv (color_hsv[0], color_hsv[1], 1-dist_y)
                if dist_z < 0.2:
                    return hsv (color_hsv[0], color_hsv[1], 1-dist_z)
                return (0,0,0)

            else:
                dist = abs(p['point'][2]-1)
                if dist > 0.1:
                    dist=1
                return hsv (color_hsv[0], color_hsv[1], 1-dist)
        else: 
            return (0,0,0)
Example #5
0
 def __init__(self, hexmodel):
     self.name = "Storm"
     self.hexes = hexmodel
     self.drops = []  # List that holds Raindrop objects
     self.bolts = []  # List that holds Lighting bolts
     self.wind = (4 + randint(0, 2)) % 6
     self.speed = 0.1
     self.drop_length = 2
     self.rain_intense = helpfunc.NUM_HEXES
     self.rain_hue = 235  # Grey
     self.rain_color = rgb_to_hsv(
         (self.rain_hue, self.rain_hue, self.rain_hue))
     self.background_hue = 15
     self.background_color = rgb_to_hsv(
         (self.background_hue, self.background_hue, self.background_hue))
     self.clock = 0
Example #6
0
    def next_frame(self):

        self.square.clear()

        while (True):

            for i in range(self.density):
                self.raindrops.add_brick(random_color_range(self.blue, 0.05),
                                         life=self.square.height + 2,
                                         pos=(randint(-10,
                                                      10 + self.square.width),
                                              self.square.height),
                                         length=0,
                                         pitch=1,
                                         length_x=0,
                                         length_y=-1,
                                         dx=self.wind / 10.0,
                                         dy=-1,
                                         accel_x=0,
                                         accel_y=0,
                                         use_faders=False)

            self.raindrops.move_bricks()

            if one_in(20):
                self.density = up_or_down(self.density, 1, 2, 10)

            if one_in(20):
                self.wind = up_or_down(self.wind, 1, -10, 10)
                self.raindrops.set_all_dx(self.wind / 10.0)

            if one_in(500):
                self.square.set_all_cells(rgb_to_hsv((255, 255, 100)))

            yield self.speed  # random time set in init function
Example #7
0
 def __init__(self, hexmodel):
     self.name = "Seasons"
     self.hexes = hexmodel
     self.treespot = []  # List that holds branch cells
     self.leaves = []  # List that holds leaf objects
     self.sky_color = black()  # Set for each season
     self.ground_color = black()  # Set for each season
     self.treecolor = rgb_to_hsv((54, 0, 0))  # Dark brown
Example #8
0
    def draw_stuff(self, clock):
        pos = get_cell((self.h, self.x_coord, self.y_coord))
        color = rgb_to_hsv((self.gray, self.gray, self.gray))

        # Draw two lines
        self.hexes.set_cells(helpfunc.hex_line_in_direction(pos, 1, 1), color)
        hex1 = helpfunc.hex_in_direction(pos, 0, 1)
        self.hexes.set_cells(helpfunc.hex_line_in_direction(hex1, 1, 1), color)
Example #9
0
 def __init__(self, squaremodel):
     self.name = "Rain"
     self.square = squaremodel
     self.raindrops = Bricks(squaremodel)
     self.speed = 0.04
     self.blue = rgb_to_hsv((0, 0, 255))
     self.density = randint(2, 10)
     self.wind = 0
Example #10
0
 def __init__(self, squaremodel):
     self.name = "Fireworks"
     self.square = squaremodel
     self.tails = Bricks(squaremodel, bounce=False)
     self.heads = Bricks(squaremodel, bounce=False)
     self.speed = 0.1
     self.tail_color = rgb_to_hsv((255, 255, 255))  # white
     self.head_color = rand_color()
     self.density = randint(2, 20)
     self.counter = 0
Example #11
0
 def __init__(self, hexmodel):
     self.name = "Driving"
     self.hexes = hexmodel
     self.stuffs = []  # List that holds stuffs objects
     self.sky_color = black()  # Set for each season
     self.ground_color = rgb_to_hsv((255, 255, 0))  # Set for each season
     self.cars_speed = 1.0  # How fast the scene moves
     self.clock = 0
     self.scene = 0
     self.max_scene = 6
Example #12
0
 def __init__(self, hexmodel):
     self.name = "Volcano"
     self.hexes = hexmodel
     self.rocks = []  # List that holds rocks
     self.rock_intense = [randint(3, 8) for _ in helpfunc.all_hexes()
                          ]  # Lower = more rocks
     self.lava_color = random_color(reds=True)
     self.volcano_color = rgb_to_hsv((100, 100, 100))  # Grey: (x,x,x)
     self.background_color = black()
     self.speed = 0.05 * randint(1, 5)
     self.clock = 0
Example #13
0
 def __init__(self, squaremodel):
     self.name = "WavePendulumFilled"
     self.square = squaremodel
     self.speed = 0.05
     self.counter = 0
     self.color = rand_color()
     self.min_freq = 10  # fastest pendulum does this many cycles in one loop
     self.cycle_time = 5  # speed of one cycle
     self.cycles = int(self.cycle_time / self.speed)
     self.black = rgb_to_hsv((0, 0, 0))
     self.gradient = 10
     self.up_down = True
Example #14
0
    def shader(self, p):

        x = p['point'][0]
        dist_x = abs(x - self.dx)   # trail - small is large tail

        if dist_x < self.trail:

            color_hsv = rgb_to_hsv(self.color)  # set the intesity to the distance
            dist_x = dist_x / self.trail

            return hsv (color_hsv[0], color_hsv[1], 1-dist_x)
        else:
            return self.background
Example #15
0
    def shader(self, p):

        z = p['point'][2]
        dist_z = abs(z - self.dz)  

        if dist_z < self.trail:

            color_hsv = rgb_to_hsv(self.color)  # set the intesity to the distance
            dist_z = dist_z / self.trail
    
            return hsv (color_hsv[0], color_hsv[1], 1-dist_z)
            
        else:
            return self.background
Example #16
0
def plot_grid(xs, ys, vals, title, xlabel="", ylabel=""):
    fig, ax = plt.subplots()

    d = 5
    xmin = min(0, min(xs)) - d
    xmax = max(100, max(xs)) + d
    ymin = min(0, min(ys)) - d
    ymax = max(100, max(ys)) + d

    print(int(xmin), int(xmax), int(ymin), int(ymax))
    ax.set_xlim(xmin=xmin, xmax=xmax)
    ax.set_ylim(ymin=ymin, ymax=ymax)

    smallest_val = min(vals)
    biggest_val = max(vals)
    value_range = biggest_val - smallest_val

    smallest_circle = 0.1
    biggest_circle = 2
    circle_range = value_range

    color_range = value_range
    start_color = color.rgb_to_hsv(0, 1, 0)
    end_color = color.rgb_to_hsv(1, 0, 0)

    for (x, y, val) in zip(xs, ys, vals):
        current_color = color.hsv_to_rgb(
            *color.lerp3(start_color, end_color, val -
                         smallest_val, color_range))
        current_radius = smallest_circle + (
            val - smallest_val) * biggest_circle / value_range
        ax.add_artist(plt.Circle((x, y), current_radius, color=current_color))

    plt.xlabel(xlabel)
    plt.ylabel(ylabel)

    plt.title(title)
Example #17
0
    def next_frame(self):

        while self.clock < self.show_length * 2:

            # Background the screen to a shade of blue

            self.hexes.set_all_cells(rgb_to_hsv((0, 0, self.background)))

            # Which sub-show are we in?

            if self.clock > self.show_length:  # in show: Snow Fall

                for i in range(self.rain_intense * helpfunc.NUM_HEXES):
                    self.drops.append(Snow(self.hexes, self.wind))

                # Draw all the snow
                for drop in self.drops:
                    drop.draw_snow()
                    if not drop.move_snow():  # Drop off screen
                        self.drops.remove(drop)

            else:  # in show: Big Flake
                self.big_flake.move_flake()
                self.big_flake.draw_flake()

            self.clock += 1

            if self.clock >= self.show_length * 2:
                self.clock = 0

            # Randomly change the wind direction, speed and drop length

            if helpfunc.one_in(100):
                self.wind = (4 + randint(0, 2)) % 6

            if helpfunc.one_in(100):
                self.rain_intense = helpfunc.up_or_down(
                    self.rain_intense, 1, 1, 5)

            if helpfunc.one_in(50):
                self.speed = helpfunc.up_or_down(self.speed, 0.05, 0.05, 0.5)

            # Randomly change the colors

            if helpfunc.one_in(50):
                self.background = helpfunc.up_or_down(self.background, 4, 50,
                                                      255)

            yield self.speed
Example #18
0
    def draw_candle(self, candle_color, wind):

        # Draw glow
        glow_size = int(self.height / 2)
        glow_cent = self.get_wick() if wind == 10 else hex_in_direction(
            self.get_wick(), wind)
        self.hexes.set_cell(glow_cent, rgb_to_hsv((200, 200, 0)))

        for rings in range(1, glow_size + 1):
            self.hexes.set_cells(
                hex_ring(glow_cent, rings),
                rgb_to_hsv((255 - (rings * 30), 255 - (rings * 30), 0)))

        # Draw wax
        self.draw_line(self.bottom, 2, self.height - 1, candle_color)
        self.draw_line(hex_in_direction(self.bottom, 4), 2, self.height,
                       candle_color)
        self.draw_line(hex_in_direction(self.bottom, 0), 2, self.height,
                       candle_color)

        # Draw Flame
        if one_in(2):
            self.hexes.set_cell(self.get_wick(),
                                rgb_to_hsv((255, randint(125, 255), 0)))
Example #19
0
    def next_frame(self):

        while True:
            self.hexes.set_all_cells(rgb_to_hsv(
                (255, 255, 255)))  # Set background to white

            for eye in self.eyes:
                eye.draw_ball()
                eye.draw_lids()
                eye.draw_rays()
                eye.wink()
                eye.move_eye_ball()
                eye.update_rays()

            yield self.speed  # random time set in init function
Example #20
0
def build_set(_dict, sort_by='hsv'):
    image_list = []
    _list = _dict.keys()
    if sort_by == 'hls':
        _list.sort(key=lambda rgb: color.rgb_to_hls(to_tuple(rgb)))
    elif sort_by == 'hsl':
        _list.sort(key=lambda rgb: color.rgb_to_hsl(to_tuple(rgb)))
    elif sort_by == 'hsv':
        _list.sort(key=lambda rgb: color.rgb_to_hsv(to_tuple(rgb)))
    elif sort_by == 'lum':
        _list.sort(key=lambda rgb: color.luminance(to_tuple(rgb)))

    rgb_list = map(to_tuple, _list)
    for c_item in _list:
        image_list += _dict.get("{}".format(c_item))

    return image_list
Example #21
0
    def shader(self,p):

        x = p['point'][0] 
        y = p['point'][1]
        z = p['point'][2]

        x_ = x*cos(self.angle)-y*sin(self.angle)
        y_ = x*sin(self.angle)+y*cos(self.angle)

        col = rgb_to_hsv(self.flag)

        if (abs(x_)<0.3 and abs(z)<0.6 and y_>0):
            return hsv(col[0], col[1], 1-abs(x_))
            #return hsv(0.3, 0, 1-abs(x_))
        if (abs(z)<0.2 and abs(x_)<0.6 and y_>0):
            return hsv(col[0], col[1], 1-abs(z))
            #return hsv(0.3, 0, 1-abs(z))

        # background
        return self.background
Example #22
0
    def shader(self, p):

        x = p['point'][0]
        y = p['point'][1]
        z = p['point'][2]
     
        x_rot = x
        # y_rot = y                   # will hold the rotated variables

        # moving packman - we need to rotate x and y
        if self.move:
            rotate = self.progress * 2*pi   # mouth opens 4 times and one
                                            # progress is one revolution
                                            # map to circle

            x_rot = x * cos(rotate) - y * sin(rotate)           
            #y_rot = y * cos(rotate) + x * sin(rotate)

        # This is PacMan, believe it or not, well, almost
        # y_ = 1 - x_rot**2 - z**2
        z_ = tan(self.angle) * x_rot

        # Learning: The perfect math does not always create the best visual representation
        # and cheating is more fun and faster too ;)

        if x_rot < 0: return self.color     # the non-mouth half of pacman
        #if y_ < abs(y_rot) and z_ < abs(z):
        if z_ < abs(z):
            color_hsv = rgb_to_hsv(self.color)  
            # -- dist = ((x_rot-x)**2 + (y_rot-y_)**2 + (z-z_)**2)  * 4
            # working: dist = ((y_rot-y_)**2 + (z-z_)**2)  * 4
            dist = abs(z-z_)
            intensity = 1
            if dist < 0.1:
                #intensity = 10*dist
                intensity = 10*dist
            #if dist > 1: dist = 1
            # intensity = cos(dist)
            return hsv (color_hsv[0], color_hsv[1], intensity)
        else:
            return self.background
Example #23
0
    def rotate_x_shader(self, p):

        y = p['point'][1]
        x = p['point'][0]


        # the shape itself
        z_ = y*sin(self.angle)+z*cos(self.angle)

        # don't change the z-position
        dist_z = abs(z_)  
        
        if dist_z < self.trail:

            color_hsv = rgb_to_hsv(self.color)  # set the intesity to the distance
            dist_z = dist_z / self.trail
    
            return hsv (color_hsv[0], color_hsv[1], 1-dist_z)
            
        else:
            return self.background
Example #24
0
    def shader(self, p):

        z = p['point'][2]
        y = p['point'][1]
        x = p['point'][0]

        # shape tilt
        x_ = x*cos(self.tilt)-z*sin(self.tilt)
        z_ = z*sin(self.tilt)+x*cos(self.tilt)
        y_ = y

        # rotate
        x__ = x_
        y__ = y_*cos(self.angle)-z_*sin(self.angle)
        z__ = y_*sin(self.angle)+z_*cos(self.angle)

        self.dz = 0
        dist_z = abs(z__ - self.dz)  
        

        #dist_z = abs(z_ - self.dz)  
        #dist = sqrt((z_-z) ** 2 + (y_-y) ** 2 + (x_-x) ** 2)
        #dist_2 = sqrt((z_-z) **2 + (y_-y) **2)

        #if (abs(x_)<0.3 and abs(y_)<0.6 and y_>0):
        #if (abs(x_)<self.trail and abs(y_)<self.trail and abs(z_)<self.trail):

        #if dist_z < self.trail and dist_y < self.trail:
        if dist_z < self.trail:

            color_hsv = rgb_to_hsv(self.color)  # set the intesity to the distance
            dist_z = dist_z / self.trail
    
            #return hsv (color_hsv[0], color_hsv[1], 1-dist_z)
            return hsv (color_hsv[0], color_hsv[1], 1-dist_z)
            
        else:
            return self.background
Example #25
0
    def Testing_shader(self, p):

        x = p['point'][0]
        y = p['point'][1]
        z = p['point'][2]
        #print 's', self.z

        x_ = cos(self.theta) * sin(self.phi)
        y_ = cos(self.theta) * cos(self.phi)
        z_ = sin(self.theta)
        dist = sqrt((z_-z) ** 2 + (y_-y) ** 2 + (x_-x) ** 2)

        if dist < self.trail:

            color_hsv = rgb_to_hsv(self.color)  # set the intesity to the distance
            #return hsv (color_hsv[0], color_hsv[1], 1.0-dist*1/self.trail)
            dist = dist / self.trail
            intensity = 1-dist
            # intensity = cos(dist)
            return hsv (color_hsv[0], color_hsv[1], intensity)

        else:
            return self.background
Example #26
0
def build_set_complementary(_dict, sort_by='hsv', every=4):
    image_list = []
    _list = _dict.keys()
    if sort_by == 'hls':
        _list.sort(key=lambda rgb: color.rgb_to_hls(to_tuple(rgb)))
    elif sort_by == 'hsl':
        _list.sort(key=lambda rgb: color.rgb_to_hsl(to_tuple(rgb)))
    elif sort_by == 'hsv':
        _list.sort(key=lambda rgb: color.rgb_to_hsv(to_tuple(rgb)))
    elif sort_by == 'lum':
        _list.sort(key=lambda rgb: color.luminance(to_tuple(rgb)))

    n = 0
    for c_item in _list:
        if n % every == 0:
            complementary = color.complementary_rgb(to_tuple(c_item))
            closest_color = color.find_closest(complementary,
                                               map(to_tuple, _list))
            image_list += _dict.get("{}".format(str(closest_color)))

        image_list += _dict.get("{}".format(c_item))
        n += 1

    return image_list
Example #27
0
    def next_frame(self):

        while (True):

            # Start new rocks
            for h in helpfunc.all_hexes():
                if helpfunc.one_in(self.rock_intense[h]):
                    self.rocks.append(Rock(self.hexes, h, self.lava_color))

            # Background the screen - occasionally set to lava red
            if helpfunc.one_in(100):
                self.hexes.set_all_cells(rgb_to_hsv((200, 0, 0)))
            else:
                self.hexes.black_all_cells()

            self.draw_volcano()

            # Draw all the rocks
            for rock in self.rocks:
                rock.draw_rock()
                if not rock.move_rock():  # Is rock dead?
                    self.rocks.remove(rock)

            self.clock += 1
            for h in helpfunc.all_hexes():
                if helpfunc.one_in(20):
                    self.rock_intense[h] = helpfunc.up_or_down(
                        self.rock_intense[h], 1, 3, 8)

            if self.clock > 100:
                self.clock = 0

            if helpfunc.one_in(10):
                self.lava_color = random_color_range(self.lava_color, 0.05)

            yield self.speed
Example #28
0
    def shader_rotate_y(self, p):

        z = p['point'][2]
        y = p['point'][1]
        x = p['point'][0]

        # shape tilt
        z_ = z*sin(self.tilt)+x*cos(self.tilt)
        y_ = y

        # rotate
        z__ = y_*sin(self.angle)+z_*cos(self.angle)

        dist_z = abs(z__)  
        
        if dist_z < self.trail:

            color_hsv = rgb_to_hsv(self.color)  # set the intesity to the distance
            dist_z = dist_z / self.trail
    
            return hsv (color_hsv[0], color_hsv[1], 1-dist_z)
            
        else:
            return self.background
Example #29
0
 def __init__(self, hexmodel, h):
     super(Tree, self).__init__(hexmodel, h)
     self.y_coord = randint(0, 5)
     self.color = rgb_to_hsv((0, randint(100,
                                         255), 0))  # Some sort of green
     self.trunk = rgb_to_hsv((randint(40, 60), 0, 0))  # Dark Brown
Example #30
0
 def turn_red(self):
     r, g, b = self.color
     self.color = rgb_to_hsv((255, g, 0))
Example #31
0
    def draw_stuff(self, clock):
        pos = get_cell((self.h, self.x_coord, self.y_coord))
        color = rgb_to_hsv((self.gray, self.gray, self.gray))

        self.hexes.set_cells(get_triangle(pos, self.size, self.size), color)
Example #32
0
    def next_frame(self):

        self.fill_branches()  # Figure out the position of the tree branches

        while True:

            # Spring

            self.sky_color = rgb_to_hsv((100, 100, 255))
            self.ground_color = rgb_to_hsv((154, 150, 100))

            self.draw_ground(self.sky_color, self.ground_color)
            self.draw_tree()
            yield 5

            self.sky_color = rgb_to_hsv((50, 50, 255))
            self.ground_color = rgb_to_hsv((54, 255, 50))
            self.draw_ground(self.sky_color, self.ground_color)
            self.draw_tree()
            yield 0.1

            shuffle(self.treespot)
            for cell in self.treespot:
                if self.hexes.cell_exists(cell):
                    self.hexes.set_cell(cell, rgb_to_hsv((255, 230, 230)))
                    yield 0.2

            shuffle(self.treespot)
            for cell in self.treespot:
                if self.hexes.cell_exists(cell):
                    self.hexes.set_cell(cell, rgb_to_hsv((0, 255, 0)))
                    yield 0.2

            # Big leaves

            shuffle(self.treespot)

            for cell in self.treespot:
                green = rgb_to_hsv((0, randint(50, 255), 0))

                self.leaves.append(Leaf(self.hexes, cell, green))

                for cell in helpfunc.hex_ring(cell, 1):
                    self.leaves.append(Leaf(self.hexes, cell, green))

                self.draw_leaves()
                yield 0.5

            # Apples

            apple_color = rgb_to_hsv((255, 0, 0))
            for i in range(5):
                apple = choice(self.treespot)
                if self.hexes.cell_exists(apple):
                    self.hexes.set_cell(apple, apple_color)
                yield 0.5

            yield 5

            # Fall foliage

            shuffle(self.leaves)

            for leaf in self.leaves:
                leaf.turn_red()

                self.draw_leaves()
                yield 0.05

            # Drop leaves

            self.sky_color = rgb_to_hsv((0, 0, 200))
            self.ground_color = rgb_to_hsv((54, 155, 50))

            shuffle(self.leaves)

            for leaf in self.leaves:
                leaf.fall()

                for leaf2 in self.leaves:
                    leaf2.move_leaf()

                self.draw_ground(self.sky_color, self.ground_color)
                self.draw_tree()
                self.draw_leaves()
                yield 0.1

            self.sky_color = rgb_to_hsv((0, 0, 100))
            self.ground_color = rgb_to_hsv((25, 105, 25))

            for _ in range(10):
                for l2 in self.leaves:
                    l2.move_leaf()

                self.draw_ground(self.sky_color, self.ground_color)
                self.draw_tree()
                self.draw_leaves()
                yield 0.1

            self.sky_color = rgb_to_hsv((0, 0, 50))
            self.ground_color = rgb_to_hsv((25, 50, 25))

            # Remove leaves

            for leaf in self.leaves:
                self.leaves.remove(leaf)
                self.draw_ground(self.sky_color, self.ground_color)
                self.draw_tree()
                self.draw_leaves()
                yield 0.1

            yield 5

            # Destroy tree

            self.branches = []
            self.hexes.black_all_cells()
            yield 4
Example #33
0
    def next_frame(self):

        while True:

            for _ in range(self.rain_intense):
                if len(self.drops) <= self.clock / (20 * helpfunc.NUM_HEXES):
                    self.drops.append(
                        Raindrop(hexmodel=self.hexes,
                                 color=self.rain_color,
                                 direction=self.wind))

            self.hexes.set_all_cells(self.background_color)

            # Draw all the drops
            for drop in self.drops:
                for _ in range(self.drop_length):
                    drop.draw_drop()
                    if not drop.move_drop():  # Drop off screen
                        self.drops.remove(drop)
                        break

            self.clock = (self.clock + 1) % 100

            # Randomly change the wind direction and drop length

            if helpfunc.one_in(100):
                self.wind = (4 + randint(0, 2)) % 6

            if helpfunc.one_in(100):
                self.drop_length = helpfunc.up_or_down(self.drop_length, 1, 1,
                                                       3)

            if helpfunc.one_in(100):
                self.rain_intense = helpfunc.up_or_down(
                    self.rain_intense, 1, 1, 5)

            # Randomly change the colors

            if helpfunc.one_in(50):
                self.rain_hue = helpfunc.up_or_down(self.rain_hue, 4, 220, 255)
                self.rain_color = rgb_to_hsv(
                    (self.rain_hue, self.rain_hue, self.rain_hue))

            if helpfunc.one_in(50):
                self.background_hue = helpfunc.up_or_down(
                    self.background_hue, 4, 0, 50)
                self.background_color = rgb_to_hsv(
                    (self.background_hue, self.background_hue,
                     self.background_hue))

            # draw flash lighting

            if helpfunc.one_in(100):
                self.hexes.set_all_cells(rgb_to_hsv((255, 255, 127)))
                yield 0.3

            # draw bolt lighting - a bolt is just a quickly-moving raindrop that does not erase

            if helpfunc.one_in(50):

                # set background to dark blue
                self.hexes.set_all_cells(rgb_to_hsv(
                    (0, 0, 127)))  # Dark blue background
                yield 0.05

                for _ in range(
                        randint(
                            1 * helpfunc.NUM_HEXES, 3 *
                            helpfunc.NUM_HEXES)):  # number of lighting bolts
                    self.bolts.append(
                        Raindrop(hexmodel=self.hexes,
                                 color=rgb_to_hsv((255, 255, 0)),
                                 direction=5))

                for _ in range(10):  # bolt length
                    yield 0.05

                    # draw all the bolts
                    for bolt in self.bolts:
                        bolt.draw_drop()
                        if helpfunc.one_in(8):
                            branch = Raindrop(hexmodel=self.hexes,
                                              color=rgb_to_hsv((255, 255, 0)),
                                              direction=5)
                            branch.set_pos(branch.pos)
                            branch.wiggle_drop()
                            self.bolts.append(branch)
                        if helpfunc.one_in(5):
                            bolt.wiggle_drop()
                        if not bolt.move_drop():  # Drop off screen
                            self.bolts.remove(bolt)

                    yield 0.05

                self.bolts = []  # need to clear bolts

            yield self.speed
Example #34
0
 def __init__(self, hexmodel, h):
     super(RedTree, self).__init__(hexmodel, h)
     red = randint(200, 255)
     self.color = rgb_to_hsv(
         (randint(200, 255), randint(0, red), 0))  # Some sort of yellow/red