예제 #1
0
파일: coverflow.py 프로젝트: oukiar/devslib
    def cancel_movement(self):
        '''
        Restaura las posiciones de manera fluida
        '''
        
        self.canceling_move = True
        
        Clock.unschedule(self.end_move)
        
        for i in self.covers:
            Animation.cancel_all(i, 'pos_x', 'rotate_y', 'scale_x', 'scale_y', 'opacity')
        
            xtrans, yrot, scale3d = self.covers_positions[self.covers.index(i)]

            #enabled smoth transition
            Animation(pos_x=xtrans, 
                        rotate_y=yrot,
                        scale_x=scale3d[0],
                        scale_y=scale3d[1],
                        opacity=1,
                        duration=self.move_duration
                        ).start(i)
                        
        #centinel reset
        Animation.cancel_all(self.centinel, 'opacity')
        self.centinel.opacity = 1
        
        self.direction = 0
        Clock.schedule_once(self.end_cancel_movement, self.move_duration)
예제 #2
0
 def on_touch_down(self, touch):
     if self in touch.ud:
         self.anim_complete(self, self)
         self.ripple_pos = ripple_pos = (touch.x, touch.y)
         Animation.cancel_all(self, 'ripple_rad', 'ripple_color')
         rc = self.ripple_color
         ripple_rad = self.ripple_rad
         self.ripple_color = [rc[0], rc[1], rc[2], 1.]
         anim = Animation(
             ripple_rad=max(self.width, self.height) * self.ripple_scale, 
             t=self.ripple_func_in,
             ripple_color=[rc[0], rc[1], rc[2], self.fade_to_alpha], 
             duration=self.ripple_duration_in)
         anim.start(self)
         with self.canvas.after:
             x,y = self.to_window(*self.pos)
             width, height = self.size
             #In python 3 the int cast will be unnecessary
             ScissorPush(x=int(round(x)), y=int(round(y)),
                 width=int(round(width)), height=int(round(height)))
             self.col_instruction = Color(rgba=self.ripple_color)
             self.ellipse = Ellipse(size=(ripple_rad, ripple_rad),
                 pos=(ripple_pos[0] - ripple_rad/2., 
                 ripple_pos[1] - ripple_rad/2.))
             ScissorPop()
         self.bind(ripple_color=self.set_color, ripple_pos=self.set_ellipse,
             ripple_rad=self.set_ellipse)
     return super(TouchRippleBehavior, self).on_touch_down(touch)
예제 #3
0
 def on_touch_down(self, touch):
     if self.collide_point(touch.x, touch.y):
         # self.anim_complete(self, self)
         self.ripple_pos = ripple_pos = (touch.x, touch.y)
         Animation.cancel_all(self, 'ripple_rad', 'ripple_color')
         rc = self.ripple_color
         ripple_rad = self.ripple_rad
         self.ripple_color = [rc[0], rc[1], rc[2], 1.]
         anim = Animation(
             ripple_rad=max(self.width, self.height) * self.ripple_scale,
             t=self.ripple_func_in,
             ripple_color=[rc[0], rc[1], rc[2], self.fade_to_alpha],
             duration=self.ripple_duration_in)
         anim.bind(on_complete=self.anim_complete)
         anim.start(self)
         with self.canvas:
             StencilPush()
             Rectangle(size=self.size, pos=self.pos)
             StencilUse()
             self.col_instruction = Color(
                 rgba=self.ripple_color, group='one')
             self.ellipse = Ellipse(
                 size=(ripple_rad, ripple_rad),
                 pos=(ripple_pos[0] - ripple_rad/2.,
                      ripple_pos[1] - ripple_rad/2.),
                 group='one')
             StencilUnUse()
             Rectangle(size=self.size, pos=self.pos)
             StencilPop()
         self.bind(
             ripple_color=self.set_color, ripple_pos=self.set_ellipse,
             ripple_rad=self.set_ellipse)
     return super(TouchRippleBehavior, self).on_touch_down(touch)
예제 #4
0
파일: main.py 프로젝트: djhedges/kivy
 def on_touch_up(self, touch):
     sup = super(Card, self).on_touch_up(touch)
     if touch.pos[1] > (self.parent.height * 0.8):
         Animation.cancel_all(self)
         anim = Animation(y=(self.parent.height + self.height))
         anim.start(self)
     return sup
예제 #5
0
 def on_touch_up(self, touch):
     if not self.disabled:
         if touch.grab_current is not self:
             return super(ButtonBehavior, self).on_touch_up(touch)
         Animation.cancel_all(self, "elevation")
         self.elevation_release_anim.start(self)
     return super(MDRaisedButton, self).on_touch_up(touch)
예제 #6
0
    def on_touch_down(self, touch):
        xtouch = touch.x
        ytouch = touch.y

        #animation that moves the ship to a designatd x and y coordinate
        Animation.cancel_all(self)
        self.anim = Animation(x=xtouch, y=ytouch, duration=0.25, t='linear')
        self.anim.bind(on_start = self.on_start)
        self.anim.bind(on_progress = self.on_progess)
        self.anim.start(self)

        #x1,y1 is the ships current position
        #x2,y2 is the postition it is moving to
        x1 = self.x
        y1 = self.y
        x2 = touch.x
        y2 = touch.y
        deltaX = x2 - x1
        deltaY = y2 - y1
        angle = math.atan2(deltaY, deltaX)

        #convert it from 180 degrees to 360
        if self.degrees <= 0:
            self.degrees = 360 - (-self.degrees)
        #convert it from radians to degrees
        self.degrees = angle * (180 / math.pi)
