<commit_before># #!/usr/bin/env python
# -*- coding: utf-8 -*-
# This code of this example should be considered public domain.

"""
Just a very fake galaxy.
Astronomers and cosmologists will kill me !
"""

import os
from vispy import oogl
from vispy import app
from vispy import gl
from OpenGL import GL
import numpy as np
from transforms import perspective, translate, rotate

#app.use('glut')
app.use('qt')

def make_arm(n,angle):
    R = np.linspace(10,500,n)          + 50*np.random.normal(0,2,n) * np.linspace(1,.1,n)
    T = angle+np.linspace(0,2*np.pi,n) + np.pi/6*np.random.normal(0,.5,n)
    S = 5+3*np.abs(np.random.normal(0,1,n))
    S *= np.linspace(.5,1.,n)
    X = R*np.cos(T)
    Y = R*np.sin(T)
    D = np.sqrt(X*X+Y*Y)
    Z = 8*np.random.normal(0, 2-D/512., n)
    D = np.maximum(0,D+25*np.random.normal(0,1,n))

    return X/256,Y/256,Z/256,S/2,D

p = 250000
n = 3*p
a_position = np.zeros((n,3),np.float32)
a_size     = np.random.uniform(.5,1,(n,1)).astype(np.float32)
a_dist     = np.ones((n,1))

for i in range(3):
    X,Y,Z,S,D = make_arm(p, i * 2*np.pi/3)
    a_dist[(i+0)*p:(i+1)*p,0] = D 
    a_position[(i+0)*p:(i+1)*p,0] = X
    a_position[(i+0)*p:(i+1)*p,1] = Y
    a_position[(i+0)*p:(i+1)*p,2] = Z
    a_size[(i+0)*p:(i+1)*p,0] = S


# Define marker array
spectrum = 'spectrum.png'
THISDIR = os.path.dirname(os.path.abspath(__file__))
spectrum_filename = os.path.join(THISDIR, 'data', spectrum)

VERT_SHADER = """
#version 120

// Uniforms
// ------------------------------------
uniform mat4      u_model;
uniform mat4      u_view;
uniform mat4      u_projection;
uniform sampler2D u_texture;


// Attributes
// ------------------------------------
attribute vec3  a_position;
attribute float a_size;
attribute float a_dist;

// Varyings
// ------------------------------------
varying float v_size;
varying float v_dist;

void main (void) {
    v_size  = a_size;
    v_dist  = a_dist/512.0;
    v_dist  = .15+.4*v_dist;
    gl_Position = u_projection * u_view * u_model * vec4(a_position,1.0);
    gl_PointSize = v_size;
}
"""

FRAG_SHADER = """
#version 120

// Uniforms
// ------------------------------------
uniform sampler2D u_texture;

// Varyings
// ------------------------------------
varying float v_size;
varying float v_dist;

// Main
// ------------------------------------
void main()
{    
    float a = 2*(length(gl_PointCoord.xy - vec2(0.5,0.5)) / sqrt(2));
    vec3 color = texture2D(u_texture, vec2(v_dist,.5)).rgb;
    gl_FragColor = vec4(color, (1-a)/v_size);
}
"""



class Canvas(app.Canvas):
    def __init__(self):
        app.Canvas.__init__(self)
        self.geometry = (0,0,1024,1024)
        self.title = "A very fake galaxy"

        self.program = oogl.ShaderProgram( oogl.VertexShader(VERT_SHADER), 
                                           oogl.FragmentShader(FRAG_SHADER) )<commit_msg>Fix for fake-galaxy. sqrt() does not work on ints.<commit_after># #!/usr/bin/env python
# -*- coding: utf-8 -*-
# This code of this example should be considered public domain.

"""
Just a very fake galaxy.
Astronomers and cosmologists will kill me !
"""

import os
from vispy import oogl
from vispy import app
from vispy import gl
from OpenGL import GL
import numpy as np
from transforms import perspective, translate, rotate

#app.use('glut')
app.use('qt')

def make_arm(n,angle):
    R = np.linspace(10,500,n)          + 50*np.random.normal(0,2,n) * np.linspace(1,.1,n)
    T = angle+np.linspace(0,2*np.pi,n) + np.pi/6*np.random.normal(0,.5,n)
    S = 5+3*np.abs(np.random.normal(0,1,n))
    S *= np.linspace(.5,1.,n)
    X = R*np.cos(T)
    Y = R*np.sin(T)
    D = np.sqrt(X*X+Y*Y)
    Z = 8*np.random.normal(0, 2-D/512., n)
    D = np.maximum(0,D+25*np.random.normal(0,1,n))

    return X/256,Y/256,Z/256,S/2,D

p = 250000
n = 3*p
a_position = np.zeros((n,3),np.float32)
a_size     = np.random.uniform(.5,1,(n,1)).astype(np.float32)
a_dist     = np.ones((n,1))

for i in range(3):
    X,Y,Z,S,D = make_arm(p, i * 2*np.pi/3)
    a_dist[(i+0)*p:(i+1)*p,0] = D 
    a_position[(i+0)*p:(i+1)*p,0] = X
    a_position[(i+0)*p:(i+1)*p,1] = Y
    a_position[(i+0)*p:(i+1)*p,2] = Z
    a_size[(i+0)*p:(i+1)*p,0] = S


# Define marker array
spectrum = 'spectrum.png'
THISDIR = os.path.dirname(os.path.abspath(__file__))
spectrum_filename = os.path.join(THISDIR, 'data', spectrum)

VERT_SHADER = """
#version 120

// Uniforms
// ------------------------------------
uniform mat4      u_model;
uniform mat4      u_view;
uniform mat4      u_projection;
uniform sampler2D u_texture;


// Attributes
// ------------------------------------
attribute vec3  a_position;
attribute float a_size;
attribute float a_dist;

// Varyings
// ------------------------------------
varying float v_size;
varying float v_dist;

void main (void) {
    v_size  = a_size;
    v_dist  = a_dist/512.0;
    v_dist  = .15+.4*v_dist;
    gl_Position = u_projection * u_view * u_model * vec4(a_position,1.0);
    gl_PointSize = v_size;
}
"""

FRAG_SHADER = """
#version 120

// Uniforms
// ------------------------------------
uniform sampler2D u_texture;

// Varyings
// ------------------------------------
varying float v_size;
varying float v_dist;

// Main
// ------------------------------------
void main()
{    
    float a = 2*(length(gl_PointCoord.xy - vec2(0.5,0.5)) / sqrt(2.0));
    vec3 color = texture2D(u_texture, vec2(v_dist,.5)).rgb;
    gl_FragColor = vec4(color, (1-a)/v_size);
}
"""



class Canvas(app.Canvas):
    def __init__(self):
        app.Canvas.__init__(self)
        self.geometry = (0,0,1024,1024)
        self.title = "A very fake galaxy"

        self.program = oogl.ShaderProgram( oogl.VertexShader(VERT_SHADER), 
                                           oogl.FragmentShader(FRAG_SHADER) )
{'fraction_non_alphanumeric': 0.23142509135200975, 'fraction_numerical': 0.04297894553680181, 'mean_word_length': 2.316791690709752, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7284254', 'n_tokens_mistral': 2354, 'n_tokens_neox': 2214, 'n_words': 440}