[{"x":0,"y":0,"type":"down","t":2687},{"x":5,"y":0,"type":"move","t":2756},{"x":11,"y":-1,"type":"move","t":2764},{"x":17,"y":-1,"type":"move","t":2773},{"x":24,"y":-2,"type":"move","t":2782},{"x":32,"y":-2,"type":"move","t":2789},{"x":39,"y":-2,"type":"move","t":2797},{"x":43,"y":-3,"type":"move","t":2805},{"x":49,"y":-4,"type":"move","t":2812},{"x":55,"y":-5,"type":"move","t":2821},{"x":59,"y":-5,"type":"move","t":2829},{"x":64,"y":-6,"type":"move","t":2836},{"x":68,"y":-6,"type":"move","t":2845},{"x":73,"y":-6,"type":"move","t":2852},{"x":75,"y":-6,"type":"move","t":2863},{"x":77,"y":-6,"type":"move","t":2868},{"x":79,"y":-6,"type":"move","t":2877},{"x":81,"y":-6,"type":"move","t":2885},{"x":82,"y":-6,"type":"move","t":2893},{"x":84,"y":-7,"type":"move","t":2900},{"x":86,"y":-7,"type":"move","t":2916},{"x":87,"y":-7,"type":"move","t":2933},{"x":88,"y":-7,"type":"move","t":2948},{"x":89,"y":-7,"type":"move","t":2965},{"x":90,"y":-7,"type":"move","t":2988},{"x":91,"y":-7,"type":"move","t":3005},{"x":92,"y":-8,"type":"move","t":3021},{"x":93,"y":-8,"type":"move","t":3036},{"x":93,"y":-8,"type":"move","t":3131},{"x":93,"y":-8,"type":"move","t":3146},{"x":93,"y":-8,"type":"up","t":3420}]
这个是样例, 根据这个样例用python生成随机轨迹, 入参是最后的x
import random # 生成随机轨迹 def generate_random_track(last_x): track = [] x = 0 y = 0 # 随机生成移动步数 move_steps = random.randint(20, 30) # 计算每步的移动距离 move_distance = (last_x - x) / move_steps # 生成随机移动轨迹 for i in range(move_steps): x += move_distance y += random.randint(-1, 1) t = random.randint(500, 1000) track.append({"x": int(x), "y": y, "type": "move", "t": t}) # 添加按下和释放动作 track.insert(0, {"x": 0, "y": 0, "type": "down", "t": 1000}) track.append({"x": int(last_x), "y": y, "type": "move", "t": random.randint(500, 1000)}) track.append({"x": int(last_x), "y": y, "type": "up", "t": random.randint(1000, 1500)}) return track # 测试生成随机轨迹 last_x = 100 # 最后的x参数 random_track = generate_random_track(last_x) # 打印生成的随机轨迹 for entry in random_track: print(entry)
标签:random,last,track,move,轨迹,简单,type From: https://www.cnblogs.com/angdh/p/17547203.html