def create_tree(self, start_pos, heading, current_length, end_length, current_line_list=None, angle_change=45,
                    len_dec=50, width=1, width_dec=100, level=0):
        if current_line_list is None:
            current_line_list = []
        if current_length > end_length:
            p = start_pos.get_point_on_line(heading, current_length)
            current_line_list.append(Branch((p.x, p.y), (start_pos.x, start_pos.y), width=width, level=level))

            level += 1

            if level > self.max_level:
                self.max_level = level

            # create left branch
            current_line_list = self.create_tree(p, heading - random_if_range(angle_change),
                                                 current_length * random_if_range(len_dec) / 100, end_length,
                                                 current_line_list, angle_change, len_dec,
                                                 width * random_if_range(width_dec)/100, width_dec, level)
            # create right branch
            current_line_list = self.create_tree(p, heading + random_if_range(angle_change),
                                                 current_length * random_if_range(len_dec) / 100, end_length,
                                                 current_line_list, angle_change, len_dec,
                                                 width * random_if_range(width_dec)/100, width_dec, level)

        else:  # when branch ends(minimum size reached) add leaf
            if random.randrange(4) == 0:  # 1 in 4 chance of having a leaf on the end of a branch
                self.leaves.append(Leaf(start_pos.get(True), c.random_color(self.lCRange[0], self.lCRange[1],
                                                                            self.lColor, random.randrange(50, 100)),
                                        random.randrange(6)))
                if random.randrange(5) == 0:
                    self.leaves[-1].color = c.random_color(self.lCRange[0], self.lCRange[1],
                                                           "b", random.randrange(10, 100))
        return current_line_list
Beispiel #2
0
 def __init__(self, hexmodel):
     self.name = "Exploding spinners"
     self.hexes = hexmodel
     self.spinners = []  # List that holds Spinner objects
     self.speed = random() + 0.05
     self.explode_color = random_color()  # Color for exploding spinner
     self.spincolor = random_color()  # Spinner color
     self.time = 0
Beispiel #3
0
 def __init__(self, hexmodel):
     self.name = "Spinners"
     self.hexes = hexmodel
     self.bullets = []  # List that holds Bullets objects
     self.speed = random() + 0.05
     self.background = random_color()  # Background color
     self.spincolor = random_color()  # Spinner color
     self.center = helpfunc.get_center(helpfunc.get_random_hex())
     self.time = 0
Beispiel #4
0
 def __init__(self, hexmodel):
     self.name = "Dendrons"
     self.hexes = hexmodel
     self.live_dendrons = []  # List that holds Dendron objects
     self.speed = 0.02
     self.main_color = random_color()  # Main color of the show
     self.inversion = randint(0,1)  # Toggle for effects
Beispiel #5
0
 def __init__(self, hexmodel):
     self.name = "Branches"
     self.hexes = hexmodel
     self.live_branches = []  # List that holds Branch objects
     self.main_color = random_color()
     self.main_dir = rand_dir()
     self.speed = 0.1
Beispiel #6
0
 def __init__(self, hexmodel):
     self.name = "rain drops"
     self.hexes = hexmodel
     self.drops = []  # List that holds Drop objects
     self.speed = 0.1
     self.main_color = random_color()
     self.main_bands = randint(2, 10)  # Change in color between rings
Beispiel #7
0
    def next_frame(self):

        while (True):

            before_cells = [
                k for k, v in self.cellmap.iteritems() if v == True
            ]

            self.check_life()

            after_cells = [k for k, v in self.cellmap.iteritems() if v == True]

            if self.counter % 400 == 0 or \
              (len(before_cells) == len(after_cells) and len(before_cells) < 10 * self.square.squares): # Have cells changed?
                self.square.clear()
                self.color = random_color()
                for i in range(randint(self.min_start, self.max_start)):
                    self.light_square(choice(self.cellmap.keys()))
                yield self.speed

            self.counter += 1
            self.color = change_color(self.color, 0.02)

            if one_in(200):
                self.speed = up_or_down(self.speed, 0.1, 0.2, 2.0)

            yield self.speed
Beispiel #8
0
 def __init__(self, hexmodel):
     self.name = "Sparkles"
     self.hexes = hexmodel
     self.sparkles = []  # List that holds Sparkle objects
     self.speed = 1.0 / randint(5, 50)
     self.color = random_color()
     self.spark_num = 30 * helpfunc.NUM_HEXES
Beispiel #9
0
 def __init__(self, squaremodel):
     self.name = "Sparkles"
     self.square = squaremodel
     self.sparkles = Faders(squaremodel)
     self.speed = 0.3
     self.color = random_color()
     self.spark_num = self.square.squares * 20
Beispiel #10
0
 def __init__(self, hexmodel):
     self.name = "Ripples"
     self.hexes = hexmodel
     self.centers = [self.hexes.rand_cell(h) for h in helpfunc.all_hexes()]
     self.time = 0
     self.speed = 0.1 + (random() / 2)
     self.width = [randint(8, 20) for _ in range(helpfunc.NUM_HEXES)]
     self.color = [random_color() for _ in range(helpfunc.NUM_HEXES)]
