Skip to content
Snippets Groups Projects
Commit aaffd4bc authored by iggy's avatar iggy Committed by q3k
Browse files

py: st4m: inertia scroll wip

parent 4f981d3c
No related branches found
No related tags found
1 merge request!35py: grand st3m unification
......@@ -124,7 +124,7 @@ class FlowerMenu(MenuController):
item.rotation_time = 10000
current = self._scroll_controller.current_position()
current_int = round(current) % len(self._items)
print("current", current, current_int)
# print("current", current, current_int)
self.ui.items_ring[current_int].highlighted = True
self.ui.items_ring[current_int].rotation_time = 3000
self.ui.angle_offset = math.pi - (tau * current / len(self.ui.items_ring))
......
......@@ -131,7 +131,7 @@ class ScrollController(st4m.Responder):
diff = d
# diff =
# print(diff)
max_velocity = 500
max_velocity = 0.2
velocity = self._velocity
if abs(velocity) < 1:
......@@ -189,16 +189,29 @@ class GestureScrollController(ScrollController):
dphi = self._petal._input._dphi
phase = self._petal._input.phase()
self._speedbuffer.append(self._velocity)
if len(self._speedbuffer) > 10:
if self._velocity == 30:
print("here")
# raise ValueError
self._speedbuffer = [1]
self._current_position += 0.3
elif self._velocity == -30:
self._speedbuffer = [-1]
self._current_position -= 0.3
else:
self._speedbuffer.append(self._velocity)
# print(self._speedbuffer)
while len(self._speedbuffer) > 5:
self._speedbuffer.pop(0)
speed = sum(self._speedbuffer) / len(self._speedbuffer)
speed = min(speed, 0.008)
speed = max(speed, -0.008)
if phase == self._petal._input.ENDED:
self._speedbuffer = [0 if abs(speed) < 0.001 else speed]
self._speedbuffer = [0 if abs(speed) < 0.005 else speed]
elif phase == self._petal._input.UP:
# pass
self._speedbuffer.append(speed * 0.85)
pass
# self._speedbuffer.append(speed * 0.85)
elif phase == self._petal._input.BEGIN:
self._ignore = 5
self._speedbuffer = [0.0]
......@@ -212,7 +225,7 @@ class GestureScrollController(ScrollController):
# self._target_position += 1
self._speedbuffer.append(impulse)
if abs(speed) < 0.000001:
if abs(speed) < 0.0001:
speed = 0
self._velocity = speed
......@@ -221,23 +234,59 @@ class GestureScrollController(ScrollController):
self._current_position + self._velocity * delta_ms
) % self._nitems
if phase != self._petal._input.UP:
return
microstep = round(self._current_position) - self._current_position
print("micro:", microstep)
print("v", self._velocity)
# print("micro:", microstep)
# print("v", self._velocity)
# print("pos", self._current_position)
if (
abs(microstep) < 0.1
and abs(self._velocity) < 0.001
# and abs(self._velocity)
):
self._velocity = 0
# self._speedbuffer = []
self._speedbuffer.append(0)
self._current_position = round(self._current_position)
# print("LOCK")
return
# if abs(self._velocity) <= 0.0001:
# self._velocity = 0
if abs(self._velocity) > 0.001:
# self._velocity *= 0.7
self._speedbuffer.append(-self._velocity)
# print("BREAKING")
return
if self._velocity >= 0 and microstep > 0:
self._velocity -= microstep / 100
print("1")
elif self._velocity <= 0 and microstep > 0:
self._velocity += microstep / 100
print("2")
elif self._velocity >= 0 and microstep < 0:
self._velocity -= microstep / 50
print("3")
# self._velocity += microstep / 5
# self._speedbuffer.append(microstep / 10)
self._speedbuffer.append(max(self._velocity, 0.01) * microstep * 10)
# print("1")
elif self._velocity < 0 and microstep > 0:
# self._velocity += microstep / 100
# self._speedbuffer.append(microstep / 5)
self._speedbuffer.append(-self._velocity)
# print("2")
elif self._velocity > 0 and microstep < 0:
# self._speedbuffer.append(microstep / 5)
self._speedbuffer.append(-self._velocity * 0.5)
# self._velocity = max(self._velocity + microstep, 0)
# if self._velocity == 0:
# self._speedbuffer = []
# print("3")
elif self._velocity <= 0 and microstep < 0:
self._velocity += microstep / 50
print("4")
# self._velocity += microstep / 20
# self._speedbuffer.append(microstep / 10)
self._speedbuffer.append(min(self._velocity, -0.01) * abs(microstep) * 10)
# print("4")
# self._speedbuffer.append(self._velocity)
# if self._velocity > 0:
# self._velocity -= microstep / 100
# else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment