/ Published in: Python
This class implements a clock for counting down the starting sequence of a sailing race start. There are methods for adjusting the clock before and after it has been started. Could be used with text, graphic or audio interfaces.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
class YachtTimer: running = 0 time_ceil = 0 time_start = None start_from = -300 def seconds(self): if self.running: return(self.start_from + time.clock() - self.time_start) else: return(self.start_from) def reset(self, s): self.running = 0 self.start_from = s def start(self): if not self.running: self.running = 1 self.time_start = time.clock() def adjust(self, sec): if self.running: self.time_start -= sec else: self.start_from += sec def ceil(self): if self.running: skip = self.seconds()%60 if time.clock()-self.time_ceil < 1: skip += 60 self.adjust(-skip) self.time_ceil = time.clock() else: self.start_from -= 60 def floor(self): if self.running: skip = self.seconds()%60 self.adjust(60-skip) else: self.start_from += 60 def round(self): skip = self.seconds()%60 if skip > 30: self.adjust(60-skip) else: self.adjust(-skip)