Beispiel #11
0
 def __init__(self, hexmodel):
     self.name = "MultipleRipples"
     self.hexes = hexmodel
     self.ripples = []  # List that holds Ripple objects
     self.time = 0
     self.speed = 0.1 + (random() / 2)
     self.width = randint(8, 20)
     self.color = random_color()
Beispiel #12
0
 def __init__(self, hexmodel):
     self.name = "Center Branches"
     self.hexes = hexmodel
     self.live_branches = []  # List that holds Branch objects
     self.main_color = random_color()
     self.main_dir = rand_dir()
     self.inversion = randint(0, 1)  # Toggle for effects
     self.speed = 0.05
Beispiel #13
0
 def __init__(self, hexmodel):
     self.name = "Snakes"
     self.hexes = hexmodel
     self.snakemap = create_snake_model(hexmodel)
     self.next_snake_id = 0
     self.live_snakes = {
     }  # Dictionary that holds Snake objects. Key is snakeID.
     self.speed = 0.1
     self.main_color = random_color()
Beispiel #14
0
 def __init__(self, hexmodel, h):
     self.hexes = hexmodel
     self.h = h
     self.pos = (h, randint(-2, 2), randint(-2, 2))
     self.color = random_color()
     self.direction = rand_dir()
     self.turny = 3
     self.speedy = 15
     self.shooty = 3
Beispiel #15
0
 def __init__(self, squaremodel):
     self.name = "Center Branches"
     self.square = squaremodel
     self.livebranches = []  # List that holds Branch objects
     self.speed = 0.03
     self.maincolor = random_color()
     self.inversion = randint(0, 1)  # Toggle for effects
     self.fork = randint(5, 30)
     self.decay = randint(4, 20)
Beispiel #16
0
    def __init__(self, hexmodel):
        self.name = "Game of Life"
        self.hexes = hexmodel  # Actual visualized hexes
        self.life_hexes = self.create_life_model(size=8)  # Virtual life hexes
        self.speed = 0.2 + (random() * 2)
        self.on_color = random_color()

        # Most of the time set the background to black
        # Some of the time choose a colored background
        self.off_color = black()
Beispiel #17
0
 def __init__(self, hexmodel):
     self.hexes = hexmodel
     self.h = get_random_hex()
     self.color = random_color()
     self.pos = choice(hex_ring(center=(self.h, 0, 0), size=HEX_SIZE))
     self.direction = get_close_dir(
         self.pos, (self.h, 0, 0))  # Aim Asteroid towards the middle
     self.speed = randint(1, 5) / 5.0
     self.curr_pos = 0.0
     self.size = randint(2, 3)
Beispiel #18
0
 def __init__(self, hexmodel, h):
     self.name = "Well"
     self.hexes = hexmodel
     self.h = h
     self.pos = self.hexes.rand_cell(hex_number=h)
     self.direction = helpfunc.rand_dir()
     self.time = 0
     self.width = randint(8, 20)
     self.color = random_color()
     self.a = 1  # -1 < a < 1 : sign and intensity of well
     self.c = randint(2, 8)  # Width of well
Beispiel #19
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
    def create_tree2(self, start_pos, heading, length, current_line_list=None,
                     angle_change=45, len_dec=50, width=1, level=0, health_split=140, health=100, health_limit=3,
                     main_branch=True, first=False):
        if current_line_list is None:
            current_line_list = []
        if health > health_limit:
            if first and self.trunk_size is not None:
                temp_len = self.trunk_size
            else:
                temp_len = length
            p = start_pos.get_point_on_line(heading, temp_len * health/100)
            current_line_list.append(Branch((p.x, p.y), (start_pos.x, start_pos.y), width=width, level=level,
                                            health=health/100))

            level += 1

            if level > self.max_level:
                self.max_level = level

            h_left = random_if_range(health_split)  # how much health is passed onto next branches
            h1 = random.randrange(h_left - 100, 100)
            h2 = h_left - h1

            if main_branch:
                m1 = h1 > h2
                m2 = not m1
            else:
                m1, m2 = False, False

            if main_branch:
                if heading < 270 and h1 > h2:
                    h1, h2 = h2, h1
                elif heading > 270 and h2 > h1:
                    h1, h2 = h2, h1

            # create left branch
            current_line_list = self.create_tree2(p, heading - random_if_range(angle_change),
                                                  length,
                                                  current_line_list, angle_change, len_dec,
                                                  width, level, health_split,
                                                  health * h1/100, health_limit, m1)
            # create right branch
            current_line_list = self.create_tree2(p, heading + random_if_range(angle_change),
                                                  length,
                                                  current_line_list, angle_change, len_dec,
                                                  width, level, health_split,
                                                  health * h2/100, health_limit, m2)

        else:  # when branch ends(minimum size reached) add leaf
            if random.randrange(1) == 0:  # 1 in 4 chance of having a leaf on the end of a branch
                self.leaves.append(Leaf(start_pos.get(True), c.random_color(self.lCRange[0], self.lCRange[1],
                                                                            self.lColor, random.randrange(50, 100)),
                                        random.randrange(4)))
        return current_line_list
