Exemplo n.º 1
0
                        bg=(255, 255, 255))
        tree3d.off()
        self.add_screen('3d', tree3d)

        self.add_button('switch', 20, 20, 40, 40, 'Switch', self.switch)
        self.add_button('redraw', 260, 20, 40, 40, 'Redraw', self.redraw)
        self.get_button('redraw').off()

    def switch(self):
        """
        Switches between the 2d and 3d screens.
        """
        if not self.is3d:
            self.get_screen('2d').off()
            self.get_screen('3d').on()
        else:
            self.get_screen('3d').off()
            self.get_screen('2d').on()
        self.is3d = not self.is3d

    def redraw(self):
        """
        Redraws the 3d screen.
        """
        self.get_screen('3d').iter = 0
        self.render()


if __name__ == '__main__':
    pyg.run(Test3D, width=500, height=700, caption='Fractal Tree')
Exemplo n.º 2
0
#!/usr/bin/python3
import pyg


class main:
    def setup(self):
        pyg.setSize((128, 128))
        pyg.setTitle("Simple")

    def loop(self):
        pass


if __name__ == "__main__":
    m = main()
    pyg.run(m)
Exemplo n.º 3
0
            r = random.randrange(3)
            p = (p + tri[r]) / 2
            self.add_point(*p, color=colors[r])

        self.flush()

    def resize(self, width, height):
        self.refit(width, height - 200)


class SierpWindow(pyg.window.Window):
    def set_vars(self):
        self.valset.add_int_value('iter', 5000, limit='ul', low=1, high=100000)
        self.valset.add_float_value('zoomratio', .5, limit='ul', inclusive='')

        self.add_screen(
            'main',
            SierpScreen(0, 200, 500, 500, 2, 2, 4, 4, self.valset,
                        'zoomratio'))

        self.add_float_field('zoomfield', 100, 130, 120, 15, 'Zoom Ratio',
                             self.get_valobj('zoomratio'))
        self.add_int_field('iterfield', 100, 100, 120, 15, 'Iter',
                           self.get_valobj('iter'))

        self.add_button('resetb', 10, 10, 40, 40, 'Reset',
                        self.get_screen('main').reset_screen)


pyg.run(SierpWindow, width=500, height=700, caption='Sierpinski')
Exemplo n.º 4
0
        self.add_button('stop', 70, 100, 40, 25, 'Stop', self.stop)
        self.add_button('randomize', 120, 100, 60, 25, 'Randomize',
                        self.randomize)

        self.add_int_value('speed', 50, limit='l', low=1)
        self.add_int_field('speed', 20, 80, 140, 15, 'Speed (gen/s)',
                           self.get_valobj('speed'))

    def update_labels(self):
        self.labels['dtlabel'].set_text('%s gen/s' %
                                        str(round(self.get_val('dt'), 5)))
        self.labels['genlabel'].set_text('Generation %d' %
                                         self.screens['1'].gen)

    def start(self):
        if not self.running:
            clock.schedule_interval(self.tick, 1 / self.get_val('speed'))
            self.running = True

    def stop(self):
        if self.running:
            clock.unschedule(self.tick)
            self.running = False

    def randomize(self):
        if not self.running:
            self.screens['1'].randomize()


pyg.run(GOLWindow, 800, 600, 'Game of Life')
        self.current_part = -1
        self.current_transform = -1
        self.labelrows['transformparts'].render()

    def all_on(self):
        fields = ['p']
        for f in fields:
            self.fields[f].on()
        buttons = ['save_p', 'delete_transform', 'cancel_transform']
        for b in buttons:
            self.buttons[b].on()

    def all_off(self):
        fields = ['p']
        for f in fields:
            self.fields[f].off()
        buttons = ['save_p', 'delete_transform', 'cancel_transform']
        for b in buttons:
            self.buttons[b].off()

    def redraw(self):
        self.get_screen('main').rendered = False
        self.render()


if __name__ == '__main__':
    pyg.run(TransformationWindow,
            width=800,
            height=750,
            caption='Transformations')