예제 #7
0
파일: carousel.py 프로젝트: ikol/PURIKURA
    def _start_animation(self, *args):
        Animation.cancel_all(self)

        # compute target offset for ease back, next or prev
        new_offset = 0
        is_horizontal = self.direction in ['right', 'left']
        extent = self.width if is_horizontal else self.height
        if self._offset < self.min_move * -extent:
            new_offset = -extent
        elif self._offset > self.min_move * extent:
            new_offset = extent

        # if new_offset is 0, it wasnt enough to go next/prev
        dur = self.anim_move_duration
        if new_offset == 0:
            dur = self.anim_cancel_duration

        if not self.loop:  # detect edge cases if not looping
            is_first = (self.index == 0)
            is_last = (self.index == len(self.slides) - 1)
            if self.direction in ['right', 'top']:
                towards_prev = (new_offset > 0)
                towards_next = (new_offset < 0)
            if self.direction in ['left', 'bottom']:
                towards_prev = (new_offset < 0)
                towards_next = (new_offset > 0)
            if (is_first and towards_prev) or (is_last and towards_next):
                new_offset = 0

        anim = Animation(_offset=new_offset, d=dur, t='out_quad')
        anim.start(self)
예제 #8
0
 def on_touch_down(self, touch):
     col_self = self.collide_point(*touch.pos)
     col_side = self._side_panel.collide_point(*touch.pos)
     if col_side and not self._main_above and self._anim_progress > 0:
         self._side_panel.on_touch_down(touch)
         return
     if not col_self or self._touch is not None:
         super(NavigationDrawer, self).on_touch_down(touch)
         return
     if self._anim_progress > 0.001:
         valid_region = (self._main_panel.x <=
                         touch.x <=
                         (self._main_panel.x + self._main_panel.width))
     else:
         valid_region = (self.x <=
                         touch.x <=
                         (self.x + self.touch_accept_width))
     if not valid_region:
         super(NavigationDrawer, self).on_touch_down(touch)
         return False
     Animation.cancel_all(self)
     self._anim_init_progress = self._anim_progress
     self._touch = touch
     touch.ud['type'] = self.state
     touch.ud['panels_jiggled'] = False  # If user moved panels back
                                         # and forth, don't default
                                         # to close on touch release
     touch.grab(self)
     return True
예제 #9
0
 def enpanel(self):
   def complete(animation,widget):
     self.ruddertrim_active = True
   Animation.cancel_all(self)
   anim = Animation(y=0,t='out_expo',duration=0.3) 
   anim.bind(on_complete=complete)
   anim.start(self)
예제 #10
0
 def dispanel(self):
   def complete(animation,widget):
     self.ruddertrim_active = False
   Animation.cancel_all(self)
   anim = Animation(y=-self.height,t='out_expo',duration=0.3) 
   anim.bind(on_complete=complete)
   anim.start(self)
예제 #11
0
	def on_touch_down(self, touch):
		if touch.is_mouse_scrolling:
			return False
		if not self.collide_point(touch.x, touch.y):
			return False

		if not self.disabled:
			if self.doing_ripple:
				Animation.cancel_all(self, 'ripple_rad', 'ripple_color',
				                     'rect_color')
				self.anim_complete()
			self.ripple_rad = self.ripple_rad_default
			self.ripple_pos = (touch.x, touch.y)

			if self.ripple_color != []:
				pass
			elif hasattr(self, 'theme_cls'):
				self.ripple_color = self.theme_cls.ripple_color
			else:
				# If no theme, set Grey 300
				self.ripple_color = [0.8784313725490196, 0.8784313725490196,
				                     0.8784313725490196, self.ripple_alpha]
			self.ripple_color[3] = self.ripple_alpha

			self.lay_canvas_instructions()
			self.finish_rad = max(self.width, self.height) * self.ripple_scale
			self.start_ripple()
		return super(CommonRipple, self).on_touch_down(touch)
예제 #12
0
	def on_touch_down(self, touch):
		if touch.is_mouse_scrolling:
			return False
		if not self.collide_point(touch.x, touch.y):
			return False
		if hasattr(self, 'disabled'):
			if not self.disabled:
				self.ripple_rad = self.ripple_rad_default
				self.ripple_pos = ripple_pos = (touch.x, touch.y)
				Animation.cancel_all(self, 'ripple_rad', 'ripple_color',
									 'rect_color')
				ripple_rad = self.ripple_rad

				if not hasattr(self, 'ripple_color'):
					self.rip_color = [rc[0], rc[1], rc[2], self.ripple_alpha]
				else:
					self.rip_color = self.ripple_color
					self.rip_color[3] = self.ripple_alpha

				with self.canvas.after:
					StencilPush()
					Rectangle(pos=self.pos, size=self.size)
					StencilUse()
					self.col_instruction = Color(rgba=self.rip_color)
					self.ellipse = Ellipse(size=(ripple_rad, ripple_rad),
										   pos=(ripple_pos[0] - ripple_rad / 2.,
												ripple_pos[1] - ripple_rad / 2.))
					StencilUnUse()
					Rectangle(pos=self.pos, size=self.size)
					StencilPop()
				self.bind(rip_color=self._set_color, ripple_pos=self._set_ellipse,
						  ripple_rad=self._set_ellipse)
				self.start_rippeling(touch)
		return super(RippleBehavior, self).on_touch_down(touch)
예제 #13
0
파일: main.py 프로젝트: djhedges/kivy
 def _fix_x_axis(self):
     increment = ((self.width - self.cards[0].width) / (len(self.cards) - 1))
     x = 0
     for card in SortCardsByX(self.cards):
         Animation.cancel_all(card)
         anim = Animation(x=x, y=0, t='in_out_back')
         anim.start(card)
         x += increment
예제 #14
0
파일: menus.py 프로젝트: asfin/electrum
    def hide(self, *dt):

        def on_stop(*l):
            Window.remove_widget(self)
        anim = Animation(opacity=0, d=.25)
        anim.bind(on_complete=on_stop)
        anim.cancel_all(self)
        anim.start(self)
