Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. import random
  2. import win32api
  3. import time
  4.  
  5. max_x = win32api.GetSystemMetrics(0)
  6. max_y = win32api.GetSystemMetrics(1)
  7.  
  8. def elastic_potential_energy(displacement, spring_constant):
  9. epe = 0.5 * spring_constant * (displacement**2)
  10. return epe
  11.  
  12. def elastic_force(displacement, spring_constant):
  13. return (-spring_constant) * displacement
  14.  
  15. def acceleration(mass, force):
  16. a = force/mass
  17. return a
  18.  
  19. def get_velocity(initial_velocity, acceleration, t):
  20. return initial_velocity + (acceleration * t)
  21.  
  22. def get_displacement(initial_velocity, acceleration, t):
  23. return (initial_velocity * t) + (0.5 * acceleration * (t**2))
  24.  
  25. def spring_cursor(displacement=400, spring_constant=40, mass=10, dt=0.01, dampening_coefficient=2):
  26. init_pos = win32api.GetCursorPos()
  27. cur_displacement = displacement
  28. new_pos_x = init_pos[0] + cur_displacement
  29. new_pos_y = init_pos[1]
  30. win32api.SetCursorPos((new_pos_x, new_pos_y))
  31. current_velocity = 0
  32. # release the springg
  33. while(True):
  34. time.sleep(dt)
  35. # after delta time t=0.001
  36. cur_force = elastic_force(cur_displacement, spring_constant) - (dampening_coefficient*current_velocity)
  37. cur_acceleration = cur_force/mass
  38. initial_velocity = current_velocity
  39. delta_displacement = get_displacement(initial_velocity, cur_acceleration, dt)
  40. cur_displacement += delta_displacement
  41. current_velocity = get_velocity(initial_velocity, cur_acceleration, dt)
  42. new_pos_x = init_pos[0] + cur_displacement
  43. print 'x={}, dd={}, cd = {}, a={}, f={}, v={}'.format(
  44. new_pos_x, delta_displacement, cur_displacement, cur_acceleration, cur_force, current_velocity)
  45. win32api.SetCursorPos((int(new_pos_x), new_pos_y))
  46.  
  47.  
  48. def bounce(cor=0.9):
  49. init_pos = win32api.GetCursorPos()
  50. dt=0.1
  51. current_velocity = 0
  52. cur_displacement = 0
  53. cur_acceleration = 9.8
  54. new_x = init_pos[0]
  55. new_y = init_pos[1]
  56. while( True):
  57. time.sleep(0.01)
  58. initial_velocity = current_velocity
  59. delta_displacement = get_displacement(initial_velocity, cur_acceleration, dt)
  60. cur_displacement += delta_displacement
  61. current_velocity = get_velocity(initial_velocity, cur_acceleration, dt)
  62. new_y = init_pos[1] + cur_displacement
  63.  
  64. if (int(new_y) > max_y): # collision with ground
  65. current_velocity *= -1
  66. current_velocity *= cor
  67. new_y = max_y
  68. if (int(new_y == max_y) and int(current_velocity) == 0):
  69. # new_y = init_pos[1]
  70. return
  71. # current_velocity = -100
  72. # cur_acceleration = 9.8
  73.  
  74. print 'maxy= {}, y={}, v={},dd={},cd={}'.format(max_y, new_y,current_velocity,delta_displacement,cur_displacement)
  75. win32api.SetCursorPos((new_x, int(new_y)))
  76.  
  77.  
  78. def jumpjump():
  79. time.sleep(1)
  80. randx = random.randint(0, max_x)
  81. randy = random.randint(0, max_y)
  82. win32api.SetCursorPos((randx, randy))
  83.  
  84. def dhinchak(effect=1):
  85. # time.sleep(0.1)
  86. while(True):
  87. cur_pos = win32api.GetCursorPos()
  88. new_pos_x, new_pos_y = cur_pos
  89. new_pos_x = cur_pos[0] + random.randint(-effect, effect)
  90. new_pos_y = cur_pos[1] + random.randint(-effect, effect)
  91.  
  92. if new_pos_x >= max_x:
  93. new_pos_x -= effect
  94. if new_pos_x <= 0:
  95. new_pos_x += effect
  96. if new_pos_y >= max_y:
  97. new_pos_y -= effect
  98. if new_pos_y <= 0:
  99. new_pos_y += effect
  100.  
  101. win32api.SetCursorPos((new_pos_x, new_pos_y))
  102.  
  103. def smooth_move(dest, slow=1):
  104. new_pos_x, new_pos_y = win32api.GetCursorPos()
  105. while(new_pos_x != dest[0] or new_pos_y != dest[1]):
  106. if dest[0] > new_pos_x:
  107. new_pos_x += 1
  108. elif dest[0] < new_pos_x:
  109. new_pos_x -= 1
  110. if dest[1] > new_pos_y:
  111. new_pos_y += 1
  112. elif dest[1] < new_pos_y:
  113. new_pos_y -= 1
  114. time.sleep(0.001*slow)
  115. win32api.SetCursorPos((new_pos_x, new_pos_y))
  116.  
  117. def eucladian_dist(pointa, pointb):
  118. import math
  119. return math.sqrt((pointa[0]-pointb[0])**2 + (pointa[1]-pointb[1])**2 )
  120.  
  121. def ilovecorners():
  122. while(True):
  123. time.sleep(1)
  124. cur_pos = win32api.GetCursorPos()
  125. topldiff = int(eucladian_dist(cur_pos, (0,0)))
  126. toprdiff = int(eucladian_dist(cur_pos, (max_x,0)))
  127. botldiff = int(eucladian_dist(cur_pos, (0,max_y)))
  128. botrtdiff = int(eucladian_dist(cur_pos, (max_x,max_y)))
  129.  
  130. lowest_diff = min(topldiff, toprdiff, botldiff, botrtdiff)
  131.  
  132. if lowest_diff == topldiff:
  133. smooth_move((0,0))
  134. elif lowest_diff == toprdiff:
  135. smooth_move((max_x,0))
  136. elif lowest_diff == botldiff:
  137. smooth_move((0,max_y))
  138. elif lowest_diff == botrtdiff:
  139. smooth_move((max_x,max_y))
  140.  
  141. def ilovewalls():
  142. while(True):
  143. time.sleep(1)
  144. cur_pos = win32api.GetCursorPos()
  145. updiff = cur_pos[1]
  146. downdiff = max_y - cur_pos[1]
  147. leftdiff = cur_pos[0]
  148. rightdiff = max_x - cur_pos[0]
  149.  
  150. lowest_diff = min(updiff, downdiff, leftdiff, rightdiff)
  151.  
  152. if lowest_diff == updiff:
  153. smooth_move((cur_pos[0],0))
  154. elif lowest_diff == downdiff:
  155. smooth_move((cur_pos[0], max_y))
  156. elif lowest_diff == leftdiff:
  157. smooth_move((0, cur_pos[1]))
  158. elif lowest_diff == rightdiff:
  159. smooth_move((max_x, cur_pos[1]))
  160.  
  161. def circle_eq_get_y(x, radius, center_x, center_y):
  162. import math
  163. y = math.sqrt( radius**2 - ((x - center_x)**2 ) ) + center_y
  164. return y
  165.  
  166. def merrygoround(radius=max_y/3):
  167. cur_pos = win32api.GetCursorPos()
  168. center_x, center_y = cur_pos
  169. if max_x <= center_x + radius:
  170. center_x -= radius
  171. if 0 >= center_x - radius:
  172. center_x += radius
  173. if 0 >= center_y - radius:
  174. center_y += radius
  175. if max_y <= center_y + radius:
  176. center_y -= radius
  177.  
  178. new_x = center_x
  179. new_y = center_y + radius
  180. rotate = 1
  181.  
  182. while(True):
  183. # time.sleep(1)
  184. print new_x, new_y
  185. smooth_move((new_x, new_y))
  186. if new_y < center_y:
  187. rotate = -1
  188. elif new_y > center_y:
  189. rotate = 1
  190. else:
  191. rotate = rotate * -1
  192. new_x += rotate
  193. new_y = int(circle_eq_get_y(new_x, radius, center_x, center_y))
  194. if rotate < 0:
  195. new_y = (2 * center_y) - new_y
  196.  
  197.  
  198.  
  199.  
  200. # ilovewalls()
  201.  
  202. # ilovecorners()
  203.  
  204. # merrygoround(200)
  205.  
  206. # dhinchak()
  207.  
  208. # spring_cursor(displacement=400, spring_constant=40, mass=10, dt=0.01, dampening_coefficient=2)
  209. # spring_cursor(600, 60, 10, 0.01, 2)
  210.  
  211. bounce(0.7)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement