Advertisement
Guest User

Rebonds

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