예제 #15
0
            def move(window, height):
                if instance.y <= height:
                    offset = 0 if type(to_move) == Contacts else to_move.y
                    y = height - instance.y + offset + 10

                    # Avoid reset when we change focus
                    Animation.cancel_all(to_move, 'y')
                    Animation(y=y, t='linear', d=0.5).start(to_move)
예제 #16
0
 def _set_cursor_val(self, *args):
     '''Get last position of cursor where output was added.
     '''
     self._cursor_pos = self.cursor_index()
     from kivy.animation import Animation
     anim = Animation(scroll_y=0, d=0.5)
     anim.cancel_all(self.parent)
     anim.start(self.parent)
예제 #17
0
 def dispanel(self):
   def complete(animation,widget):
     self.padactive = False
     
   Animation.cancel_all(self)
   anim = Animation(y=self.parent.height*2,t='out_expo',duration=0.3) 
   anim.bind(on_complete=complete)
   anim.start(self)
예제 #18
0
 def _reset(self, *args):
     Animation.cancel_all(self, '_angle_start', '_rotation_angle',
                          '_angle_end', '_alpha')
     self._angle_start = 0
     self._angle_end = 8
     self._rotation_angle = 360
     self._alpha = 0
     self.active = False
예제 #19
0
  def enpanel(self):
    def complete(animation,widget):
      self.padactive = True

    Animation.cancel_all(self)
    anim = Animation(center_y=self.parent.parent.height-self.parent.height*1.04/2,t='out_expo',duration=0.3) 
    anim.bind(on_complete=complete)
    anim.start(self)
예제 #20
0
 def showanim(self):
   def complete(animation,widget):
     glb.root.rudder.rudder_active = False
     self.panel_active = True
   Animation.cancel_all(self)
   anim = Animation(y=0,t='out_expo',duration=0.3) 
   anim.bind(on_complete=complete)
   anim.start(self)
예제 #21
0
	def finnish_ripple(self, touch, *args):
		self._finnishing = True
		if self._rippeling:
			Animation.cancel_all(self, 'ripple_rad')
			anim = Animation(ripple_rad=max(self.width, self.height) * self.ripple_scale,
							  t=self.ripple_func_in,
							  duration=self.ripple_duration_in_fast)
			anim.bind(on_complete=self.fade_out)
			anim.start(self)
예제 #22
0
 def hide(self, *dt):
     ''' Auto fade out the Bubble
     '''
     def on_stop(*l):
         Window.remove_widget(self)
     anim = Animation(opacity=0, d=0.75)
     anim.bind(on_complete=on_stop)
     anim.cancel_all(self)
     anim.start(self)
예제 #23
0
	def finish_ripple(self):
		if self.doing_ripple and not self.finishing_ripple:
			Animation.cancel_all(self, 'ripple_rad')
			anim = Animation(ripple_rad=self.finish_rad,
			                 t=self.ripple_func_in,
			                 duration=self.ripple_duration_in_fast)
			anim.bind(on_complete=self.fade_out)
			self.finishing_ripple = True
			anim.start(self)
예제 #24
0
	def fade_out(self, *args):
		self._finnishing = True
		rc = self.ripple_color
		if self._rippeling:
			Animation.cancel_all(self, 'rip_color')
			anim = Animation(rip_color=[rc[0], rc[1], rc[2], 0.],
							 t=self.ripple_func_out, duration=self.ripple_duration_out)
			anim.bind(on_complete=self.anim_complete)
			anim.start(self)
예제 #25
0
파일: main.py 프로젝트: djhedges/kivy
 def on_touch_up(self, touch):
     if touch.pos[1] > (self.parent.height * 0.8):
         Animation.cancel_all(self)
         anim = Animation(y=(self.parent.height + self.height), 
                          t='in_out_circ')
         anim.start(self)
         # TODO remove the widget or something
         # self.parent.remove_widget(self)
     return super(Card, self).on_touch_up(touch)
    def anim_to_random_pos(self):
        Animation.cancel_all(self)
        
        random_x = random() * (Window.width - self.width)
        random_y = random() * (Window.height - self.height)

        anim = Animation(x=random_x, y=random_y, duration=4, t='out_elastic')

        anim.start(self)
예제 #27
0
	def fade_out(self, *args):
		rc = self.ripple_color
		if not self.fading_out:
			Animation.cancel_all(self, 'ripple_color')
			anim = Animation(ripple_color=[rc[0], rc[1], rc[2], 0.],
			                 t=self.ripple_func_out,
			                 duration=self.ripple_duration_out)
			anim.bind(on_complete=self.anim_complete)
			self.fading_out = True
			anim.start(self)
예제 #28
0
파일: main.py 프로젝트: djhedges/kivy
 def arrange_hand(self):
     img_width, img_height = self.cards[0].get_norm_image_size()
     x = 4 - (self.cards[0].width - img_width) / 2
     y = 4 - (self.cards[0].height- img_height) / 2
     increment = ((self.width - img_width) / 12)
     for card in self.cards:
         Animation.cancel_all(card)
         anim = Animation(x=x, y=y, t='in_out_back')
         anim.start(card)
         x += increment
예제 #29
0
 def on_touch_down(self, touch):
     if not self.disabled:
         if touch.is_mouse_scrolling:
             return False
         if not self.collide_point(touch.x, touch.y):
             return False
         if self in touch.ud:
             return False
         Animation.cancel_all(self, "elevation")
         self.elevation_press_anim.start(self)
     return super(MDRaisedButton, self).on_touch_down(touch)
    def on_touch_down(self, touch):
        xtouch = touch.x
        movex = self.center
        if xtouch >= self.center_x:                                                                                     #different response based on where click is
            movex = 600
        else:
            movex = -600

        Animation.cancel_all(self)
        anim = Animation(x = self.x + movex, duration = 15)
        anim.start(self)
