<s> from __future__ import absolute_import , division , print_function , unicode_literals <EOL> """<STR_LIT>""" <EOL> import numpy as np <EOL> import math <EOL> import colorsys <EOL> def getattra ( obj , attr , default ) : <EOL> if ( "<STR_LIT:[>" in attr ) : <EOL> splits = attr . split ( "<STR_LIT:[>" ) <EOL> index = int ( splits [ <NUM_LIT:1> ] . replace ( "<STR_LIT:]>" , "<STR_LIT>" ) ) <EOL> thearray = getattr ( obj , splits [ <NUM_LIT:0> ] , None ) <EOL> if ( thearray is not None ) : <EOL> return thearray [ index ] <EOL> else : <EOL> return default <EOL> else : <EOL> return getattr ( obj , attr , default ) <EOL> class TextBlockColour ( object ) : <EOL> def __init__ ( self , colour = ( <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , textBlock = None ) : <EOL> self . colour = [ colour [ <NUM_LIT:0> ] , colour [ <NUM_LIT:1> ] , colour [ <NUM_LIT:2> ] , colour [ <NUM_LIT:3> ] ] <EOL> self . textBlock = textBlock <EOL> def recolour ( self ) : <EOL> self . set_colour ( ) <EOL> def set_colour ( self , colour = None , alpha = None ) : <EOL> if colour is not None : <EOL> self . colour [ <NUM_LIT:0> : <NUM_LIT:2> ] = colour [ <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> if alpha is not None : <EOL> self . colour [ <NUM_LIT:3> ] = alpha <EOL> textBlock = self . textBlock <EOL> manager = textBlock . _text_manager <EOL> st = textBlock . _buffer_index <EOL> mid = st + textBlock . _string_length <EOL> end = st + textBlock . char_count <EOL> manager . normals [ st : end , <NUM_LIT:2> ] = <NUM_LIT:0> <EOL> normal = np . zeros ( ( <NUM_LIT:3> ) , dtype = np . float ) <EOL> normal [ <NUM_LIT:0> ] = textBlock . rot + textBlock . char_rot <EOL> normal [ <NUM_LIT:1> ] = ( self . colour [ <NUM_LIT:1> ] * <NUM_LIT> ) + ( math . floor ( self . colour [ <NUM_LIT:0> ] * <NUM_LIT> ) ) <EOL> normal [ <NUM_LIT:2> ] = ( self . colour [ <NUM_LIT:3> ] * <NUM_LIT> ) + ( math . floor ( self . colour [ <NUM_LIT:2> ] * <NUM_LIT> ) ) <EOL> manager . normals [ st : mid , : ] = normal <EOL> class TextBlockColourGradient ( TextBlockColour ) : <EOL> def __init__ ( self , colour1 , colour2 , textBlock = None ) : <EOL> self . colour1 = colour1 <EOL> self . colour2 = colour2 <EOL> self . textBlock = textBlock <EOL> def set_colour ( self , colour1 = None , colour2 = None ) : <EOL> '''<STR_LIT>''' <EOL> if colour1 is not None : <EOL> self . colour1 = colour1 <EOL> if colour2 is not None : <EOL> self . colour2 = colour2 <EOL> if self . textBlock is None : <EOL> return <EOL> colour1 = self . colour1 <EOL> colour2 = self . colour2 <EOL> textBlock = self . textBlock <EOL> manager = textBlock . _text_manager <EOL> hsv1 = colorsys . rgb_to_hsv ( colour1 [ <NUM_LIT:0> ] , colour1 [ <NUM_LIT:1> ] , colour1 [ <NUM_LIT:2> ] ) <EOL> hsv2 = colorsys . rgb_to_hsv ( colour2 [ <NUM_LIT:0> ] , colour2 [ <NUM_LIT:1> ] , colour2 [ <NUM_LIT:2> ] ) <EOL> normal = np . zeros ( ( <NUM_LIT:3> ) , dtype = np . float ) <EOL> normal [ <NUM_LIT:0> ] = textBlock . rot + textBlock . char_rot <EOL> for index in range ( <NUM_LIT:0> , textBlock . _string_length ) : <EOL> h = np . interp ( index , [ <NUM_LIT:0> , textBlock . _string_length ] , [ hsv1 [ <NUM_LIT:0> ] , hsv2 [ <NUM_LIT:0> ] ] ) <EOL> s = np . interp ( index , [ <NUM_LIT:0> , textBlock . _string_length ] , [ hsv1 [ <NUM_LIT:1> ] , hsv2 [ <NUM_LIT:1> ] ] ) <EOL> v = np . interp ( index , [ <NUM_LIT:0> , textBlock . _string_length ] , [ hsv1 [ <NUM_LIT:2> ] , hsv2 [ <NUM_LIT:2> ] ] ) <EOL> a = np . interp ( index , [ <NUM_LIT:0> , textBlock . _string_length ] , [ colour1 [ <NUM_LIT:3> ] , colour2 [ <NUM_LIT:3> ] ] ) <EOL> rgb = colorsys . hsv_to_rgb ( h , s , v ) <EOL> normal [ <NUM_LIT:1> ] = ( rgb [ <NUM_LIT:1> ] * <NUM_LIT> ) + math . floor ( ( rgb [ <NUM_LIT:0> ] * <NUM_LIT> ) ) <EOL> normal [ <NUM_LIT:2> ] = ( a * <NUM_LIT> ) + math . floor ( ( rgb [ <NUM_LIT:2> ] * <NUM_LIT> ) ) <EOL> manager . normals [ textBlock . _buffer_index + index , : ] = normal <EOL> class TextBlock ( object ) : <EOL> def __init__ ( self , x , y , z , rot , char_count , data_obj = None , attr = None , <EOL> text_format = "<STR_LIT>" , size = <NUM_LIT> , spacing = "<STR_LIT:C>" , space = <NUM_LIT> , <EOL> colour = ( <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:1.0> ) , char_rot = <NUM_LIT:0.0> , justify = <NUM_LIT:0.0> ) : <EOL> """<STR_LIT>""" <EOL> self . x = x <EOL> self . y = y <EOL> self . z = z <EOL> self . rot = math . radians ( rot ) <EOL> self . char_count = char_count <EOL> self . data_obj = data_obj <EOL> self . attr = attr <EOL> self . text_format = text_format <EOL> self . size = size <EOL> self . spacing = spacing <EOL> self . space = space <EOL> self . point_size = <NUM_LIT> <EOL> if isinstance ( colour , tuple ) : <EOL> self . colouring = TextBlockColour ( colour , self ) <EOL> else : <EOL> self . colouring = colour <EOL> self . colouring . textBlock = self <EOL> self . char_rot = math . radians ( char_rot ) <EOL> self . justify = justify <EOL> self . last_value = self <EOL> self . rotation_changed = False <EOL> self . _buffer_index = <NUM_LIT:0> <EOL> self . _text_manager = None <EOL> self . _string_length = <NUM_LIT:0> <EOL> self . char_offsets = [ <NUM_LIT:0.0> ] * char_count <EOL> self . _string_length = len ( self . get_string ( self . get_value ( ) ) ) <EOL> def set_text_manager ( self , manager , buffer_index ) : <EOL> self . _text_manager = manager <EOL> self . _buffer_index = buffer_index <EOL> def get_value ( self ) : <EOL> if ( self . attr is not None ) and ( self . data_obj is not None ) : <EOL> return getattra ( self . data_obj , self . attr , None ) <EOL> return None <EOL> def get_string ( self , value ) : <EOL> if value is not None : <EOL> strval = self . text_format . format ( value ) <EOL> self . _string_length = len ( strval ) <EOL> return strval <EOL> return self . text_format <EOL> def set_position ( self , x = None , y = None , z = None , rot = None ) : <EOL> if x is not None : <EOL> self . x = x <EOL> if y is not None : <EOL> self . y = y <EOL> if z is not None : <EOL> self . z = z <EOL> if rot is not None : <EOL> self . rot = math . radians ( rot ) <EOL> size_pos , __ = math . modf ( self . size ) <EOL> size_pos += math . trunc ( self . z * <NUM_LIT> ) <EOL> pos = [ self . x , self . y , size_pos ] <EOL> locations = np . zeros ( ( self . char_count , <NUM_LIT:3> ) , dtype = np . float ) <EOL> locations [ : , <NUM_LIT:0> ] = np . multiply ( self . char_offsets , math . cos ( self . rot ) ) <EOL> locations [ : , <NUM_LIT:1> ] = np . multiply ( self . char_offsets , math . sin ( self . rot ) ) <EOL> locations = np . add ( locations , pos ) <EOL> st = self . _buffer_index <EOL> mid = st + self . _string_length <EOL> end = st + self . char_count <EOL> self . _text_manager . locations [ st : end , : ] = locations <EOL> self . _text_manager . normals [ st : mid , <NUM_LIT:0> ] = self . rot + self . char_rot <EOL> self . _text_manager . set_do_reinit ( ) <EOL> def recolour ( self ) : <EOL> self . colouring . recolour ( ) <EOL> def set_text ( self , text_format = None , size = None , spacing = None , space = None , <EOL> char_rot = None , set_pos = True , set_colour = True ) : <EOL> if text_format is not None : <EOL> self . text_format = text_format <EOL> if size is not None : <EOL> self . size = size <EOL> if spacing is not None : <EOL> self . spacing = spacing <EOL> if space is not None : <EOL> self . space = space <EOL> if char_rot is not None : <EOL> self . char_rot = math . radians ( char_rot ) <EOL> if self . data_obj is not None : <EOL> value = self . get_value ( ) <EOL> strval = self . get_string ( value ) <EOL> self . last_value = value <EOL> else : <EOL> strval = self . text_format <EOL> self . _string_length = len ( strval ) <EOL> pos = <NUM_LIT:0.0> <EOL> index = <NUM_LIT:0> <EOL> const_width = <NUM_LIT:0.0> <EOL> vari_width = <NUM_LIT:0.0> <EOL> if self . spacing == "<STR_LIT:C>" : <EOL> const_width = <NUM_LIT> * self . size * self . space <EOL> if self . spacing == "<STR_LIT:M>" : <EOL> vari_width = self . size * self . space <EOL> if self . spacing == "<STR_LIT:F>" : <EOL> vari_width = self . size <EOL> const_width = ( <NUM_LIT> * self . space * self . size ) <EOL> for char in strval : <EOL> glyph = self . _text_manager . font . glyph_table [ char ] <EOL> self . _text_manager . uv [ index + self . _buffer_index ] = glyph [ <NUM_LIT:4> : ] <EOL> """<STR_LIT>""" <EOL> g_scale = float ( self . _text_manager . point_size ) / self . _text_manager . font . height <EOL> char_offset = pos <EOL> if self . spacing == "<STR_LIT:F>" : <EOL> char_offset += float ( glyph [ <NUM_LIT:0> ] ) * g_scale * self . size * <NUM_LIT:0.5> <EOL> self . char_offsets [ index ] = char_offset <EOL> spacing = ( glyph [ <NUM_LIT:0> ] * g_scale * vari_width ) + const_width <EOL> pos += spacing <EOL> index += <NUM_LIT:1> <EOL> self . char_offsets = np . add ( self . char_offsets , ( pos - spacing ) * - self . justify ) <EOL> if set_pos : <EOL> self . set_position ( ) <EOL> if set_colour : <EOL> self . recolour ( ) <EOL> self . _text_manager . set_do_reinit ( ) </s>
