draw rectangle endpoint

This commit is contained in:
waltem01 2023-11-23 10:48:19 +01:00
parent 909107766d
commit d715b0a01b

View File

@ -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__":