예제 #1
0
 def run(self, fnprovider: AbstractFilenameProvider):
     self.grid().save(fnprovider.get_filename('.png', 'grid', 'Grid'))
     self.circles().save(
         fnprovider.get_filename('.png', 'circles', 'Circles'))
     self.color_grid().save(
         fnprovider.get_filename('.png', 'color_grid', 'Color grid'))
     return fnprovider.format_files()
예제 #2
0
 def run(self, fnprovider: AbstractFilenameProvider):
     self.s1('../resources/w4/skryvacka1.png').save(
         fnprovider.get_filename('.png', 'skryvacka1', 'Skrývačka 1'))
     self.s2('../resources/w4/skryvacka2.png').save(
         fnprovider.get_filename('.png', 'skryvacka2', 'Skrývačka 2'))
     self.s3('../resources/w4/skryvacka3.png').save(
         fnprovider.get_filename('.png', 'skryvacka3', 'Skrývačka 3'))
     return fnprovider.format_files()
예제 #3
0
 def run(self, fnprovider: AbstractFilenameProvider):
     img = bifurcations((2, 4), 10000, (0, 1), 5000, .2)
     img.save(fnprovider.get_filename('.png', 'bif', 'Bifurcations'))
     img.thumbnail((500, 500), Image.ANTIALIAS)
     img.save(
         fnprovider.get_filename('.png', 'bif_small',
                                 'Bifurcations (small)'))
     return fnprovider.format_files()
예제 #4
0
 def run(self, fnprovider: AbstractFilenameProvider):
     """Sokoban. Prevzaté z https://www.umimematiku.cz"""
     animate_sokoban('../resources/w12/sokoban1.txt',
                     fnprovider.get_filename('.gif', 'simple', "Simple"))
     animate_sokoban('../resources/w12/sokoban2.txt',
                     fnprovider.get_filename('.gif', 'hard', 'Hard'))
     animate_sokoban('../resources/w12/sokoban3.txt',
                     fnprovider.get_filename('.gif', 'slides', 'Slides'))
     return fnprovider.format_files()
예제 #5
0
 def run(self, fnprovider: AbstractFilenameProvider):
     plt.clf()
     random.seed(433308)
     iters = 100000
     drawResults(20, iters).savefig(
         fnprovider.get_filename(".png", "test_20", "Test 20"))
     drawResults(50, iters).savefig(
         fnprovider.get_filename(".png", "test_50", "Test 50"))
     drawResults(100, iters).savefig(
         fnprovider.get_filename(".png", "test_100", "Test 100"))
     return fnprovider.format_files()
예제 #6
0
 def run(self, fnprovider: AbstractFilenameProvider):
     hidden = self.hide(Image.open('../resources/w4/fi.png'),
                        Image.open('../resources/w4/hidden.png'))
     hidden.save(
         fnprovider.get_filename('.png', 'with_message',
                                 "Image with a hidden message"))
     extracted = self.extract(hidden)
     extracted.save(
         fnprovider.get_filename('.png', 'extracted_message',
                                 "Extracted message"))
     return fnprovider.format_files()
예제 #7
0
파일: PartB.py 프로젝트: jksdf/IV122
    def run(self, fnprovider: AbstractFilenameProvider):
        random.seed(433308)

        colors = list(matplotlib.colors.TABLEAU_COLORS.values())
        animate(
            5, 3,
            sum([
                generate_circle_gauss(50, (200, 200), 20),
                generate_circle_gauss(80, (300, 200), 30),
                generate_circle_gauss(50, (380, 350), 50)
            ], []), colors,
            500).saveas(fnprovider.get_filename(".svg", "example1",
                                                "Distinct clusters"),
                        pretty=True)

        animate(
            5, 3,
            sum([
                generate_circle_gauss(100, (200, 200), 50),
                generate_circle_gauss(100, (300, 200), 50),
                generate_circle_gauss(50, (380, 350), 50)
            ], []), colors,
            500).saveas(fnprovider.get_filename(".svg", "example2",
                                                "2 merged clusters"),
                        pretty=True)

        animate(13,
                3,
                sum([
                    generate_circle_gauss(200, (200, 200), 50),
                    generate_circle_gauss(200, (250, 200), 50),
                    generate_circle_gauss(50, (380, 350), 50)
                ], []),
                colors,
                500,
                init_idxs=[0, 1, 2]).saveas(fnprovider.get_filename(
                    ".svg", "example3", "2 merged clusters (very close)"),
                                            pretty=True)

        animate(6,
                2,
                load_points('../resources/w11/faithful.txt'),
                colors,
                150,
                x_scale=10,
                scale=5,
                init_idxs=[54, 222]).saveas(fnprovider.get_filename(
                    ".svg", "faithful", "Faithful"),
                                            pretty=True)

        return fnprovider.format_files()
