예제 #1
0
    def _run(self):
        window = app.Window()

        @window.event
        def on_init():
            # FIXME: it doesn't work here, so it' has been duplicated in the main cycle
            gl.glEnable(gl.GL_DEPTH_TEST)

        @window.event
        def on_resize(width, height):
            ratio = width / float(height)
            self._scene.set_camera_projection(45.0, ratio, 2.0, 100.0)

        @window.event
        def on_draw(dt):
            window.clear()
            if dt == 0:
                return
            # ensure that depth test is enabled
            gl.glEnable(gl.GL_DEPTH_TEST)
            # rotate cube
            try:
                rotation_matrix = np.eye(4, dtype=np.float32)
                glm.rotate(
                    rotation_matrix,
                    angle=self.angle * self._RAD_TO_DEG_K,
                    x=self.x,
                    y=self.y,
                    z=self.z
                )
                self._rotation_matrix[...] = rotation_matrix
            except Exception as e:
                logger.error(e)
            # draw scene
            self._scene.draw()

        @window.event
        def on_close():
            print("Window has been closed", file=sys.stderr)
            sys.exit(1)

        backend = app.__backend__
        clock = app.__init__(backend=backend)
        clock.set_fps_limit(30)
        count = len(backend.windows())
        while count:
            count = backend.process(clock.tick())
            if not self._active:
                break
        with suppress(Exception):
            window.close()
예제 #2
0
 def run(self):
     app.use("qt5")
     self.window = app.Window(width=self.width, height=self.height)
     #self.window = app.Window()
     self.window.attach(self)
     #app.clock.set_fps_limit(20)
     clock = app.__init__(backend=app.__backend__)
     if False:
         with record(self.window, "cube.mp4", fps=20):
             app.run(framerate=20)
     else:
         while True:
             #dt = clock.tick()
             #self.program1['time'] = dt*5
             time.sleep(0.01)
             app.__backend__.process(0.05)
             if self.finish:
                 return
예제 #3
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) 2014, Nicolas P. Rougier
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------
""" This example shows how to run the event loop manually """

from glumpy import app

window = app.Window()

@window.event
def on_draw(dt):
    window.clear()

backend = app.__backend__
clock = app.__init__(backend=backend)
count = len(backend.windows())
while count:
    count = backend.process(clock.tick())
# -----------------------------------------------------------------------------
# Copyright (c) 2009-2016 Nicolas P. Rougier. All rights reserved.
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------
""" This example shows how to run the event loop manually """

from glumpy import app

window = app.Window()

@window.event
def on_draw(dt):
    window.clear()

backend = app.__backend__
clock = app.__init__(backend=backend)
count = len(backend.windows())
while count:
    count = backend.process(clock.tick())
예제 #5
0
def run_main(demo, Scene):
    args = usage()
    screen = app.Window(width=args.winsize[0], height=args.winsize[1])
    scene = Scene(args.winsize, screen)
    screen.attach(scene)

    backend = app.__backend__
    clock = app.__init__(backend=backend, framerate=args.fps)

    if args.wav:
        audio = Audio(args.wav, args.fps, play=not args.record)
    else:
        audio = NoAudio()
    demo.setAudio(audio)

    if args.midi:
        midi = Midi(args.midi)
    else:
        midi = NoMidi()
    demo.setMidi(midi, args.midi_skip)
    demo.set(screen, scene)

    import pygame
    pygame.init()
    scene.render(0)
    audio.play = False
    demo.silent = True
    for skip in range(args.skip):
        demo.update(skip)
    demo.silent = False
    audio.play = not args.record
    demo.update_sliders()

    scene.alive = True

    if args.paused:
        demo.paused = True
        args.paused = False

    frame = args.skip
    while scene.alive:
        start_time = time.monotonic()
        demo.update(frame)

        if not demo.paused:
            frame += 1
        if scene.render(frame):
            print("%04d: %.2f sec '%s'" %
                  (frame, time.monotonic() - start_time,
                   json.dumps(demo.get(), sort_keys=True)))

        if args.record:
            scene.capture(os.path.join(args.record, "%04d.png" % frame))

        backend.process(clock.tick())

    if args.record:
        import subprocess
        cmd = [
            "ffmpeg", "-y", "-framerate",
            str(args.fps), "-i",
            "%s/%%04d.png" % args.record, "-i", args.wav, "-c:a", "libvorbis",
            "-c:v", "copy",
            "%s/render.mp4" % (args.record)
        ]
        print("Running: %s" % " ".join(cmd))
        subprocess.Popen(cmd).wait()
예제 #6
0
def main(modulator):
    args = usage()
    scene = FragmentShader(args)
    backend = app.__backend__
    clock = app.__init__(backend=backend, framerate=args.fps)
    scene.alive = True
    frame = args.skip
    if args.wav:
        audio = Audio(args.wav, args.fps, play=not args.record)
    else:
        audio = NoAudio()
    if args.midi:
        midi = Midi(args.midi)
    else:
        midi = NoMidi()

    mod = modulator(scene.params)
    scene.controller.update_sliders()

    spectre = SpectroGram(audio.blocksize)

    audio.play = False
    for skip in range(args.skip):
        audio_buf = audio.get(frame)
        spectre.transform(audio_buf)
        mod(skip, spectre, midi.get(args.midi_skip + skip))
    audio.play = not args.record

    scene.alive = True

    if args.paused:
        scene.paused = True
        args.paused = False

    frame = args.skip
    while scene.alive:
        start_time = time.monotonic()
        if not scene.paused:
            audio_buf = audio.get(frame)
            if audio_buf is not None:
                spectre.transform(audio_buf)
            midi_events = midi.get(args.midi_skip + frame)
            if midi_events:
                print(midi_events)
            if mod(frame, spectre, midi.get(args.midi_skip + frame)):
                print("Setting alive to false")
                scene.alive = False
            frame += 1
            scene.controller.update_sliders()
        scene.controller.root.update()
        if scene.update(frame):
            scene.render(frame)

            if args.record:
                scene.capture(os.path.join(args.record, "%04d.png" % frame))

            print("%04d: %.2f sec '%s'" %
                  (frame, time.monotonic() - start_time,
                   json.dumps(scene.controller.get(), sort_keys=True)))
            scene.draw = False

        backend.process(clock.tick())

    if args.record:
        import subprocess
        cmd = [
            "ffmpeg", "-y", "-framerate",
            str(args.fps), "-i",
            "%s/%%04d.png" % args.record, "-i", args.wav, "-c:a", "libvorbis",
            "-c:v", "copy",
            "%s/render.mp4" % (args.record)
        ]
        print("Running: %s" % " ".join(cmd))
        subprocess.Popen(cmd).wait()
예제 #7
0
        }

import time
import json

if __name__ == "__main__":
    demo = Demo()
    args = usage()
    screen = app.Window(width=args.winsize[0], height=args.winsize[1])
    scene = Scene(args.winsize, screen)
    scene.params = params
    scene.paused = args.paused
    screen.attach(scene)

    backend = app.__backend__
    clock = app.__init__(backend=backend, framerate=args.fps)

    audio = Audio(args.wav, args.fps, play=not args.record and not args.wav)
    demo.setAudio(audio)

    if args.midi:
        midi = Midi(args.midi)
    else:
        midi = NoMidi()
    demo.setMidi(midi, args.midi_skip)
    demo.set(screen, scene)

    import pygame
    pygame.init()
    scene.render(0)
    audio.play = False