Exemplo n.º 6
0
    def key_down(self, symbol, modifiers):
        super().key_down(symbol, modifiers)
        if symbol == pyglet.window.key.K:
            self.get_valobj('n').incr()
            self.render()
        elif symbol == pyglet.window.key.J:
            self.get_valobj('n').decr()
            self.render()

    def resize(self, width, height):
        self.refit(width, height - 200)


class ComplexWindow(pyg.window.Window):
    def set_vars(self):
        self.add_float_value('sz', .5)
        self.add_int_value('n', 0, limit='l', low=0)
        self.add_float_value('power', 2, limit='l', inclusive='', low=0)
        self.add_int_value('hqw', 100)
        self.add_complex_value('c', 0+0j)
        screen = ComplexScreen(0, 200, 500, 500, 0, 0, 5, 5, self.valset, self.get_valobj('sz'))
        self.add_screen('main', screen)
        self.add_int_field('n', 260, 115, 100, 15, 'N', self.valset.get_valobj('n'))
        self.add_float_field('power', 260, 135, 100, 15, 'Power', self.valset.get_valobj('power'))
        self.add_int_field('hqw', 260, 155, 100, 15, 'Quality', self.valset.get_valobj('hqw'))
        self.add_complex_field('c', 260, 95, 100, 15, 'C', self.valset.get_valobj('c'))
        self.add_button('resetb', 190, 120, 40, 40, 'Reset', self.screens['main'].reset_screen)

pyg.run(ComplexWindow, 500, 700, 'Complex Graph')
Exemplo n.º 7
0
            return
        self.screens['main'].set_mode(mode)
        self.render()

    def update_labels(self):
        main = self.get_screen('main')
        self.labels['leftlabel'].set_text('%.5f' % main.min_gx)
        self.labels['rightlabel'].set_text('%.5f' % main.max_gx)
        self.labels['rightlabel'].set_pos(self.width - 60, 180)
        self.labels['toplabel'].set_text('%.5f' % main.max_gy)
        self.labels['toplabel'].set_pos(10, self.height + 180)
        self.labels['bottomlabel'].set_text('%.5f' % main.min_gy)
        self.labels['calclabel'].set_text('  calc time: %.5f ms' %
                                          self.valset.get_val('calctime'))
        self.labels['calclabel'].set_pos(self.width - 160, 110)
        self.labels['flushlabel'].set_text(' flush time: %.5f ms' %
                                           self.valset.get_val('flushtime'))
        self.labels['flushlabel'].set_pos(self.width - 160, 90)

    def mouse_move(self, x, y, dx, dy):
        super().mouse_move(x, y, dx, dy)
        if self.screens['main'].mouse_c:
            self.fields['c'].update_label()
            self.screens['main'].render()

    def on_resize(self, width, height):
        super().on_resize(width, height)


pyg.run(JuliaWindow, 500, 700, 'Julia Graph', (0, 0, 0))
Exemplo n.º 8
0
        pyg.clear()
        bb = [[0, 0, 0]] * 5 * 5 * 5
        for z in range(5):
            for y in range(5):
                for x in range(5):
                    p = self.b[z * 25 + y * 5 + x]
                    px, py, pz = p[0], p[1], p[2]
                    xx, yy = self.rot(px, py, self.ra)  #z
                    xx, zz = self.rot(xx, pz, self.rb)  #y
                    zz = zz + 20
                    xx = int(xx * zz / 3) + 128
                    yy = int(yy * zz / 3) + 64

                    bb[z * 25 + y * 5 + x] = [xx, yy, zz]

        bb = sorted(bb, key=itemgetter(2))

        for i in range(125):
            p = bb[i]
            zv = p[2] / 15
            pyg.putImage(self.ball, (p[0], p[1]), scale=(zv, zv), center=True)

        self.ra = (self.ra + 4) % 360
        self.rb = (self.rb + 0.5) % 360

        pyg.putImage(self.msgImg, (128, 64), center=True)


main = main()
pyg.run(main)