예제 #8
0
파일: PartA.py 프로젝트: jksdf/IV122
 def run(self, fnprovider: AbstractFilenameProvider):
     save_gif(
         chaos_game(3, 10000, 10, 1 / 2),
         fnprovider.get_filename('.gif', 'chaos_triangle',
                                 'Chaos triangle (n=3, r=1/2)'))
     save_gif(chaos_game(5, 10000, 50, 1 / 2),
              fnprovider.get_filename('.gif', 'chaos_pentagon',
                                      'Chaos pentagon (n=3, r=1/2)'),
              duration=100)
     save_gif(chaos_game(5, 10000, 50, 1 / 3),
              fnprovider.get_filename('.gif', 'chaos_pentagon_third',
                                      'Chaos pentagon (n=3, r=1/3)'),
              duration=100)
     return fnprovider.format_files()
예제 #9
0
파일: Solution.py 프로젝트: jksdf/IV122
    def run(self, fnprovider: AbstractFilenameProvider) -> str:
        fns = {}
        palette: List[Tuple[int, int, int]] = [tuple(map(int, mult_tuple(c, (255, 255, 255)))) for c in
                                               matplotlib.pyplot.get_cmap('Set3').colors]
        fn = fnprovider.get_filename(suffix='.png', name='pascal_50_5')
        fns['pascal_30_5'] = fn
        self.pascal_image(50, 5, palette[:5]).save(fn)
        fn = fnprovider.get_filename(suffix='.png', name='pascal_500_10')
        fns['pascal_500_10'] = fn
        self.pascal_image(500, 10, palette[:10]).save(fn)

        fn = fnprovider.get_filename(suffix='.png', name='pascal_500_5')
        fns['pascal_500_5'] = fn
        self.pascal_image(500, 5, palette[:5]).save(fn)

        return '\n'.join('{}: {}'.format(k, v) for k, v in fns.items())
예제 #10
0
파일: Solution.py 프로젝트: jksdf/IV122
 def run(self, fnprovider: AbstractFilenameProvider):
     fn = fnprovider.get_filename('.png', 'pow_efficiency')
     self.efficiency_graph(fn, 123, (10 ** i for i in range(100)), 1000000007, trials=1000)
     return '\n'.join([self.get(123, 1234567, 1000000007),
                       self.get(9, 10, 2),
                       self.get(123456, 12345678901234567890, 1000000007, perform_inefficient=False),
                       f'efficiency graph {fn}'])
예제 #11
0
파일: PartB.py 프로젝트: jksdf/IV122
    def run(self, fnprovider: AbstractFilenameProvider):
        draw_mrcm(5,
                  square(25), [
                      mult(translation(25, 0), scale(0.5, 0.5)),
                      mult(translation(0, 50), scale(0.5, 0.5)),
                      mult(translation(50, 50), scale(0.5, 0.5))
                  ],
                  viewbox=(-10, -10, 70, 70),
                  stroke=0.5).saveas(
                      fnprovider.get_filename('.svg', 'square_sierpinsky',
                                              'Square Sierpinsky'))

        draw_mrcm(5,
                  square(25), [
                      mult(scale(0.5, 0.5)),
                      mult(translation(0, 50), scale(0.5, 0.5)),
                      mult(translation(50, 50), scale(0.5, 0.5))
                  ],
                  viewbox=(-10, -10, 70, 70),
                  stroke=0.5).saveas(
                      fnprovider.get_filename('.svg',
                                              'square_tilted_sierpinsky',
                                              'Square tilted Sierpinsky'))

        draw_mrcm(7,
                  apply(translation(25, 25), square(25)), [
                      mult(translation(0, -50), scale(0.5, -0.5)),
                      mult(translation(50, 0), scale(0.5, 0.5)),
                      mult(translation(-50, 50), scale(-0.5, 0.5))
                  ],
                  viewbox=(-10, -10, 70, 70),
                  stroke=0.1).saveas(
                      fnprovider.get_filename('.svg', 'sierpinsky_var1',
                                              'Sierpinsky variant 1'))

        draw_mrcm(1,
                  apply(translation(25, 25), square_with_corner(25)), [
                      mult(translation(0, -50), scale(0.5, -0.5)),
                      mult(translation(50, 0), scale(0.5, 0.5)),
                      mult(translation(-50, 50), scale(-0.5, 0.5))
                  ],
                  viewbox=(-10, -10, 70, 70),
                  stroke=0.1).saveas(
                      fnprovider.get_filename('.svg', 'sierpinsky_var1_1step',
                                              'Sierpinsky variant 1 (1 step)'))

        return fnprovider.format_files()
예제 #12
0
    def run(self, fnprovider: AbstractFilenameProvider):
        fns = {}

        fn = fnprovider.get_filename('.png', 'polygon')
        self.polygon(200, [(10, 10), (180, 20), (160, 150), (100, 50),
                           (20, 180)]).save(fn)
        fns['Polygon'] = fn
        return '\n'.join(f'{k}: {v}' for k, v in fns.items())
예제 #13
0
    def run(self, fnprovider: AbstractFilenameProvider):
        plt.clf()
        visualize_from_file('../resources/w11/linreg.txt').save(
            fnprovider.get_filename('.gif', 'linreg', 'Linreg'),
            writer='imagemagick',
            fps=1)

        visualize_generated(lambda: random.uniform(-1, 1), random.random) \
            .save(fnprovider.get_filename('.gif', 'even_dist', 'Even distribution'), writer='imagemagick', fps=1)
        visualize_generated(lambda: random.gauss(0, 1), random.random) \
            .save(fnprovider.get_filename('.gif', 'gauss_dist', 'Gaussian distribution'), writer='imagemagick', fps=1)

        visualize_generated(lambda: random.gauss(0, 1), lambda: random.lognormvariate(0, 1)) \
            .save(fnprovider.get_filename('.gif', 'gauss_log-normal_dist',
                                          'Gaussian distribution with log-normal along the line'), writer='imagemagick',
                  fps=1)
        return fnprovider.format_files()
예제 #14
0
    def run(self, fnprovider: AbstractFilenameProvider):
        with open(fnprovider.get_filename(".svg", "small", "Small (5)"),
                  'w') as f:
            create_puzzle(5, 2).write(f, pretty=True)

        with open(fnprovider.get_filename(".svg", "medium", "Medium (10)"),
                  'w') as f:
            create_puzzle(10, 2).write(f, pretty=True)

        with open(fnprovider.get_filename(".svg", "large", "Large (20)"),
                  'w') as f:
            create_puzzle(20, 2).write(f, pretty=True)

        with open(
                fnprovider.get_filename(".svg", "large_dense",
                                        "Large dense (20)"), 'w') as f:
            create_puzzle(20, 4).write(f, pretty=True)
        return fnprovider.format_files()