예제 #31
0
    def show_game(self, running):
        Animation.cancel_all(self)
        self.canvas.clear()

        if not running:
            return

        self.add_widget(self._background)
        with self.canvas:
            # Load & configure the flock of bird animation frames
            birds = Image(source=IMAGES_PATH.format('birds.zip'),
                          pos=(Window.width, 400),
                          anim_delay=1)
            birds.size = birds.texture_size

            # Setup the flock of birds to move in wave pattern
            up_down = (Animation(y=375, d=5, t=self._sin_transition) +
                       Animation(y=425, d=5, t=self._sin_transition))
            up_down.repeat = True
            bird_animation = Animation(x=-birds.width, d=30) & up_down
            bird_animation.start(birds)
            bird_animation.bind(on_complete=self.on_birds_complete)

            # Initialize and draw the Mirror Cannon onto the canvas based on its state
            self._game.mirror.shape = Image(
                pos=(150, 260),
                source=ATLAS_PATH.format(
                    f'{self._game.mirror.id}-{self._game.mirror.state}'))
            self._game.mirror.shape.size = self._game.mirror.shape.texture_size

            # Change the color and display the incident
            # sun rays on the canvas
            self.canvas.add(self._game.sun_rays.color)
            self.canvas.add(self._game.sun_rays)

            # Change the color and display the death sun rays on the canvas
            self.canvas.add(
                Color(LIGHT_COLOR_MAX_RED, LIGHT_COLOR_MAX_GREEN,
                      LIGHT_COLOR_MAX_BLUE, 0.7))
            self.canvas.add(self._game.death_rays)

        # Add the Health Bar for the Castle/Island
        self.add_widget(self._hp_bar)

        # Add the Score display
        self.add_widget(self._score)
        self.add_widget(self.pause_btn)
예제 #32
0
    def ripple_show(self, touch):
        '''Begin ripple animation on current widget.

        Expects touch event as argument.
        '''
        self.init_pos = self.to_window(*self.pos)
        print self.init_pos
        Animation.cancel_all(self, 'ripple_rad', 'ripple_color')
        self._ripple_reset_pane()
        x, y = self.to_window(*self.pos)
        width, height = self.size
        if isinstance(self, RelativeLayout):
            self.ripple_pos = ripple_pos = (touch.x - self.pos[0], touch.y - self.pos[1])
        else:
            self.ripple_pos = ripple_pos = (touch.x, touch.y)
        if self.circular_ripple:
            self.ripple_pos = ripple_pos = self.ripple_center if self.ripple_center else self.center
        rc = self.ripple_color
        ripple_rad = self.ripple_rad
        self.ripple_color = [rc[0], rc[1], rc[2], self.ripple_fade_from_alpha]
        with self.ripple_pane:
            if not self.circular_ripple:
                self.sp = ScissorPush(
                    x=round(x),
                    y=round(y),
                    width=round(width),
                    height=round(height)
                )
            self.ripple_col_instruction = Color(rgba=self.ripple_color)
            self.ripple_ellipse = Ellipse(
                size=(ripple_rad, ripple_rad),
                pos=(
                    ripple_pos[0] - ripple_rad / 2.,
                    ripple_pos[1] - ripple_rad / 2.
                )
            )
            if not self.circular_ripple:
                ScissorPop()

        self.ripple_scale = self.circular_ripple if self.circular_ripple else self.ripple_scale
        anim = Animation(
            ripple_rad=max(width, height) * self.ripple_scale,
            t=self.ripple_func_in,
            ripple_color=[rc[0], rc[1], rc[2], self.ripple_fade_to_alpha],
            duration=self.ripple_duration_in
        )
        anim.start(self)
예제 #33
0
    def on_touch_down(self, touch):
        col_self = self.collide_point(*touch.pos)
        col_side = self._side_panel.collide_point(*touch.pos)
        col_main = self._main_panel.collide_point(*touch.pos)

        if self._anim_progress < 0.001:  # i.e. closed
            valid_region = (self.x <= touch.x <=
                            (self.x + self.touch_accept_width))
            if not valid_region:
                self._main_panel.on_touch_down(touch)
                return False
        else:
            if col_side and not self._main_above:
                Animation.cancel_all(self)
                self._anim_init_progress = self._anim_progress
                self._touch = touch
                touch.ud['type'] = self.state
                touch.ud['panels_jiggled'] = False
                self._side_panel.on_touch_down(touch)
                return False
            valid_region = (self._main_panel.x <= touch.x <=
                            (self._main_panel.x + self._main_panel.width))
            if not valid_region:
                if self._main_above:
                    if col_main:
                        self._main_panel.on_touch_down(touch)
                    elif col_side:
                        self._side_panel.on_touch_down(touch)
                else:
                    if col_side:
                        self._side_panel.on_touch_down(touch)
                    elif col_main:
                        self._main_panel.on_touch_down(touch)
                return False
        if touch.y < self.height:
            Animation.cancel_all(self)
            self._anim_init_progress = self._anim_progress
            self._touch = touch
            touch.ud['type'] = self.state
            touch.ud['panels_jiggled'] = False  # If user moved panels back
            # and forth, don't default
            # to close on touch release
            touch.grab(self)
        else:
            self._main_panel.on_touch_down(touch)
            return False
        return True
