window.clear() galaxy.update(100000) # in years ! program['a_size'] = galaxy['size'] * max(window.width / 800.0, window.height / 800.0) program['a_position'] = galaxy['position'] / 13000.0 program.draw(gl.GL_POINTS) @window.event def on_resize(width, height): gl.glViewport(0, 0, width, height) projection = glm.perspective(45.0, width / float(height), 1.0, 1000.0) program['u_projection'] = projection galaxy = Galaxy(35000) galaxy.reset(13000, 4000, 0.0004, 0.90, 0.90, 0.5, 200, 300) t0, t1 = 1000.0, 10000.0 n = 256 dt = (t1 - t0) / n colors = np.zeros((n, 3), dtype=np.float32) for i in range(n): temperature = t0 + i * dt x, y, z = spectrum_to_xyz(bb_spectrum, temperature) r, g, b = xyz_to_rgb(SMPTEsystem, x, y, z) r = min((max(r, 0), 1)) g = min((max(g, 0), 1)) b = min((max(b, 0), 1)) colors[i] = norm_rgb(r, g, b) program = gloo.Program(vertex, fragment, count=len(galaxy))
FRAG_SHADER = """ #version 120 //star texture uniform sampler2D u_texture; //predicted color from black body varying vec3 v_color; void main() { //amount of intensity from the grayscale star float star_tex_intensity = texture2D(u_texture, gl_PointCoord).r; gl_FragColor = vec4(v_color * star_tex_intensity, 0.8); } """ galaxy = Galaxy(10000) galaxy.reset(13000, 4000, 0.0004, 0.90, 0.90, 0.5, 200, 300) # coldest and hottest temperatures of out galaxy t0, t1 = 200.0, 10000.0 # total number of discrete colors between t0 and t1 n = 1000 dt = (t1 - t0) / n # maps [0, n) -> colors # generate a linear interpolation of temperatures # then map the temperatures to colors using black body # color predictions colors = np.zeros(n, dtype=(np.float32, 3)) for i in range(n): temperature = t0 + i * dt x, y, z = galaxy_specrend.spectrum_to_xyz(galaxy_specrend.bb_spectrum,