Exemple #1
0
class ModelSwitcherOnPress:
    def __init__(self, renderer, models):
        self.renderer = renderer
        self.models = models
        self.index = 0

    def __call__(self, state):
        if state == plum.keystate.RELEASED:
            self.index += 1
            if self.index >= len(self.models):
                self.index = 0
            self.renderer.model = self.models[self.index]
            self.renderer()

plum.init()
w = plum.init_screen(800, 600, "Press space or drag mouse", "")
err = plum.sdl_error()
if err != "":
    print("SDL error: " + err)
gl = plum.GL(800, 600)
cube, rect, ico = Cube(), Rectangle(), Icosahedron()
render = Renderer(cube, gl, translate=Vector(-0.5, -0.5, -2.6))
w.key.add_handler(plum.keycode['space'], ModelSwitcherOnPress(render, (cube, rect, ico)))
w.mouse.add_draghandler(1, Dragger(render))
w.mouse.add_draghandler(3, Rotater(render))
render()

w.main_loop()

plum.quit()
Exemple #2
0
import plum
import geometry
import time

class Dragger:
    def start(self, x, y):
        print("Starting drag at {0}, {1}".format(x, y))
    def drag(self, x, y, xrel, yrel):
        print("Now at ({0}, {1}), vector ({2}, {3})".format(x, y, xrel, yrel))
    def stop(self, x, y):
        print("Stopping drag at {0}, {1}".format(x, y))

plum.init()
w = plum.init_screen(800, 600, "Press A", "")

w.key.add_handler(plum.keycode['a'], lambda state: print("Pressed A") if state == plum.keystate.PRESSED else print("Released A"))
w.mouse.add_clickhandler(1, lambda x, y: print("LMB clicked at {0}, {1}.".format(x, y)))
w.mouse.add_draghandler(1, Dragger())

w.main_loop()

plum.quit()