Example #1
0
    def on_paint(self, event):
        '''EVT_PAINT handler.'''
        # todo: optimization: if motion blur is (rounded to) zero, don't draw
        
        event.Skip()
        
        if self.recalculation_flag:
            self._recalculate(possibly_refresh=False)
            # We make sure `_recalculate` won't refresh, because that would make
            # an infinite loop
            
        bw, bh = self.GetWindowBorderSize()
        
        ox, oy = ((4 - bw) / 2 , (4 - bh) / 2)

        self.current_bitmap = images.get_blurred_gear_image_by_ratio(
            self.current_frame_number,
            self.current_blur_alpha
        )
        
        #print(self.current_frame_number,
            #self.current_blur_alpha)
        
        dc = wx.PaintDC(self)
        dc.DrawBitmap(self.current_bitmap, ox, oy)
Example #2
0
    def __update_motion_blur_bitmap(self, possibly_refresh):
        '''
        Check the speed and update the motion blur bitmap if necessary.
        
        If `possibly_refresh` is True, and this function sees that the image on
        the scratch wheel should change, then it will trigger a `Refresh`.
        '''

        current = (time.time(), self.get_current_angle())
        last = self.last_tracked_time_and_angle

        d_time = current[0] - last[0]
        d_angle = current[1] - last[1]
        
        if d_time < self.velocity_time_sampling_minimum:
            self.motion_blur_update_timer.Start(30)
            return
            # This protects us from two things: Having a grossly inaccurate
            # velocity reading because of tiny sample, and having a division by
            # zero.
        
        self.current_velocity_estimate = velocity = d_angle / d_time

        r_velocity = velocity / self.velocity_for_maximal_motion_blur

        alpha = min(abs(r_velocity), 1)
        
        alpha = min(alpha, 0.8)
        # I'm limiting the alpha, still want to see some animation
        
        self.current_blur_alpha = alpha
        
        new_bitmap = images.get_blurred_gear_image_by_ratio(
            self.current_frame_number,
            alpha
        )
        
        if self.current_bitmap is not new_bitmap:
            # No need to do this:
            # self.current_bitmap = new_bitmap
            # The `on_paint` handler will do it anyway
            if possibly_refresh:
                self.Refresh()
        
        if new_bitmap.blur_raw is not images.get_blur_image_raw(0):
            # We have a non-zero visible motion blur
            self.motion_blur_update_timer.Start(30)
        else:
            self.motion_blur_update_timer.Stop()
            
        self.last_tracked_time_and_angle = current