diff --git a/API/main.py b/API/main.py index 0008dfc..67126c8 100644 --- a/API/main.py +++ b/API/main.py @@ -62,6 +62,25 @@ def draw_circle(): return jsonify(response) +@api.route('/rectangle', methods=['POST']) +def draw_rectangle(): + response = { 'success': True } + try: + global matrix + + data = request.get_json() + width = data.get('w') + height = data.get('h') + x_coord = data.get('x') + y_coord = data.get('y') + + matrix.rectangle(x_coord, y_coord, width, height) + except Exception as e: + print(e) + response['success'] = False + + return jsonify(response) + @api.route('/color', methods=['POST']) def set_color(): response = { 'success': True } @@ -128,6 +147,11 @@ class Matrix(SampleBase): def circle(self, x, y, r): graphics.DrawCircle(self.canvas, self.font, x, y, r, self.color) + def rectangle(self, x, y, w, h): + for i in range(w): + for j in range(h): + self.canvas.SetPixel(x+i, y+j, self.color.red, self.color.green, self.color.blue) + matrix = None if __name__ == "__main__":