Guest User

Untitled

a guest
Jan 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. from decimal import Decimal as dec
  2.  
  3. def light_through_glass(panes, iterations):
  4.     rays = [[dec(0)]*(panes+1), [dec(100)]+[dec(0)]*(panes)]
  5.     out = [dec(0)]*2
  6.     percent = 10
  7.     print('0%'),
  8.     for i in range(iterations):
  9.         # Graphic bling-bling
  10.         if float(i)/float(iterations)*100 >= percent:
  11.             print(str(percent)+'%'),
  12.             percent += 10
  13.         newrays = [[dec(0)]*(panes+1),[dec(0)]*(panes+1)]
  14.         for d in (0, 1):
  15.             for n,r in enumerate(rays[d]):
  16.                 if r == 0:
  17.                     continue
  18.                 if n == panes*d:
  19.                     out[d] += r
  20.                 else:
  21.                     newrays[abs(d-1)][n] += r/10
  22.                     newrays[d][n-1+d*2] += r * dec('0.9')
  23.         rays = newrays
  24.     return out
  25.  
  26. if __name__ == '__main__':
  27.     panes = 50
  28.     iterations = 200
  29.     print('panes: {0}, iterations: {1}'.format(panes, iterations))
  30.     data = light_through_glass(panes, iterations)
  31.     print('\nreflect: {0}\nthrough: {1}\nloss: {2}'.format(data[0], data[1],
  32.                                                     100-sum(data)))
Add Comment
Please, Sign In to add comment