예제 #15
0
파일: PartA.py 프로젝트: jksdf/IV122
    def run(self, fnprovider: AbstractFilenameProvider):
        res = 500
        mandelbrot(20, res, 'simple', 'mandelbrot').save(
            fnprovider.get_filename(".png", "mandelbrot", "Mandelbrot"))
        mandelbrot(15, res, 'simple+finaldist', 'mandelbrot').save(
            fnprovider.get_filename(".png", "mandelbrot_final_dist",
                                    "Mandelbrot with final distances"))
        mandelbrot(20, res, 'avgdist', 'mandelbrot').save(
            fnprovider.get_filename(".png", "mandelbrot_avgdist",
                                    "Mandelbrot with average distances"))

        julius_init = -0.13 + 0.75j
        mandelbrot(20, res, 'simple', 'julius', julius_init=julius_init).save(
            fnprovider.get_filename(".png", "julius", "Julius"))
        mandelbrot(15,
                   res,
                   'simple+finaldist',
                   'julius',
                   julius_init=julius_init).save(
                       fnprovider.get_filename(".png", "julius_final_dist",
                                               "Julius with final distances"))
        mandelbrot(20, res, 'avgdist', 'julius', julius_init=julius_init).save(
            fnprovider.get_filename(".png", "julius_avgdist",
                                    "Julius with average distances"))
        return fnprovider.format_files()
예제 #16
0
    def run(self, fnprovider: AbstractFilenameProvider):
        fns = {}

        fn = fnprovider.get_filename('.png', 'circle')
        self.circle(200, 80).save(fn)
        fns['Circle'] = fn

        fn = fnprovider.get_filename('.png', 'empty_circle')
        self.empty_circle(200, 80, 5).save(fn)
        fns['Empty circle'] = fn

        fn = fnprovider.get_filename('.png', 'gonio_circle')
        self.goniometric_circle(200, 80).save(fn)
        fns['Goniometric circle'] = fn

        fn = fnprovider.get_filename('.png', 'spiral')
        self.spiral(400, 160, 10).save(fn)
        fns['Spiral'] = fn

        fn = fnprovider.get_filename('.png', 'triangle')
        self.triangle(200).save(fn)
        fns['Triangle'] = fn

        fn = fnprovider.get_filename('.png', 'elipsis')
        self.elipsis(200, 80, 30).save(fn)
        fns['Elipsis'] = fn

        return '\n'.join(f'{k}: {v}' for k, v in fns.items())
예제 #17
0
 def run(self, fnprovider: AbstractFilenameProvider):
     random.seed(433308)
     lines = gen_line_segments(500, 30, (5, 405))
     d = svgwrite.Drawing(fnprovider.get_filename('.svg', 'test', 'Test'),
                          size=(410, 410))
     for start, end in lines:
         d.add(svgwrite.shapes.Line(start, end, stroke='black'))
     for intersection in intersections(lines):
         d.add(
             svgwrite.shapes.Circle(center=intersection, r=1,
                                    stroke='blue'))
     d.save()
     return fnprovider.format_files()
예제 #18
0
 def run(self, fnprovider: AbstractFilenameProvider):
     fn = fnprovider.get_filename(suffix='.svg', name="shapes")
     turtle = Turtle(fn, (50, 50))
     polygon(turtle, 5, 50)
     turtle.penup()
     turtle.forward(100)
     turtle.pendown()
     star(turtle, 5, 50)
     turtle.penup()
     turtle.forward(100)
     turtle.pendown()
     star(turtle, 7, 50)
     turtle.save(frame=(280, 100))
     return fn
예제 #19
0
파일: PartB.py 프로젝트: jksdf/IV122
 def run(self, fnprovider: AbstractFilenameProvider):
     fn = fnprovider.get_filename(suffix='.svg', name="polygon")
     turtle = Turtle(fn)
     self.pentagon(turtle)
     turtle.resetpos(position=(250, 0))
     self.squares(turtle)
     turtle.resetpos(position=(400, 0))
     self.grid(turtle)
     turtle.resetpos(position=(750, 0))
     self.triangles(turtle)
     turtle.resetpos(position=(900, 50))
     self.flower(turtle)
     turtle.save(frame=(1000, 200))
     return fn
예제 #20
0
파일: PartD.py 프로젝트: jksdf/IV122
 def run(self, fnprovider: AbstractFilenameProvider):
     iters = 100000
     for N in (5, 10, 20, 50, 100):
         plt.clf()
         x = np.array(list(range(2, 10)))
         y2 = [sample(N, X, iters) for X in x]
         y = [v[True] for v in y2]
         z = [v[False] for v in y2]
         plt.bar(x, y, width=0.2, color='red')
         plt.bar(x, z, bottom=y, width=0.2, color='blue')
         plt.legend(['fake', 'correct'])
         plt.xlabel(f'Number of throws')
         plt.ylabel(f'Probability of the kind of die')
         plt.title(f'{N} dice')
         plt.savefig(fnprovider.get_filename('.png', f'samples_N{N}', f'Samples with N = {N}'))
     return fnprovider.format_files()
