コード例 #1
0
def test_get_minutes():
    function_result_1 = a1.get_minutes(3800)
    function_result_2 = a1.get_minutes(4000)
    function_result_3 = a1.get_minutes(42000)
    assert type(function_result_1) is int
    assert function_result_1 == 3
    assert function_result_2 == 6
    assert function_result_3 == 40
コード例 #2
0
ファイル: TestA1.py プロジェクト: psmith/LearnToProgramPython
 def test_get_minuts(self):
     self.assertEqual(a1.get_minutes(0), 0)
     self.assertEqual(a1.get_minutes(63), 1)
     self.assertEqual(a1.get_minutes(59), 0)
     self.assertEqual(a1.get_minutes(61), 1)
     self.assertEqual(3, a1.get_minutes(237));
     self.assertEqual(3, a1.get_minutes(3800));
     self.assertEqual(1, a1.get_minutes(3660));
コード例 #3
0
    def refresh(self, forced=False):
        '''Redraw the clock. If forced is True, display it now. If forced is
        False, register a redraw for later.'''

        self.now = self.now + self.interval / 1000 * self.time_scale
        self.canvas.delete(tkinter.ALL)

        # Draw the clock rim.
        self.canvas.create_oval(10,
                                10,
                                self.width - 10,
                                self.height - 10,
                                width=2,
                                fill="#334455")

        # Draw the tick marks around the clock.
        for i in range(0, 12):
            angle = math.radians(i / 12 * 360)
            outer_length = 90
            inner_length = 80
            self.canvas.create_line(
                math.cos(angle) * inner_length + self.width / 2,
                math.sin(angle) * inner_length + self.width / 2,
                math.cos(angle) * outer_length + self.width / 2,
                math.sin(angle) * outer_length + self.width / 2,
                fill='white',
                width=3)

        # Draw a light or dark face depending on whether it's before noon or
        # after.
        utc_hour = (self.now / 60 / 60) % 24
        hour = int(a1.time_from_utc(utc_hour, self.diff))
        self.canvas.create_oval(15,
                                15,
                                self.width - 15,
                                self.height - 15,
                                width=2,
                                fill="#e0e8ff" if hour < 12 else "#334")

        hands_colour = "black" if hour < 12 else "white"

        # Draw the hour hand.
        hours_angle = (hour % 12) / 12 * 360
        self._draw_hand(hours_angle,
                        30,
                        arrow=tkinter.FIRST,
                        arrowshape=(50, 2, 2),
                        fill=hands_colour)
        self._draw_hand(hours_angle + 180, 5, fill=hands_colour)

        # Draw the minute hand.
        minutes_angle = a1.get_minutes(int(self.now)) / 60 * 360
        if a1.time_from_utc(0, self.diff) % 1 == 0.5:
            minutes_angle += 180
        elif a1.time_from_utc(0, self.diff) % 1 == 0.75:
            minutes_angle += 270
        self._draw_hand(minutes_angle,
                        30,
                        arrow=tkinter.FIRST,
                        arrowshape=(80, 2, 2),
                        fill=hands_colour)
        self._draw_hand(minutes_angle + 180, 5, fill=hands_colour)

        # Draw the second hand.
        seconds_angle = int(a1.get_seconds(int(self.now))) / 60 * 360
        self._draw_hand(seconds_angle,
                        70,
                        fill='red',
                        width=2,
                        arrow=tkinter.FIRST,
                        arrowshape=(70, 9, 2))
        self._draw_hand(seconds_angle + 180,
                        18,
                        fill='red',
                        arrow=tkinter.LAST,
                        arrowshape=(8, 5, 5),
                        width=2)
        self._draw_hand(seconds_angle + 180, 20, fill='red')

        # Draw the four larger tick marks at noon, 3, 6, and 9.
        for i in range(0, 12, 3):
            angle = math.radians(i / 12 * 360)
            outer_length = 90
            inner_length = 70
            self.canvas.create_line(
                math.cos(angle) * inner_length + self.width / 2,
                math.sin(angle) * inner_length + self.width / 2,
                math.cos(angle) * outer_length + self.width / 2,
                math.sin(angle) * outer_length + self.width / 2,
                width=5)

        if not forced:
            self.canvas.after(self.interval, self.refresh)
