mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-11-14 00:43:50 +00:00
draw rectangle endpoint
This commit is contained in:
parent
909107766d
commit
d715b0a01b
24
API/main.py
24
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__":
|
||||
|
Loading…
Reference in New Issue
Block a user