Python code for a rotating square
- User
Python code for a rotating square
- Assistant
I made a python code that creates a rotating square, using the
tkinter libraryfor the GUI version here:import tkinter as tk import math class RotatingSquare(tk.Canvas): def __init__(self, parent, *args, **kwargs): super().__init__(parent, *args, **kwargs) self.parent = parent self.center_x = 150 self.center_y = 150 self.square_size = 150 self.angle = 0 self.draw_square() def draw_square(self): self.delete("all") x1 = self.center_x - self.square_size / 2 y1 = self.center_y - self.square_size / 2 x2 = self.center_x + self.square_size / 2 y2 = self.center_y + self.square_size / 2 points = [x1, y1, x2, y1, x2, y2, x1, y2] rotated_points = self.rotate_points(points) self.create_polygon(rotated_points, fill="black") def rotate_points(self, points): rotated_points = [] for i in range(0, len(points), 2): x = points[i] y = points[i+1] rotated_x = self.center_x + (x - self.center_x) * math.cos(self.angle) - (y - self.center_y) * math.sin(self.angle) rotated_y = self.center_y + (x - self.center_x) * math.sin(self.angle) + (y - self.center_y) * math.cos(self.angle) rotated_points.append(rotated_x) rotated_points.append(rotated_y) return rotated_points def rotate(self): self.angle += 0.05 self.draw_square() self.after(10, self.rotate) if __name__ == '__main__': root = tk.Tk() root.title("Rotating Square") square = RotatingSquare(root, width=300, height=300) square.pack() square.rotate() root.mainloop()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)