Write some Python code that displays an analog clock
- User
Write some Python code that displays an analog clock
Assistant
Here is Python code to display an analog clock:
import math import datetime import matplotlib.pyplot as plt def draw_clock(ax, t): # Draw the clock face ax.set_xlim(-1.2, 1.2) ax.set_ylim(-1.2, 1.2) ax.set_xticks([]) ax.set_yticks([]) # Draw the hour ticks for hour in range(12): angle = math.pi/6 * hour x = math.cos(angle) y = math.sin(angle) ax.plot([0, 0.8*x], [0, 0.8*y], color='black') # Draw the minute ticks for minute in range(60): angle = math.pi/30 * minute x = math.cos(angle) y = math.sin(angle) ax.plot([0, 0.9*x], [0, 0.9*y], color='black') # Draw the hands hour = t.hour % 12 minute = t.minute second = t.second hour_angle = math.pi/6 * hour + (minute/60)*math.pi/6 minute_angle = math.pi/30 * minute + (second/60)*math.pi/30 ax.plot([0, 0.5*math.cos(hour_angle)], [0, 0.5*math.sin(hour_angle)], linewidth=3, color='red') ax.plot([0, 0.8*math.cos(minute_angle)], [0, 0.8*math.sin(minute_angle)], linewidth=2, color='blue') ax.plot([0, math.cos(math.pi/30 * second)], [0, math.sin(math.pi/30 * second)], linewidth=1, color='green') t = datetime.datetime.now() fig, ax = plt.subplots() draw_clock(ax, t) plt.show()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.