fork(2) download
  1. import time
  2. import math
  3.  
  4. class Boat:
  5. def __init__(self, pace, spm, var=0.5):
  6. self.pace = pace #average velocity of the boat in m/s
  7. self.sps = spm/60.0 #strokes per second
  8. self.var = var #variation in speed from 0-1
  9. self.totalT = 0 #total time
  10. self.distance = 0 #distance traveled
  11.  
  12. def move(self, deltaT):
  13. self.totalT += deltaT
  14. timeCalc = self.totalT + self.var * math.sin(self.totalT * self.sps * 2.0 * math.pi)
  15. self.distance = self.pace * timeCalc
  16.  
  17. boat1 = Boat(10.0, 20.0, 0.5)
  18. prevDist = 0.0
  19. print "Time\t\tDistance\tDeltaDistance"
  20. for index in range(0,30):
  21. boat1.move(0.1)
  22. print "%.2f\t\t%.2f\t\t%.2f" % (index / 10.0, boat1.distance, boat1.distance - prevDist)
  23. prevDist = boat1.distance
  24. time.sleep(0.1)
  25.  
  26. print "Rowed 3 seconds, distance: %.2f" % (boat1.distance)
Success #stdin #stdout 0.01s 7736KB
stdin
Standard input is empty
stdout
Time		Distance	DeltaDistance
0.00		2.04		2.04
0.10		4.03		1.99
0.20		5.94		1.91
0.30		7.72		1.78
0.40		9.33		1.61
0.50		10.76		1.43
0.60		11.97		1.22
0.70		12.97		1.00
0.80		13.76		0.78
0.90		14.33		0.57
1.00		14.72		0.39
1.10		14.94		0.22
1.20		15.03		0.09
1.30		15.04		0.01
1.40		15.00		-0.04
1.50		14.96		-0.04
1.60		14.97		0.01
1.70		15.06		0.09
1.80		15.28		0.22
1.90		15.67		0.39
2.00		16.24		0.57
2.10		17.03		0.78
2.20		18.03		1.00
2.30		19.24		1.22
2.40		20.67		1.43
2.50		22.28		1.61
2.60		24.06		1.78
2.70		25.97		1.91
2.80		27.96		1.99
2.90		30.00		2.04
Rowed 3 seconds, distance: 30.00