<s> """<STR_LIT>""" <EOL> __version__ = "<STR_LIT>" <EOL> from noise import pnoise3 <EOL> import ctypes <EOL> from pyglet . gl import * <EOL> class ShaderNoiseTexture : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , freq = <NUM_LIT:8> , width = <NUM_LIT:32> ) : <EOL> """<STR_LIT>""" <EOL> self . freq = freq <EOL> self . width = width <EOL> scale = float ( freq ) / width <EOL> width2 = width ** <NUM_LIT:2> <EOL> texel = ( ctypes . c_ushort * ( <NUM_LIT:2> * width ** <NUM_LIT:3> ) ) ( ) <EOL> for z in range ( width ) : <EOL> for y in range ( width ) : <EOL> for x in range ( width ) : <EOL> texel [ ( x + ( y * width ) + ( z * width2 ) ) * <NUM_LIT:2> ] = int ( ( pnoise3 ( <EOL> x * scale , y * scale , z * scale , <EOL> repeatx = freq , repeaty = freq , repeatz = freq ) + <NUM_LIT:1.0> ) * <NUM_LIT> ) <EOL> texel [ ( x + ( y * width ) + ( z * width2 ) ) * <NUM_LIT:2> + <NUM_LIT:1> ] = int ( ( pnoise3 ( <EOL> x * scale , y * scale , z * scale , <EOL> repeatx = freq , repeaty = freq , repeatz = freq , base = freq + <NUM_LIT:1> ) + <NUM_LIT:1.0> ) * <NUM_LIT> ) <EOL> self . data = texel <EOL> def load ( self ) : <EOL> """<STR_LIT>""" <EOL> glTexImage3D ( GL_TEXTURE_3D , <NUM_LIT:0> , GL_LUMINANCE16_ALPHA16 , <EOL> self . width , self . width , self . width , <NUM_LIT:0> , GL_LUMINANCE_ALPHA , <EOL> GL_UNSIGNED_SHORT , ctypes . byref ( self . data ) ) <EOL> def enable ( self ) : <EOL> """<STR_LIT>""" <EOL> glEnable ( GL_TEXTURE_3D ) <EOL> glTexParameteri ( GL_TEXTURE_3D , GL_TEXTURE_WRAP_S , GL_REPEAT ) <EOL> glTexParameteri ( GL_TEXTURE_3D , GL_TEXTURE_WRAP_T , GL_REPEAT ) <EOL> glTexParameteri ( GL_TEXTURE_3D , GL_TEXTURE_WRAP_R , GL_REPEAT ) <EOL> glTexParameteri ( GL_TEXTURE_3D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ) <EOL> glTexParameteri ( GL_TEXTURE_3D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) <EOL> shader_noise_glsl = '''<STR_LIT>''' <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import shader <EOL> win = pyglet . window . Window ( width = <NUM_LIT> , height = <NUM_LIT> , resizable = True , visible = False ) <EOL> vert_shader = shader . VertexShader ( '<STR_LIT>' , '''<STR_LIT>''' ) <EOL> frag_shader = shader . FragmentShader ( '<STR_LIT>' , shader_noise_glsl + '''<STR_LIT>''' ) <EOL> shader_prog = shader . ShaderProgram ( vert_shader , frag_shader ) <EOL> shader_prog . install ( ) <EOL> tex = ShaderNoiseTexture ( ) <EOL> tex . load ( ) <EOL> tex . enable ( ) <EOL> shader_prog . uset1I ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> quadratic = gluNewQuadric ( ) <EOL> gluQuadricNormals ( quadratic , GLU_SMOOTH ) <EOL> gluQuadricTexture ( quadratic , GL_TRUE ) <EOL> glEnable ( GL_CULL_FACE ) <EOL> global spin <EOL> spin = <NUM_LIT:0> <EOL> def on_resize ( width , height ) : <EOL> glViewport ( <NUM_LIT:0> , <NUM_LIT:0> , width , height ) <EOL> glMatrixMode ( GL_PROJECTION ) <EOL> glLoadIdentity ( ) <EOL> gluPerspective ( <NUM_LIT> , <NUM_LIT:1.0> * width / height , <NUM_LIT:0.1> , <NUM_LIT> ) <EOL> glMatrixMode ( GL_MODELVIEW ) <EOL> glLoadIdentity ( ) <EOL> win . on_resize = on_resize <EOL> @ win . event <EOL> def on_draw ( ) : <EOL> global spin <EOL> win . clear ( ) <EOL> glLoadIdentity ( ) <EOL> glTranslatef ( <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT> ) <EOL> glRotatef ( spin , <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:1.0> ) <EOL> gluSphere ( quadratic , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> def update ( dt ) : <EOL> global spin <EOL> spin += dt * <NUM_LIT> <EOL> pyglet . clock . schedule_interval ( update , <NUM_LIT:1.0> / <NUM_LIT> ) <EOL> win . set_visible ( ) <EOL> pyglet . app . run ( ) </s>
