<s> from __future__ import absolute_import , division , print_function , unicode_literals <EOL> import demo <EOL> import pi3d <EOL> import numpy as np <EOL> def normal_map ( texture , factor = <NUM_LIT:1.0> ) : <EOL> '''<STR_LIT>''' <EOL> gray = ( texture . image [ : , : , : <NUM_LIT:3> ] * [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) . sum ( axis = <NUM_LIT:2> ) <EOL> grdnt = np . gradient ( gray ) <EOL> grdnt [ <NUM_LIT:0> ] = <NUM_LIT> - grdnt [ <NUM_LIT:0> ] * <NUM_LIT:0.5> * factor <EOL> grdnt [ <NUM_LIT:1> ] = <NUM_LIT> + grdnt [ <NUM_LIT:1> ] * <NUM_LIT:0.5> * factor <EOL> z = np . maximum ( <NUM_LIT:0> , <NUM_LIT> - grdnt [ <NUM_LIT:0> ] ** <NUM_LIT:2> - grdnt [ <NUM_LIT:1> ] ** <NUM_LIT:2> ) <EOL> n_map = np . zeros ( texture . image . shape [ : <NUM_LIT:2> ] + ( <NUM_LIT:3> , ) , dtype = np . uint8 ) <EOL> n_map [ : , : , <NUM_LIT:0> ] = grdnt [ <NUM_LIT:0> ] . astype ( np . uint8 ) <EOL> n_map [ : , : , <NUM_LIT:1> ] = grdnt [ <NUM_LIT:1> ] . astype ( np . uint8 ) <EOL> n_map [ : , : , <NUM_LIT:2> ] = ( z ** <NUM_LIT:0.5> ) . astype ( np . uint8 ) <EOL> return pi3d . Texture ( n_map ) <EOL> class StarSystem ( object ) : <EOL> def __init__ ( self , star_ref , planet_tex , obj_object , v ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> self . flatsh = pi3d . Shader ( '<STR_LIT>' ) <EOL> self . shader = pi3d . Shader ( '<STR_LIT>' ) <EOL> self . star_tex = pi3d . Texture ( '<STR_LIT>' ) <EOL> self . star = None <EOL> self . planet = None <EOL> self . change_details ( star_ref , planet_tex , obj_object , v ) <EOL> self . visible = True <EOL> def draw ( self ) : <EOL> if self . visible : <EOL> self . star . draw ( ) <EOL> self . planet . draw ( ) <EOL> self . obj_object . draw ( ) <EOL> self . planet . rotateIncY ( - <NUM_LIT> ) <EOL> self . obj_object . rotateIncY ( <NUM_LIT:0.1> ) <EOL> self . obj_object . rotateIncZ ( <NUM_LIT> ) <EOL> def change_details ( self , star_ref , planet_tex , obj_object , v ) : <EOL> self . star_ref = star_ref <EOL> star_loc = v [ star_ref , <NUM_LIT:0> : <NUM_LIT:3> ] <EOL> star_rgb = v [ star_ref , <NUM_LIT:3> : <NUM_LIT:6> ] <EOL> light = pi3d . Light ( is_point = True , lightpos = star_loc , lightcol = star_rgb * <NUM_LIT> , <EOL> lightamb = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> if self . star is None : <EOL> self . star = pi3d . Sphere ( radius = <NUM_LIT> , slices = <NUM_LIT> , sides = <NUM_LIT> ) <EOL> self . star . set_draw_details ( self . flatsh , [ self . star_tex ] ) <EOL> self . star . set_material ( star_rgb ) <EOL> self . star . position ( * star_loc ) <EOL> if self . planet is None : <EOL> self . planet = pi3d . Sphere ( radius = <NUM_LIT:0.1> , slices = <NUM_LIT> , sides = <NUM_LIT> , light = light ) <EOL> self . planet . set_draw_details ( self . shader , planet_tex , <NUM_LIT:1.0> , <NUM_LIT:0.0> ) <EOL> self . planet . set_light ( light ) <EOL> self . planet . position ( star_loc [ <NUM_LIT:0> ] , star_loc [ <NUM_LIT:1> ] , star_loc [ <NUM_LIT:2> ] - <NUM_LIT> ) <EOL> self . obj_object = obj_object <EOL> self . obj_object . set_shader ( self . shader ) <EOL> self . obj_object . set_light ( light ) <EOL> self . obj_object . position ( star_loc [ <NUM_LIT:0> ] + <NUM_LIT> , star_loc [ <NUM_LIT:1> ] , star_loc [ <NUM_LIT:2> ] - <NUM_LIT> ) <EOL> systems = [ [ <NUM_LIT:0> , pi3d . Texture ( "<STR_LIT>" ) , pi3d . Model ( file_string = '<STR_LIT>' , sx = <NUM_LIT> , sy = <NUM_LIT> , sz = <NUM_LIT> ) ] ] <EOL> '''<STR_LIT>''' <EOL> for s in systems : <EOL> s [ <NUM_LIT:1> ] = [ s [ <NUM_LIT:1> ] , normal_map ( s [ <NUM_LIT:1> ] ) ] </s>