예제 #34
0
    def on_touch_down(self, touch):
        if self in touch.ud:
            self.anim_complete(self, self)
            self.ripple_pos = ripple_pos = (touch.x, touch.y)
            Animation.cancel_all(self, 'ripple_rad', 'ripple_color')
            rc = self.ripple_color
            ripple_rad = self.ripple_rad
            self.ripple_color = [rc[0], rc[1], rc[2], .16]
            anim = Animation(
                ripple_rad=max(self.width, self.height) * self.ripple_scale,
                t=self.ripple_func_in,
                ripple_color=[rc[0], rc[1], rc[2], self.fade_to_alpha],
                duration=self.ripple_duration_in)
            anim.start(self)
            with self.canvas.after:
                x,y = self.to_window(*self.pos)
                width, height = self.size
                #In python 3 the int cast will be unnecessary
                pos = (int(round(x)), int(round(y)))
                size = (int(round(width)), int(round(height)))

                if _has_scissor_instr:
                    ScissorPush(x=pos[0], y=pos[1],
                                width=size[0], height=size[1])
                else:
                    StencilPush()
                    Rectangle(pos=(int(round(x)), int(round(y))),
                              size=(int(round(width)), int(round(height))))

                    StencilUse()

                self.col_instruction = Color(rgba=self.ripple_color)
                self.ellipse = Ellipse(size=(ripple_rad, ripple_rad),
                                       pos=(ripple_pos[0] - ripple_rad/2.,
                                            ripple_pos[1] - ripple_rad/2.))

                if _has_scissor_instr:
                    ScissorPop()
                else:
                    StencilUnUse()
                    Rectangle(pos=(int(round(x)), int(round(y))),
                              size=(int(round(width)), int(round(height))))
                    StencilPop()

            self.bind(ripple_color=self.set_color, ripple_pos=self.set_ellipse,
                      ripple_rad=self.set_ellipse)
        return super(TouchRippleBehavior, self).on_touch_down(touch)
예제 #35
0
파일: imageloader.py 프로젝트: mwlt/akivymd
class AKImageLoader(ThemableBehavior, AsyncImage):

    bg_rec_opacity = NumericProperty(0)
    fr_rec_opacity = NumericProperty(0)
    circle = BooleanProperty(True)

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.start_anim = None

    def _check_source(self, source):
        if source == False or len(source.strip()) == 0:
            self.source = ' '
            return False
        else:
            return True

    def _start_animate(self):
        self.bg_rec_opacity = 1
        self.fr_rec_opacity = 1
        self.color = [1, 1, 1, 0]
        duration = 0.8

        self.start_anim = Animation(bg_rec_opacity=1, t='in_quad', duration=duration)\
            + Animation(bg_rec_opacity=0, t='out_quad', duration=duration)
        self.start_anim.repeat = True
        self.start_anim.start(self)

    def _stop_animate(self):
        duration = 0.8

        self.color = [1, 1, 1, 1]
        if self.start_anim:
            self.start_anim.cancel_all(self)
            self.stop_anim = Animation(fr_rec_opacity=0,
                                       t='out_quad',
                                       duration=0.1)
            self.stop_anim &= Animation(bg_rec_opacity=0,
                                        t='out_quad',
                                        duration=0.1)
            self.stop_anim.start(self)

    def on_source(self, *args):
        if self._check_source(self.source):
            self._stop_animate()
        else:
            self._start_animate()
예제 #36
0
    def _start_animation(self, *args, **kwargs):
        # compute target offset for ease back, next or prev
        new_offset = 0
        direction = kwargs.get('direction', self.direction)
        is_horizontal = direction[0] in ['r', 'l']
        extent = self.width if is_horizontal else self.height
        min_move = kwargs.get('min_move', self.min_move)
        _offset = kwargs.get('offset', self._offset)

        if _offset < min_move * -extent:
            new_offset = -extent
        elif _offset > min_move * extent:
            new_offset = extent

        if 'new_offset' in kwargs:
            new_offset = kwargs['new_offset']

        # if new_offset is 0, it wasnt enough to go next/prev
        dur = self.anim_move_duration
        if new_offset == 0:
            dur = self.anim_cancel_duration

        # detect edge cases if not looping
        len_slides = len(self.slides)
        index = self.index
        if not self.loop or len_slides == 1:
            is_first = (index == 0)
            is_last = (index == len_slides - 1)
            if direction[0] in ['r', 't']:
                towards_prev = (new_offset > 0)
                towards_next = (new_offset < 0)
            else:
                towards_prev = (new_offset < 0)
                towards_next = (new_offset > 0)
            if (is_first and towards_prev) or (is_last and towards_next):
                new_offset = 0

        anim = Animation(_offset=new_offset, d=dur, t=self.anim_type)
        anim.cancel_all(self)

        def _cmp(*l):
            if self._skip_slide is not None:
                self.index = self._skip_slide
                self._skip_slide = None

        anim.bind(on_complete=_cmp)
        anim.start(self)
예제 #37
0
    def start_(self, tmp=None):
        props = ["height", "width", "opacity"]

        vals = [self._original["height"] * 0.3, self._original["width"] * 0.3, 0]
        self._initialize(**dict(zip(props, vals)))

        vals = [self._original["height"] * 1.05, self._original["width"] * 1.05, 1]
        anim = Animation(d=self.duration / 3, **dict(zip(props, vals)),)

        vals = [self._original["height"] * 0.9, self._original["width"] * 0.9, 1]
        anim += Animation(d=self.duration / 3, **dict(zip(props, vals)),)

        anim += Animation(d=self.duration / 3, **self._original,)

        anim.cancel_all(self.widget)
        anim.start(self.widget)
        anim.bind(on_complete=partial(self.anim_complete, self))
예제 #38
0
 def on_touch_down(self, touch):
     Animation.cancel_all(self)
     anim_choices = [
         'in_back', 'in_bounce', 'in_circ', 'in_cubic', 'in_elastic',
         'in_expo', 'in_out_back', 'in_out_bounce', 'in_out_circ',
         'in_out_cubic', 'in_out_elastic', 'in_out_expo', 'in_out_quad',
         'in_out_quart', 'in_out_quint', 'in_out_sine', 'in_quad',
         'in_quart', 'in_quint', 'in_sine', 'linear', 'out_back',
         'out_bounce', 'out_circ', 'out_cubic', 'out_elastic', 'out_expo',
         'out_quad', 'out_quart', 'out_quint', 'out_sine'
     ]
     self.anim_choice = anim_choices[self.counter]
     anim = Animation(center_x=touch.x,
                      center_y=touch.y,
                      t=self.anim_choice)
     anim.start(self)
     self.counter = (self.counter + 1) % len(anim_choices)
