Beispiel #1
0
class GalaxyCanvas(Canvas):
    def __init__(self):
        Canvas.__init__(self, size=[800, 800], close_keys='ESCAPE', show=True,
                        title='Galaxy')
        self.galaxy = Galaxy(35000)
        self.galaxy.reset(13000, 4000, 0.0004, 0.90, 0.90, 0.5, 200, 300)
        program = gloo.Program(vertex, fragment, count=len(self.galaxy))
        view = np.eye(4, dtype=np.float32)
        translate(view, 0, 0, -5)
        program['u_view'] = view
        program['u_model'] = np.eye(4, dtype=np.float32)
        program['u_projection'] = np.eye(4, dtype=np.float32)

        from PIL import Image
        from specrend import (SMPTEsystem, spectrum_to_xyz, norm_rgb,
                              xyz_to_rgb, bb_spectrum)
        image = Image.open("particle.bmp")
        program['u_texture'] = np.array(image)/255.0
        t0 = 1000.
        t1 = 10000.
        n = 256
        dt = (t1 - t0) / n
        colors = np.zeros((1, n, 3), dtype=np.float32)
        for i in range(n):
            cs = SMPTEsystem
            temperature = t0 + i*dt
            x, y, z = spectrum_to_xyz(bb_spectrum, temperature)
            r, g, b = xyz_to_rgb(cs, x, y, z)
            colors[0, i] = norm_rgb(r, g, b)
        program['u_colormap'] = gloo.Texture2D(colors)
        program['a_size'] = self.galaxy['size']
        program['a_type'] = self.galaxy['type']
        self.program = program

    def on_initialize(self):
        gloo.set_clear_color((0.0, 0.0, 0.0, 1.0))
        gloo.set_state(blend=True, depth_test=True,
                       blend_func=('src_alpha', 'one_minus_src_alpha'))

    def on_paint(self, region):
        self.galaxy.update(100000)  # in years !
        self.program['a_size'] = self.galaxy['size']
        gloo.clear()
        t0 = 1000.
        t1 = 10000.
        gloo.set_state(blend=True, blend_func=('src_alpha', 'one'))
        self.program['a_position'] = self.galaxy['position'] / 15000.0
        self.program['a_temperature'] = ((self.galaxy['temperature'] - t0)
                                         / (t1-t0))
        self.program['a_brightness'] = self.galaxy['brightness']
        self.program.draw('points')

    def on_resize(self, width, height):
        gloo.set_viewport(0, 0, width, height)
        projection = perspective(45.0, width / float(height), 1.0, 1000.0)
        self.program['u_projection'] = projection
Beispiel #2
0
    program['u_projection'] = projection


def keyboard(key, x, y):
    if key == '\033': sys.exit()


def timer(fps):
    galaxy.update(100000)  # in years !
    program['a_size'] = galaxy['size']
    glut.glutTimerFunc(1000 / fps, timer, fps)
    glut.glutPostRedisplay()


galaxy = Galaxy(35000)
galaxy.reset(13000, 4000, 0.0004, 0.90, 0.90, 0.5, 200, 300)

glut.glutInit(sys.argv)
glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
glut.glutCreateWindow('Galaxy')
glut.glutReshapeWindow(800, 800)
glut.glutReshapeFunc(reshape)
glut.glutKeyboardFunc(keyboard)
glut.glutDisplayFunc(display)
glut.glutTimerFunc(1000 / 60, timer, 60)

program = gloo.Program(vertex, fragment, count=len(galaxy))
view = np.eye(4, dtype=np.float32)
model = np.eye(4, dtype=np.float32)
projection = np.eye(4, dtype=np.float32)
translate(view, 0, 0, -5)
Beispiel #3
0
    gl.glViewport(0, 0, width, height)
    projection = perspective(45.0, width / float(height), 1.0, 1000.0)
    program['u_projection'] = projection

def keyboard(key, x, y):
    if key == '\033': sys.exit()

def timer(fps):
    galaxy.update(100000) # in years !
    program['a_size'] = galaxy['size']
    glut.glutTimerFunc(1000 / fps, timer, fps)
    glut.glutPostRedisplay()


galaxy = Galaxy(35000)
galaxy.reset(13000, 4000, 0.0004, 0.90, 0.90, 0.5, 200, 300)

glut.glutInit(sys.argv)
glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
glut.glutCreateWindow('Galaxy')
glut.glutReshapeWindow(800,800)
glut.glutReshapeFunc(reshape)
glut.glutKeyboardFunc(keyboard)
glut.glutDisplayFunc(display)
glut.glutTimerFunc(1000 / 60, timer, 60)

program = gloo.Program(vertex, fragment, count = len(galaxy))
view = np.eye(4, dtype=np.float32)
model = np.eye(4, dtype=np.float32)
projection = np.eye(4, dtype=np.float32)
translate(view, 0, 0, -5)