Return to Snippet

Revision: 13610
at April 29, 2009 07:41 by alx


Initial Code
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)

Initial URL


Initial Description
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.

Initial Title
Start clock class

Initial Tags


Initial Language
Python