예제 #39
0
    def _reset(self, *args):
        Animation.cancel_all(
            self,
            "_angle_start",
            "_rotation_angle",
            "_angle_end",
            "_alpha",
            "color",
        )
        self._angle_start = 0
        self._angle_end = 0
        self._rotation_angle = 360
        self._alpha = 0
        self.active = False

        if self.determinate:
            self._start_determinate()
예제 #40
0
    def randomize_position(self):
        self.console.text = ""
        x = [
            dp(500),
            dp(550),
            dp(600),
            dp(650),
            dp(700),
            dp(750),
            dp(800),
            dp(850),
            dp(900),
            dp(950),
            dp(1000)
        ]
        y = [
            dp(0),
            dp(50),
            dp(100),
            dp(150),
            dp(200),
            dp(250),
            dp(300),
            dp(350),
            dp(400),
            dp(450),
            dp(500),
            dp(550),
            dp(600)
        ]

        rand_x = random.choice(x)
        rand_y = random.choice(y)
        rand_color = (random.random(), random.random(), random.random())
        rand_color_hex = webcolors.rgb_to_hex(
            (int(round(rand_color[0] * 255,
                       3)), int(round(rand_color[1] * 255,
                                      3)), int(round(rand_color[2] * 255, 3))))

        self.robot.rgb = rand_color

        Animation.cancel_all(self.robot, 'x')
        anim = Animation(x=rand_x, y=rand_y, duration=0.4, t='in_out_cubic')
        anim.start(self.robot)
        self.console.text = "Randomized!\nPosition: [{}, {}]\nColor: {}".format(
            rand_x, rand_y, rand_color_hex)
예제 #41
0
	def start_(self, tmp=None):
		pivot= (self.widget.x-self.widget.width/2,self.widget.y)
		self.widget.origin_= pivot

		props=["angle","opacity"]
		vals=[-90,0]
		self._initialize(**dict(zip(props,vals)))

		vals=[0,1]
		anim= Animation(
			d= self.duration,
			**dict(zip(props,vals))
			)
		
		anim.cancel_all(self.widget)
		anim.start(self.widget)
		anim.bind(on_complete= partial(self.anim_complete, self))
예제 #42
0
 def on_touch_down(self, touch):
     if not self.collide_point(*touch.pos):
         touch.ud[self._get_uid('cavoid')] = True
         return
     if self.disabled:
         return True
     if self._touch:
         return super(Carousel, self).on_touch_down(touch)
     Animation.cancel_all(self)
     self._touch = touch
     uid = self._get_uid()
     touch.grab(self)
     touch.ud[uid] = {'mode': 'unknown', 'time': touch.time_start}
     self._change_touch_mode_ev = Clock.schedule_once(
         self._change_touch_mode, self.scroll_timeout / 1000.)
     self.touch_mode_change = False
     return True
예제 #43
0
    def on_visible(self, _instance, value):
        """
        Hide or show the widget, depending on whether `visible` is True
        or False.

        :param _instance: The Hideable instance
        :type _instance: Hideable
        :param value: The new value of `visible`
        :type value: bool
        :return: None
        """

        Animation.cancel_all(self)
        if value:
            self.show()
        else:
            self.hide()
예제 #44
0
 def _animate_outer(self):
     anim = Animation(
         d=0.2,
         t="out_cubic",
         **dict(
             zip(
                 ["_outer_radius", "_target_radius"],
                 [self._outer_radius, self._target_radius],
             )
         ),
     )
     anim.cancel_all(self.widget)
     anim.bind(on_progress=lambda x, y, z: self._draw_canvas())
     anim.bind(on_complete=self._animate_ripple)
     anim.start(self.widget)
     setattr(self.widget, "target_ripple_radius", self._target_radius)
     setattr(self.widget, "target_ripple_alpha", 1)
예제 #45
0
 def on_touch_down(self, touch):
     initial_y = Window.height / 5 - self.height / 2
     initial_x = (Window.width / 2 - self.width / 2)
     y = Window.height / 10 + self.y
     max_y = 2 * Window.height - self.height / 2
     if self.y + y < max_y:
         Animation.cancel_all(self)
         # TO do animation = ... jump!
         animation = Animation(x=initial_x,
                               y=y,
                               duration=0.3,
                               t='out_cubic')
         animation += Animation(x=initial_x,
                                y=initial_y,
                                duration=0.3,
                                t='in_cubic')
         animation.start(self)
예제 #46
0
파일: browsingcard.py 프로젝트: pmtoan/CoAP
    def _start_animation(self, *args):
        Animation.cancel_all(self)
        new_offset = 0
        extent = self.width
        #if self._offset < self.min_move * -extent:
        #    new_offset = -extent
        if self._offset > self.min_move * extent:
            new_offset = extent

        dur = self.anim_move_duration
        if new_offset == 0:
            dur = self.anim_cancel_duration

        anim = Animation(_offset=new_offset, d=dur, t='out_quad')
        if new_offset == extent:
            anim.bind(on_complete=self.controller.close_card)
        anim.start(self)
예제 #47
0
 def button_collision(self):
     font_instance = 57
     buttons = [self.covid_button, self.blm_button]
     for button in buttons:
         if button.collide_point(*Window.mouse_pos):
             animation = Animation(font_size=font_instance + 6,
                                   s=1 / 60,
                                   duration=.06)
             button.color = (.96, .60, .61)
             if button.count == 0:
                 animation.start(button)
                 button.count += 1
         else:
             button.count = 0
             Animation.cancel_all(button)
             button.color = (1, 1, 1, 1)
             button.font_size = font_instance