Beispiel #21
0
 def __init__(self, hexmodel):
     self.name = "Pin Cushion"
     self.hexes = hexmodel
     self.pos = []  # List of pin centers
     self.space = 0
     self.time = 0
     self.speed = 0.1
     self.width = randint(8, 20)
     self.color = random_color()
     self.a = 1  # -1 < a < 1 : sign and intensity of well
     self.c = 5  # Width of well
     self.min_bright = 0.1
Beispiel #22
0
    def __init__(self, squaremodel):
        self.name = "GameOfLife"
        self.square = squaremodel
        self.speed = randint(2, 20) / 10.0
        self.counter = 0
        self.color = random_color()
        self.cellmap = {}
        self.min_start = self.square.squares * 20
        self.max_start = self.square.squares * 100

        # Populate the cellmap with all the coordinates and blank it (set everything to False)
        for x in range(self.square.width):
            for y in range(self.square.height):
                self.cellmap[(x, y)] = False
Beispiel #23
0
 def __init__(self, hexmodel):
     self.name = "Pinwheels"
     self.hexes = hexmodel
     self.live_pinwheels = []  # List that holds Pinwheel objects
     self.speed = 1.0 / randint(2, 20)
     self.maincolor = random_color()
Beispiel #24
0
async def counter(websocket, path):
    await register(websocket)
    try:
        async for message in websocket:
            data = json.loads(message)
            if data["action"] == "message":
                if data["data"].find('/nick ', 0,
                                     (-1) * (len(data["data"]) - 6)) != -1:
                    newnick = data["data"][6:]
                    if newnick in USERS.values():
                        await asyncio.wait([
                            websocket.send(
                                json.dumps({
                                    "type":
                                    "system",
                                    "text":
                                    "Nickname is already occupied"
                                }))
                        ])
                    elif len(newnick) > 32:
                        await asyncio.wait([
                            websocket.send(
                                json.dumps({
                                    "type":
                                    "system",
                                    "text":
                                    "Nicname is more than 32 characters"
                                }))
                        ])
                    else:
                        if USERS[websocket][0] != "":
                            old = USERS[websocket][0]
                            USERS[websocket][0] = newnick
                            await notify_system(old +
                                                " nickname is changed to " +
                                                USERS[websocket][0])
                        else:
                            USERS[websocket][0] = newnick
                            USERS[websocket][1] = color.random_color()
                            await notify_system(newnick + " is connected")
                elif data["data"].find('/color ', 0,
                                       (-1) * (len(data["data"]) - 7)) != -1:
                    coloruser = data["data"][7:]
                    if color.check_color(coloruser):
                        await notify_color(USERS[websocket], coloruser)
                        USERS[websocket][1] = coloruser
                    else:
                        await asyncio.wait([
                            websocket.send(
                                json.dumps({
                                    "type":
                                    "system",
                                    "text":
                                    "Your color is invalid, formate is /color FFFFFF"
                                }))
                        ])
                else:
                    if (USERS[websocket][0] == ''):
                        await asyncio.wait([
                            websocket.send(
                                json.dumps({
                                    "type": "system",
                                    "text": "Your nickname is empty"
                                }))
                        ])
                    else:
                        await notify_message(data["data"], USERS[websocket])

            else:
                logging.error("unsupported event: {}".format(data))
    finally:
        await unregister(websocket)
Beispiel #25
0
 def __init__(self, hexmodel):
     self.name = "Rings"
     self.hexes = hexmodel
     self.rings = []  # List that holds Rings objects
     self.speed = 0.1
     self.main_color = random_color()
Beispiel #26
0
 def __init__(self, hexmodel):
     self.name = "AllOn"
     self.hexes = hexmodel
     self.color = random_color()
     self.speed = 0.2
Beispiel #27
0
 def __init__(self, hexmodel):
     self.name = "Swirls"
     self.hexes = hexmodel
     self.live_swirls = []  # List that holds Swirl objects
     self.speed = 1.0 / randint(3, 15)
     self.main_color = random_color()
Beispiel #28
0
 def __init__(self, hexmodel, h):
     super(House, self).__init__(hexmodel, h)
     self.y_coord = randint(0, 6)
     self.roof = random_color()
     self.wall = random_color()
Beispiel #29
0
 def __init__(self, hexmodel):
     self.name = "Balls"
     self.hexes = hexmodel
     self.balls = []	 # List that holds Balls objects
     self.speed = 1.0 / randint(4, 10)
     self.maincolor = random_color()  # Main color of the show