예제 #21
0
 def run(self, fnprovider: AbstractFilenameProvider):
     plt.clf()
     fig, ax = plt.subplots()
     fig.suptitle("Monty hall distributions by strategy")
     ax.set_ylabel('Win rate')
     ax.set_xlabel('Strategy')
     ax.bar(list(range(3)), [
         play(lambda: True),
         play(lambda: False),
         play(lambda: random.choice([True, False]))
     ],
            tick_label=['Always swap', 'Never swap', 'Random'])
     fig.savefig(
         fnprovider.get_filename('.png', 'monty_hall_distribution',
                                 'Monty hall distributions by strategy'))
     return fnprovider.format_files()
예제 #22
0
 def run(self, fnprovider: AbstractFilenameProvider):
     fn = fnprovider.get_filename(".svg", "fractals")
     turtle = Turtle(fn, (50, 250))
     turtle.left(90)
     self.ker(turtle, 9, size=0.2)
     turtle.resetpos(position=(200, -150))
     turtle.right(60)
     self.sierpinsky(turtle, 5, 9)
     turtle.resetpos(position=(350, -120))
     self.koch(turtle, 5, 0.8)
     turtle.resetpos(position=(600, -150))
     self.hilbert(turtle, 4, 2)
     turtle.resetpos(position=(900, -200))
     self.pentagon(turtle, 3, 10)
     turtle.resetpos(position=(1200, -200))
     self.square_sierpinsky(turtle, 4, 3)
     turtle.save(frame=(1500, 500))
     return fn
예제 #23
0
    def run(self, fnprovider: AbstractFilenameProvider):
        weed(fnprovider.get_filename('.svg', 'weed_growth', 'Weed growth'))
        koch(fnprovider.get_filename('.svg', 'koch', 'Koch'))
        sierpinsky(fnprovider.get_filename('.svg', 'sierpinsky', "Sierpinsky"))
        sierpinsky(fnprovider.get_filename('.svg', 'sierpinsky_twisted',
                                           "Sierpinsky twisted"),
                   angle=56,
                   step=4)
        paprad(fnprovider.get_filename('.svg', 'paprad', 'Paprad'))
        pentaplexity(
            fnprovider.get_filename('.svg', 'pentaplexity', "Pentaplexity"))

        return fnprovider.format_files()
예제 #24
0
파일: Solution.py 프로젝트: jksdf/IV122
 def run(self, fnprovider: AbstractFilenameProvider):
     res = {'lei': {}, 'arch': {}, 'monte': {}}
     for time in range(3, 10):
         time = 10 ** time
         res['lei'][time] = sampling.sample(pi.leibniz_formula, time)
         res['arch'][time] = sampling.sample(pi.archimedes_sequence, time)
         res['monte'][time] = sampling.sample(pi.monte_carlo, time)
     labels = []
     for kind in res:
         keys, vals = zip(*res[kind].items())
         matplotlib.pyplot.loglog(keys, [abs(v - math.pi) / math.pi for v in vals])
         labels.append(kind)
     matplotlib.pyplot.legend(labels)
     matplotlib.pyplot.xlabel('Time')
     matplotlib.pyplot.ylabel('Runs')
     fn = fnprovider.get_filename(suffix='.png', name='pi_precision')
     matplotlib.pyplot.savefig(fn)
     matplotlib.pyplot.clf()
     return fn
예제 #25
0
 def run(self, fnprovider: AbstractFilenameProvider):
     files = [f'../resources/w9/random{f}.txt' for f in range(1, 8)]
     for i in range(1, 5):
         self.render(i, files).savefig(
             fnprovider.get_filename(".png", f"{i}-grams", f"{i}-grams"))
     return fnprovider.format_files()