예제 #48
0
class AKSpinnerCircleFlip(AKSpinnerBase):
    animation = StringProperty('out_back')

    _circle_size = ListProperty([0, 0])

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def _start_animate(self, size):
        size = [size, size]
        self.flip_v_start = Animation(
            _circle_size=[
                size[0],
                size[1]],
            opacity=1,
            duration=self.speed,
            t=self.animation)
        self.flip_v = Animation(_circle_size=[size[0], 0], duration=self.speed, t=self.animation) \
            + Animation(_circle_size=[size[0], size[1]], duration=self.speed, t=self.animation)\
            + Animation(_circle_size=[0, size[1]], duration=self.speed, t=self.animation)\
            + Animation(_circle_size=[size[0], size[1]],
                        duration=self.speed, t=self.animation)

        self.flip_v.repeat = True
        self.flip_v_start.start(self)
        Clock.schedule_once(lambda x: self.flip_v.start(self), self.speed)

    def _stop_animate(self):
        self.flip_v_start.cancel_all(self)
        self.flip_v.cancel_all(self)
        self.flip_v_stop = Animation(
            _circle_size=[
                0,
                0],
            opacity=0,
            duration=0.1,
            t=self.animation)
        self.flip_v_stop.start(self)

    def on_active(self, *args):
        size = self.size[0]
        if self.active:
            self._start_animate(size)
        else:
            self._stop_animate()
예제 #49
0
    def _show(self, pos, duration):
        def on_stop(*l):
            if duration:
                Clock.schedule_once(self.hide, duration + .5)

        self.opacity = 0
        arrow_pos = self.arrow_pos
        if arrow_pos[0] in ('l', 'r'):
            pos = pos[0], pos[1] - (self.height / 2)
        else:
            pos = pos[0] - (self.width / 2), pos[1]

        self.limit_to = Window

        anim = Animation(opacity=1, pos=pos, d=.32)
        anim.bind(on_complete=on_stop)
        anim.cancel_all(self)
        anim.start(self)
예제 #50
0
def shake(animation, block):
    def shake_back_to_origin(animation, block):
        Animation.cancel_all(block)
        block.change_pos = Animation(pos_hint=block.origin_pos_hint, duration=random.choice([0.6, 0.4, 0.2]))
        block.change_pos.bind(on_complete=shake)
        block.change_pos.start(block)

    Animation.cancel_all(block)
    app = App.get_running_app()
    if not app.sm.current_screen.game_status.stage_over \
    and not app.sm.current_screen.game_status.stage_clear:

        shake_change_x = block.pos_hint['center_x'] + random.choice(SHAKE_DIRECTION_SET)
        shake_change_y = block.pos_hint['center_y'] + random.choice(SHAKE_DIRECTION_SET)
        block.change_pos = Animation(pos_hint = {'center_x': shake_change_x,'center_y': shake_change_y}, 
                        duration=random.choice([0.6, 0.4, 0.2]))
        block.change_pos.bind(on_complete=shake_back_to_origin)
        block.change_pos.start(block)
예제 #51
0
    def start_(self, tmp=None):
        props = ["angle", "opacity", "pos_hint"]

        __tmp = {}
        for key, val in self._original["pos_hint"].items():
            if key in ["center_x", "x", "left"]:
                __tmp[key] = 1.2
            else:
                __tmp[key] = val
        vals = [-90, 0, __tmp]
        anim = Animation(
            d=self.duration,
            **dict(zip(props, vals)),
        )

        anim.cancel_all(self.widget)
        anim.start(self.widget)
        anim.bind(on_complete=partial(self.anim_complete, self))
예제 #52
0
    def roll(self):
        roll = random.randrange(1, 7)
        Animation.cancel_all(self)

        anim = Animation(center_y=150,
                         size=[50, 50],
                         duration=random.random() / 2 + 0.5,
                         t="out_bounce")
        if not self.locked:
            size = random.randrange(60, 100)
            self.size = [size, size]
            self.center_y = 150
            Animation.cancel_all(self)
            self.animate_me = True
            anim.start(self)
            self.value = roll

            anim.bind(on_complete=self.stop_animation)
예제 #53
0
class AKLabelLoader(MDLabel):

    bg_rec_opacity = NumericProperty(0)
    fr_rec_opacity = NumericProperty(0)

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.start_anim = None
        Clock.schedule_once(self.on_text)

    def _check_text(self, text):
        if not text:
            return False
        else:
            return True

    def _start_animate(self):
        self.bg_rec_opacity = 1
        self.fr_rec_opacity = 1
        self.start_anim = Animation(
            bg_rec_opacity=1, t="in_quad", duration=0.8) + Animation(
                bg_rec_opacity=0, t="out_quad", duration=0.8)
        self.start_anim.repeat = True
        self.start_anim.start(self)

    def _stop_animate(self):

        if self.start_anim:
            self.start_anim.cancel_all(self)

        if self.bg_rec_opacity != 0 and self.fr_rec_opacity != 0:
            self.stop_anim = Animation(fr_rec_opacity=0,
                                       t="out_quad",
                                       duration=0.3)
            self.stop_anim &= Animation(bg_rec_opacity=0,
                                        t="out_quad",
                                        duration=0.3)
            self.stop_anim.start(self)

    def on_text(self, *args):
        if self._check_text(self.text):
            self._stop_animate()
        else:
            self._start_animate()
