fork(1) 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*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		5.76		5.76
0.10		-0.94		-6.69
0.20		0.06		1.00
0.30		8.76		8.69
0.40		5.00		-3.76
0.50		1.24		-3.76
0.60		9.94		8.69
0.70		10.94		1.00
0.80		4.24		-6.69
0.90		10.00		5.76
1.00		15.76		5.76
1.10		9.06		-6.69
1.20		10.06		1.00
1.30		18.76		8.69
1.40		15.00		-3.76
1.50		11.24		-3.76
1.60		19.94		8.69
1.70		20.94		1.00
1.80		14.24		-6.69
1.90		20.00		5.76
2.00		25.76		5.76
2.10		19.06		-6.69
2.20		20.06		1.00
2.30		28.76		8.69
2.40		25.00		-3.76
2.50		21.24		-3.76
2.60		29.94		8.69
2.70		30.94		1.00
2.80		24.24		-6.69
2.90		30.00		5.76
Rowed 3 seconds, distance: 30.00