def __init__(self, win, seeds): self.paused = False self.multi_logoview = True self.win = win self.single_logoview = None width = win.width / 3 height = win.height / 3 self.logoviews = [LogoView((0, int(win.height/1.5)), (width, height), Logo([textgen.TextGen()])), LogoView((width, int(win.height/1.5)), (width, height), Logo([lsysgen.LSysGen(), polygen.PolyGen(), polygen.PolyGen(), polygen.PolyGen()])), LogoView((int(win.width/1.5), int(win.height/1.5)), (width, height), Logo([polygen.PolyGen(), polygen.PolyGen(), lsysgen.LSysGen()])), LogoView((0, height), (width, height), Logo([polygen.PolyGen()])), LogoView((width, height), (width, height), Logo([lsysgen.LSysGen(), lsysgen.LSysGen()])), LogoView((int(win.width/1.5), height), (width, height), Logo([polygen.PolyGen()])), LogoView((0, 0), (width, height), Logo([lsysgen.LSysGen()])), LogoView((width, 0), (width, height), Logo([polygen.PolyGen()])), LogoView((int(win.width/1.5), 0), (width, height), Logo()) ] if seeds == None: self.create_seeds_for_all_generators(0) # Mix the second and third logo to form a new one, and place it # in the lower right position. logo = Logo.mix_of(self.logoviews[1].logo, self.logoviews[2].logo) mixed_view = LogoView((int(win.width/1.5), 0), (width, height), logo) self.logoviews[8] = mixed_view else: newgens = [] for seed in seeds: (module, generator) = seed.get('__generator__', ('polygen', 'PolyGen')) genclass = reduce(getattr, [generator], sys.modules[module]) gen = genclass() gen.seed = seed newgens.append(gen) for view in self.logoviews: view.logo = Logo(newgens) print(self.logoviews) pyglet.clock.schedule_interval(self.create_seeds_for_all_generators, 10)
def test_multiple_generator_logos_mixed_should_adhere_to_rules(self): l1 = Logo([lsysgen.LSysGen(), polygen.PolyGen(), polygen.PolyGen(), polygen.PolyGen()]) l2 = Logo([polygen.PolyGen(), polygen.PolyGen(), lsysgen.LSysGen()]) l3 = Logo.mix_of(l1, l2) assert_that(len(l3), is_(4))
def test_mix_of_two_logos_with_one_different_gen_each_should_contain_two_unchanged_gens(self): poly_gen = polygen.PolyGen() text_gen = textgen.TextGen() l1 = self.create_logo([ poly_gen ]) l2 = self.create_logo([ text_gen ]) l3 = Logo.mix_of(l1, l2) assert_that(len(l3), is_(2)) assert_that(l3, contains_inanyorder(poly_gen, text_gen))
def test_mix_of_two_logos_with_one_polygen_each_should_contain_one_new_polygen(self): l1 = self.create_logo([ polygen.PolyGen() ]) l2 = self.create_logo([ polygen.PolyGen() ]) mixed = Logo.mix_of(l1, l2) assert_that("Mixed logo does not have one generator", len(mixed), is_(1)) assert_that("Mixed logo's first generator is not a PolyGen", mixed[0], is_(instance_of(polygen.PolyGen))) assert_that("Mixed logo's first generator is one of the original PolyGens", mixed[0], is_not(is_in([l1, l2])))
def test_mix_two_textgens_and_one_polygen_should_get_one_mixed_textgen_and_one_unchanged_polygen(self): poly_gen = polygen.PolyGen() text_gen1 = textgen.TextGen() text_gen2 = textgen.TextGen() l1 = self.create_logo([ poly_gen, text_gen1 ]) l2 = self.create_logo([ text_gen2 ]) mixed = Logo.mix_of(l1, l2) # Many asserts, but we want to be strict here # The mixed Logo shall: # * Only have two elements. # * Contain the original poly_gen. # * Not contain any of the original text_gens # * Contain one TextGen assert_that("Mixed Logo does not have two generators", len(mixed), is_(2)) assert_that("Mixed Logo does not contain the original PolyGen", mixed, has_item(poly_gen)) assert_that("Mixed Logo contains the original TextGens", mixed, is_not(has_items([text_gen1, text_gen2]))) assert_that("Mixed Logo does not contain a TextGen", mixed, has_item(instance_of(textgen.TextGen)))