예제 #54
0
    def update(self, fromWho, vals):
        if (self.gui.rl.current[:7] != 'Widgets'
                or self.screen != self.gui.rl.current[7:]):
            return 0

        if 0:
            print('''update from widget_n[{}] 
                from:{}  
                gotvals:{}'''.format(self.mtitle, fromWho, vals))

        v = self.wvfh.updateVal(fromWho, vals)
        if v != None:

            vAsInt = True
            try:
                vi = int(v)
            except:
                vAsInt = False

            if vAsInt:
                self.valueToDisplay = round(
                    v, self.mround) if self.mround > 0 else int(v)
            else:
                self.valueToDisplay = v

            if self.smSettings['title'] != '':
                self.sm.label = "{}\n{}".format(self.smSettings['title'],
                                                self.valueToDisplay)
            else:
                self.sm.label = str(self.valueToDisplay)

            if self.valueToDisplay > self.smSettings['max']:
                self.valueToDisplay = self.smSettings['max']
            if self.valueToDisplay < self.smSettings['min']:
                self.valueToDisplay = self.smSettings['min']

            if self.gui.animation:
                Animation.cancel_all(self.sm, 'angle')
                anim = Animation(value=self.valueToDisplay, t='out_quad')
                anim.start(self.sm)

            else:
                self.sm.value = self.valueToDisplay
예제 #55
0
    def cancel_all_animations_on_double_click(self) -> None:
        """
        Cancels the animations of the text field when double-clicking on the
        text field.
        """

        if (
            self._hint_y == dp(38)
            and not self.text
            or self._hint_y == dp(14)
            and self.text
        ):
            Animation.cancel_all(
                self,
                "_underline_width",
                "_hint_y",
                "_hint_x",
                "_hint_text_font_size",
            )
예제 #56
0
 def start_stop_timer(self):
     # Cancel any current animation in progress
     Animation.cancel_all(self)
     # Define the rules for Animation; i.e., (where we are going, where
     # we're coming from)
     self.anim = Animation(
         countdown=0,
         duration=self.countdown,
     )
     # on_release of Start/Pause button, if it's down and there is still
     # time on the clock, then
     if self.ids.start_pause.state == 'down' and self.countdown > 0:
         # Set current cmd value
         self.get_cmd()
         # On completion of the countdown, call method to initiate the
         # shutdown process
         self.anim.bind(on_complete=self.initiate_shutdown)
         # Start the animation
         self.anim.start(self)
예제 #57
0
	def start_(self, tmp=None):
		props=["pos_hint","opacity"]

		__tmp={}
		for key, val in self._original["pos_hint"].items():
			if key in ["center_y", "y", "top"]:
				__tmp[key]= val+0.2
			else: __tmp[key]= val
		vals=[__tmp, 0]
		self._initialize(**dict(zip(props,vals)))
		
		__tmp={}
		for _key, _val in self._original["pos_hint"].items():
			if _key in ["center_y", "y", "top"]:
				__tmp[_key]= _val-0.04
			else: __tmp[_key]= _val

		vals=[__tmp, 1]
		anim= Animation(
			d= self.duration/3,
			**dict(zip(props,vals)),
			)

		__tmp={}
		for key, val in self._original["pos_hint"].items():
			if key in ["center_y", "y", "top"]:
				__tmp[key]= val+0.02
			else: __tmp[key]= val
		vals=[__tmp, 1]

		anim+= Animation(
			d= self.duration/3,
			**dict(zip(props,vals)),
			)

		anim+= Animation(
			d= self.duration/3,
			**self._original,
			)

		anim.cancel_all(self.widget)
		anim.start(self.widget)
		anim.bind(on_complete= partial(self.anim_complete, self))
예제 #58
0
    def on_leave(self, instance):
        """Called when the mouse cursor goes outside the button of stack."""

        if self.state == "open":
            for widget in self.children:
                if isinstance(widget, MDFloatingLabel) and self.hint_animation:
                    Animation.cancel_all(widget)
                    if self.data[instance.icon] == widget.text:
                        Animation(
                            _canvas_width=0,
                            _padding_right=0,
                            d=self.opening_time,
                            t=self.opening_transition,
                        ).start(instance)
                        if self.hint_animation:
                            Animation(
                                opacity=0, d=0.1, t=self.opening_transition
                            ).start(widget)
                        break
예제 #59
0
    def update_progress(self, img):
        N = 5
        #image = skimage.transform.resize(img, (480, 640), preserve_range=True).astype(np.uint8)
        image = cv2.resize(img, (640, 480), interpolation=cv2.INTER_LANCZOS4)
        image = cv2.flip(image, 0)

        anim = Animation(value=self.counter / N, duration=0.5)
        if self.counter < N:
            self.ids.w_info.text = "處理中 %2d%%" % (self.counter * 100 // N)
            print(self.ids.w_info.text)
            self.ids.w_info.font_size = 64
            self.counter += 1
            anim += Animation(value=self.counter / N, duration=6.)
        Animation.cancel_all(self.ids.w_pb)
        anim.start(self.ids.w_pb)
        self.output_texture.blit_buffer(image.tostring(),
                                        colorfmt='bgr',
                                        bufferfmt='ubyte')
        self.canvas.ask_update()
예제 #60
0
파일: car.py 프로젝트: lbovet/funcrash
    def bouge(self):
        new_y = self.road.hauteur_piste * self.current_piste
        angle = 0
        if new_y > self.y:
            angle = 15
        if new_y < self.y:
            angle = -15

        duration = 0.05
        inertie = 1.5 * sqrt(self.width / self.road.hauteur_piste)
        Animation.cancel_all(self)
        anim = Animation(y=new_y, duration=duration)
        anim &= (
            Animation(angle=angle, duration=duration * 1.1, t='in_out_cubic') +
            Animation(angle=-inertie * angle / 6,
                      duration=1.5 * duration * inertie,
                      t='out_circ') +
            Animation(angle=0, duration=2 * duration * inertie, t='out_sine'))
        anim.start(self)