def draw(self): # XXX This method is not speed-optimized. I just wrote it to # get the job done. (Nonetheless, it seems faster than the C # version commented out above.) p = self.parameters # shorthand now_sec = VisionEgg.time_func() if self.start_times_sec is not None: # compute extinct dots and generate new positions replace_indices = Numeric.nonzero( Numeric.greater( now_sec - self.start_times_sec, p.dot_lifespan_sec) ) Numeric.put( self.start_times_sec, replace_indices, now_sec ) new_centers = np.random.standard_normal((3,len(replace_indices))) for i in range(3): Numeric.put( self.centers[i,:], replace_indices, new_centers[i,:] ) else: # initialize dot extinction values to random (uniform) distribution self.start_times_sec = RandomArray.uniform( now_sec - p.dot_lifespan_sec, now_sec, (self.constant_parameters.num_dots,)) time_delta_sec = now_sec - self.last_time_sec self.last_time_sec = now_sec # reset for next loop self.centers = self.centers + np.array(p.signal_vec)[:,np.newaxis]*time_delta_sec xyz = self.centers*p.start_position_variance + np.array(p.start_position_mean)[:,np.newaxis] xs = xyz[0,:] ys = xyz[1,:] zs = xyz[2,:] if p.on: gl.glEnable( gl.GL_POINT_SMOOTH ) # allow max_alpha value to control blending gl.glEnable( gl.GL_BLEND ) gl.glBlendFunc( gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA ) gl.glPointSize(p.dot_size) # Clear the modeview matrix gl.glMatrixMode(gl.GL_MODELVIEW) gl.glPushMatrix() gl.glDisable(gl.GL_TEXTURE_2D) draw_dots(xs,ys,zs,self.colors) gl.glDisable( gl.GL_POINT_SMOOTH ) # turn off gl.glPopMatrix()
def draw(self): # XXX This method is not speed-optimized. I just wrote it to # get the job done. (Nonetheless, it seems faster than the C # version commented out above.) p = self.parameters # shorthand if p.center is not None: if not hasattr(VisionEgg.config, "_GAVE_CENTER_DEPRECATION"): logger = logging.getLogger('VisionEgg.Dots') logger.warning("Specifying DotArea2D by deprecated " "'center' parameter deprecated. Use " "'position' parameter instead. (Allows " "use of 'anchor' parameter to set to " "other values.)") VisionEgg.config._GAVE_CENTER_DEPRECATION = 1 p.anchor = 'center' p.position = p.center[0], p.center[ 1] # copy values (don't copy ref to tuple) if p.on: # calculate center center = VisionEgg._get_center(p.position, p.anchor, p.size) if p.anti_aliasing: if len(p.color) == 4 and not self._gave_alpha_warning: if p.color[3] != 1.0: logger = logging.getLogger('VisionEgg.Dots') logger.warning("The parameter anti_aliasing is " "set to true in the DotArea2D " "stimulus class, but the color " "parameter specifies an alpha " "value other than 1.0. To " "acheive the best anti-aliasing, " "ensure that the alpha value for " "the color parameter is 1.0.") self._gave_alpha_warning = 1 gl.glEnable(gl.GL_POINT_SMOOTH) # allow max_alpha value to control blending gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) else: gl.glDisable(gl.GL_BLEND) now_sec = VisionEgg.time_func() if self.start_times_sec is not None: # compute extinct dots and generate new positions replace_indices = Numeric.nonzero( Numeric.greater(now_sec - self.start_times_sec, p.dot_lifespan_sec)) Numeric.put(self.start_times_sec, replace_indices, now_sec) new_x_positions = RandomArray.uniform(0.0, 1.0, (len(replace_indices), )) Numeric.put(self.x_positions, replace_indices, new_x_positions) new_y_positions = RandomArray.uniform(0.0, 1.0, (len(replace_indices), )) Numeric.put(self.y_positions, replace_indices, new_y_positions) new_random_directions_radians = RandomArray.uniform( 0.0, 2 * math.pi, (len(replace_indices), )) Numeric.put(self.random_directions_radians, replace_indices, new_random_directions_radians) else: # initialize dot extinction values to random (uniform) distribution self.start_times_sec = RandomArray.uniform( now_sec - p.dot_lifespan_sec, now_sec, (self.constant_parameters.num_dots, )) signal_num_dots = int( round(p.signal_fraction * self.constant_parameters.num_dots)) time_delta_sec = now_sec - self.last_time_sec self.last_time_sec = now_sec # reset for next loop x_increment_normalized = math.cos( p.signal_direction_deg / 180.0 * math.pi ) * p.velocity_pixels_per_sec / p.size[0] * time_delta_sec y_increment_normalized = -math.sin( p.signal_direction_deg / 180.0 * math.pi ) * p.velocity_pixels_per_sec / p.size[1] * time_delta_sec self.x_positions[:signal_num_dots] += x_increment_normalized self.y_positions[:signal_num_dots] += y_increment_normalized num_random_dots = self.constant_parameters.num_dots - signal_num_dots random_x_increment_normalized = Numeric.cos( self.random_directions_radians[signal_num_dots:] ) * p.velocity_pixels_per_sec / p.size[0] * time_delta_sec random_y_increment_normalized = -Numeric.sin( self.random_directions_radians[signal_num_dots:] ) * p.velocity_pixels_per_sec / p.size[1] * time_delta_sec self.x_positions[signal_num_dots:] += random_x_increment_normalized self.y_positions[signal_num_dots:] += random_y_increment_normalized self.x_positions = Numeric.fmod(self.x_positions, 1.0) # wrap self.y_positions = Numeric.fmod(self.y_positions, 1.0) self.x_positions = Numeric.fmod(self.x_positions + 1, 1.0) # wrap again for values < 1 self.y_positions = Numeric.fmod(self.y_positions + 1, 1.0) xs = (self.x_positions - 0.5) * p.size[0] + center[0] ys = (self.y_positions - 0.5) * p.size[1] + center[1] if len(p.color) == 3: gl.glColor3f(*p.color) elif len(p.color) == 4: gl.glColor4f(*p.color) gl.glPointSize(p.dot_size) # Clear the modeview matrix gl.glMatrixMode(gl.GL_MODELVIEW) gl.glPushMatrix() gl.glDisable(gl.GL_TEXTURE_2D) if p.depth is None: depth = 0.0 else: gl.glEnable(gl.GL_DEPTH_TEST) depth = p.depth zs = (depth, ) * len(xs) # make N tuple with repeat value of depth draw_dots(xs, ys, zs) if p.anti_aliasing: gl.glDisable(gl.GL_POINT_SMOOTH) # turn off gl.glPopMatrix()
def draw(self): # XXX This method is not speed-optimized. I just wrote it to # get the job done. (Nonetheless, it seems faster than the C # version commented out above.) p = self.parameters # shorthand if p.center is not None: if not hasattr(VisionEgg.config,"_GAVE_CENTER_DEPRECATION"): logger = logging.getLogger('VisionEgg.Dots') logger.warning("Specifying DotArea2D by deprecated " "'center' parameter deprecated. Use " "'position' parameter instead. (Allows " "use of 'anchor' parameter to set to " "other values.)") VisionEgg.config._GAVE_CENTER_DEPRECATION = 1 p.anchor = 'center' p.position = p.center[0], p.center[1] # copy values (don't copy ref to tuple) if p.on: # calculate center center = VisionEgg._get_center(p.position,p.anchor,p.size) if p.anti_aliasing: if len(p.color) == 4 and not self._gave_alpha_warning: if p.color[3] != 1.0: logger = logging.getLogger('VisionEgg.Dots') logger.warning("The parameter anti_aliasing is " "set to true in the DotArea2D " "stimulus class, but the color " "parameter specifies an alpha " "value other than 1.0. To " "acheive the best anti-aliasing, " "ensure that the alpha value for " "the color parameter is 1.0.") self._gave_alpha_warning = 1 gl.glEnable( gl.GL_POINT_SMOOTH ) # allow max_alpha value to control blending gl.glEnable( gl.GL_BLEND ) gl.glBlendFunc( gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA ) else: gl.glDisable( gl.GL_BLEND ) now_sec = VisionEgg.time_func() if self.start_times_sec is not None: # compute extinct dots and generate new positions replace_indices = Numeric.nonzero( Numeric.greater( now_sec - self.start_times_sec, p.dot_lifespan_sec) ) Numeric.put( self.start_times_sec, replace_indices, now_sec ) new_x_positions = RandomArray.uniform(0.0,1.0, (len(replace_indices),)) Numeric.put( self.x_positions, replace_indices, new_x_positions ) new_y_positions = RandomArray.uniform(0.0,1.0, (len(replace_indices),)) Numeric.put( self.y_positions, replace_indices, new_y_positions ) new_random_directions_radians = RandomArray.uniform(0.0,2*math.pi, (len(replace_indices),)) Numeric.put( self.random_directions_radians, replace_indices, new_random_directions_radians ) else: # initialize dot extinction values to random (uniform) distribution self.start_times_sec = RandomArray.uniform( now_sec - p.dot_lifespan_sec, now_sec, (self.constant_parameters.num_dots,)) signal_num_dots = int(round(p.signal_fraction * self.constant_parameters.num_dots)) time_delta_sec = now_sec - self.last_time_sec self.last_time_sec = now_sec # reset for next loop x_increment_normalized = math.cos(p.signal_direction_deg/180.0*math.pi) * p.velocity_pixels_per_sec / p.size[0] * time_delta_sec y_increment_normalized = -math.sin(p.signal_direction_deg/180.0*math.pi) * p.velocity_pixels_per_sec / p.size[1] * time_delta_sec self.x_positions[:signal_num_dots] += x_increment_normalized self.y_positions[:signal_num_dots] += y_increment_normalized num_random_dots = self.constant_parameters.num_dots - signal_num_dots random_x_increment_normalized = Numeric.cos(self.random_directions_radians[signal_num_dots:]) * p.velocity_pixels_per_sec / p.size[0] * time_delta_sec random_y_increment_normalized = -Numeric.sin(self.random_directions_radians[signal_num_dots:]) * p.velocity_pixels_per_sec / p.size[1] * time_delta_sec self.x_positions[signal_num_dots:] += random_x_increment_normalized self.y_positions[signal_num_dots:] += random_y_increment_normalized self.x_positions = Numeric.fmod( self.x_positions, 1.0 ) # wrap self.y_positions = Numeric.fmod( self.y_positions, 1.0 ) self.x_positions = Numeric.fmod( self.x_positions+1, 1.0 ) # wrap again for values < 1 self.y_positions = Numeric.fmod( self.y_positions+1, 1.0 ) xs = (self.x_positions - 0.5) * p.size[0] + center[0] ys = (self.y_positions - 0.5) * p.size[1] + center[1] if len(p.color)==3: gl.glColor3f(*p.color) elif len(p.color)==4: gl.glColor4f(*p.color) gl.glPointSize(p.dot_size) # Clear the modeview matrix gl.glMatrixMode(gl.GL_MODELVIEW) gl.glPushMatrix() gl.glDisable(gl.GL_TEXTURE_2D) if p.depth is None: depth = 0.0 else: gl.glEnable(gl.GL_DEPTH_TEST) depth = p.depth zs = (depth,)*len(xs) # make N tuple with repeat value of depth draw_dots(xs,ys,zs) if p.anti_aliasing: gl.glDisable( gl.GL_POINT_SMOOTH ) # turn off gl.glPopMatrix()