Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from decimal import Decimal as dec
- def light_through_glass(panes, iterations):
- rays = [[dec(0)]*(panes+1), [dec(100)]+[dec(0)]*(panes)]
- out = [dec(0)]*2
- percent = 10
- print('0%'),
- for i in range(iterations):
- # Graphic bling-bling
- if float(i)/float(iterations)*100 >= percent:
- print(str(percent)+'%'),
- percent += 10
- newrays = [[dec(0)]*(panes+1),[dec(0)]*(panes+1)]
- for d in (0, 1):
- for n,r in enumerate(rays[d]):
- if r == 0:
- continue
- if n == panes*d:
- out[d] += r
- else:
- newrays[abs(d-1)][n] += r/10
- newrays[d][n-1+d*2] += r * dec('0.9')
- rays = newrays
- return out
- if __name__ == '__main__':
- panes = 50
- iterations = 200
- print('panes: {0}, iterations: {1}'.format(panes, iterations))
- data = light_through_glass(panes, iterations)
- print('\nreflect: {0}\nthrough: {1}\nloss: {2}'.format(data[0], data[1],
- 100-sum(data)))
Add Comment
Please, Sign In to add comment