mirror of
https://github.com/sijiyo/projects.git
synced 2025-04-12 03:26:58 +08:00
34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
import random
|
|
|
|
|
|
def __ease_out_expo(x):
|
|
if x == 1:
|
|
return 1
|
|
else:
|
|
return 1 - pow(2, -10 * x)
|
|
def get_track(distance):
|
|
if not isinstance(distance, int) or distance < 0:
|
|
raise ValueError(f"distance类型必须是大于等于0的整数: distance: {distance}, type: {type(distance)}")
|
|
# 初始化轨迹列表
|
|
slide_track = [[random.randint(20, 60), random.randint(10, 40), 0]]
|
|
# 共记录count次滑块位置信息
|
|
count = 30 + int(distance / 2)
|
|
# 初始化滑动时间
|
|
t = random.randint(50, 100)
|
|
# 记录上一次滑动的距离
|
|
_x = 0
|
|
_y = 0
|
|
for i in range(count):
|
|
# 已滑动的横向距离
|
|
x = round(__ease_out_expo(i / count) * distance)
|
|
# 滑动过程消耗的时间
|
|
t = random.randint(10, 20)
|
|
if x == _x:
|
|
continue
|
|
slide_track.append([x - _x, _y, t])
|
|
_x = x
|
|
slide_track.append([0, 0, random.randint(200, 300)])
|
|
return slide_track
|
|
|