Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. def pool_bounce(pool_x, pool_y, pos_x, pos_y, angle_init, nbr_bounce):
  2.     assert(pool_x >= 0), "The width of the pool (the x size) must be a positive number"
  3.     assert(pool_y >= 0), "The height of the pool (the y size) must be a positive number"
  4.  
  5.     # Drawing the pool (only the edges)
  6.    
  7.     teleport(pool_x/2, 0)
  8.     pencolor("red")
  9.     left(90)
  10.     forward(pool_y/2)
  11.     left(90)
  12.     forward(pool_x)
  13.     left(90)
  14.     forward(pool_y)
  15.     left(90)
  16.     forward(pool_x)
  17.     left(90)
  18.     forward(pool_y/2)
  19.     right(90)
  20.     pencolor("black")
  21.  
  22.     teleport(pos_x, pos_y) # Placing the point at the specified coordinates
  23.     left(angle_init) # Inputting the beginning angle to the turtle
  24.    
  25.  
  26.     forward((pool_x/2)/cos(radians(angle_init)))
  27.     left(180-2*angle_init)
  28.    
  29.     idx = 1
  30.    
  31.     for idx in range (1, nbr_bounce):
  32.  
  33.         v = pos()
  34.         d1 = pool_x/cos(radians(angle_init))
  35.  
  36.         opposed = d1*sin(radians(angle_init))
  37.  
  38.         if(opposed > floor(pool_y/2 - v[1])):
  39.             d = floor(pool_y/2 - v[1])/sin(radians(angle_init))
  40.         else:
  41.             d = d1
  42.         forward(d)
  43.        
  44.         if(heading() > 90.0):
  45.             right(180-2*angle_init)
  46.         else:
  47.             left(180-2*angle_init)
  48.  
  49.  
  50.  
  51. pool_bounce(400, 400, 0, 0, 12, 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement