高级农民
- 积分
- 1256
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2018-12-20
- 最后登录
- 1970-1-1
|
answer from chatgpt- import sys
- class ASCIIPrinter:
- def __init__(self):
- # Initialize the canvas with spaces
- self.canvas = [[' ' for _ in range(10)] for _ in range(6)]
- # Initialize the list of rectangles
- self.rectangles = []
-
- def draw_rectangle(self, fill_character, left_x, top_y, right_x, bottom_y):
- # Add the rectangle to the list of rectangles
- self.rectangles.append((fill_character, left_x, top_y, right_x, bottom_y))
- # Draw the rectangle on the canvas
- for i in range(top_y, bottom_y + 1):
- for j in range(left_x, right_x + 1):
- self.canvas[i][j] = fill_character
-
- def drag_and_drop(self, select_x, select_y, release_x, release_y):
- # Find the rectangle at the select coordinate
- for i, rect in enumerate(self.rectangles):
- if select_x >= rect[1] and select_x <= rect[3] and select_y >= rect[2] and select_y <= rect[4]:
- # Remove the rectangle from the list of rectangles
- rect = self.rectangles.pop(i)
- # Erase the rectangle from the canvas
- for i in range(rect[2], rect[4] + 1):
- for j in range(rect[1], rect[3] + 1):
- self.canvas[i][j] = ' '
- # Calculate the new left_x, top_y, right_x, and bottom_y of the rectangle
- left_x = min(select_x, release_x)
- top_y = min(select_y, release_y)
- right_x = max(select_x, release_x)
- bottom_y = max(select_y, release_y)
- # Add the rectangle to the list of rectangles
- self.rectangles.append((rect[0], left_x, top_y, right_x, bottom_y))
- # Draw the rectangle on the canvas
- for i
复制代码 |
|