コード例 #4
0
ファイル: a1_gui.py プロジェクト: CaglarGonul/PythonBasics
    def refresh(self, forced=False):
        '''Redraw the clock. If forced is True, display it now. If forced is
        False, register a redraw for later.'''

        self.now = self.now + self.interval / 1000 * self.time_scale
        self.canvas.delete(tkinter.ALL)

        # Draw the clock rim.
        self.canvas.create_oval(10, 10, self.width - 10,
            self.height - 10, width=2, fill="#334455")

        # Draw the tick marks around the clock.
        for i in range(0, 12):
            angle = math.radians(i / 12 * 360)
            outer_length = 90
            inner_length = 80
            self.canvas.create_line(
                math.cos(angle) * inner_length + self.width / 2,
                math.sin(angle) * inner_length + self.width / 2,
                math.cos(angle) * outer_length + self.width / 2,
                math.sin(angle) * outer_length + self.width / 2,
                fill='white', width=3
            )

        # Draw a light or dark face depending on whether it's before noon or
        # after.
        utc_hour = (self.now / 60 / 60) % 24
        hour = int(a1.time_from_utc(utc_hour, self.diff))
        self.canvas.create_oval(15, 15, self.width - 15, self.height - 15,
            width=2, fill="#e0e8ff" if hour < 12 else "#334")

        hands_colour = "black" if hour < 12 else "white"
        
        # Draw the hour hand.
        hours_angle = (hour % 12) / 12 * 360
        self._draw_hand(hours_angle, 30, arrow=tkinter.FIRST,
            arrowshape=(50, 2, 2), fill=hands_colour)
        self._draw_hand(hours_angle + 180, 5, fill=hands_colour)

        # Draw the minute hand.
        minutes_angle = a1.get_minutes(int(self.now)) / 60 * 360
        if a1.time_from_utc(0, self.diff) % 1 == 0.5:
            minutes_angle += 180
        elif a1.time_from_utc(0, self.diff) % 1 == 0.75:
            minutes_angle += 270
        self._draw_hand(minutes_angle, 30, arrow=tkinter.FIRST, arrowshape=(80, 2, 2), fill=hands_colour)
        self._draw_hand(minutes_angle + 180, 5, fill=hands_colour)

        # Draw the second hand.
        seconds_angle = int(a1.get_seconds(int(self.now))) / 60 * 360
        self._draw_hand(seconds_angle, 70, fill='red', width=2, arrow=tkinter.FIRST, arrowshape=(70, 9, 2))
        self._draw_hand(seconds_angle + 180, 18, fill='red', arrow=tkinter.LAST, arrowshape=(8, 5, 5), width=2)
        self._draw_hand(seconds_angle + 180, 20, fill='red')
        
        # Draw the four larger tick marks at noon, 3, 6, and 9.
        for i in range(0, 12, 3):
            angle = math.radians(i / 12 * 360)
            outer_length = 90
            inner_length = 70
            self.canvas.create_line(
                math.cos(angle) * inner_length + self.width / 2,
                math.sin(angle) * inner_length + self.width / 2,
                math.cos(angle) * outer_length + self.width / 2,
                math.sin(angle) * outer_length + self.width / 2,
                width = 5
           )

        if not forced:
            self.canvas.after(self.interval, self.refresh)
コード例 #5
0
ファイル: assignment1.py プロジェクト: TheMonk9/assignment1
import a1

print(a1.seconds_difference(1800.0, 3600.0))
print(a1.seconds_difference(3600.0, 1800.0))
print(a1.seconds_difference(1800.0, 2160.0))
print(a1.seconds_difference(1800.0, 1800.0))

print(a1.hours_difference(1800.0, 3600.0))
print(a1.hours_difference(3600.0, 1800.0))
print(a1.hours_difference(1800.0, 2160.0))
print(a1.hours_difference(1800.0, 1800.0))

print(a1.to_float_hours(0, 15, 0))
print(a1.to_float_hours(2, 45, 9))
print(a1.to_float_hours(1, 0, 36))

print(a1.get_hours(3800))
print(a1.get_minutes(3800))
print(a1.get_seconds(3800))

print(a1.time_to_utc(+0.5, 12.0))
print(a1.time_to_utc(+1, 12.0))
print(a1.time_to_utc(-1, 12.0))
print(a1.time_to_utc(-11, 18.0))
print(a1.time_to_utc(-1, 0.0))
print(a1.time_to_utc(-1, 23.0))
# ^ last test in time_to_utc