mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-12-25 11:31:46 +00:00
implement draw line endpoint and method
This commit is contained in:
parent
8eded89afa
commit
be55d35f67
31
API/main.py
31
API/main.py
@ -170,6 +170,33 @@ def draw_rectangle():
|
|||||||
# respond to client
|
# respond to client
|
||||||
return jsonify(response)
|
return jsonify(response)
|
||||||
|
|
||||||
|
@api.route('/line', methods=['POST'])
|
||||||
|
@cross_origin()
|
||||||
|
def draw_line():
|
||||||
|
# prepare response data
|
||||||
|
response = { 'success': True }
|
||||||
|
try:
|
||||||
|
global matrix
|
||||||
|
assert matrix is not None
|
||||||
|
|
||||||
|
# receive client data
|
||||||
|
data = request.form
|
||||||
|
# try unpacking x,y coordinates
|
||||||
|
x1 = int(data.get('x1'))
|
||||||
|
y1 = int(data.get('y1'))
|
||||||
|
x2 = int(data.get('x2'))
|
||||||
|
y2 = int(data.get('y2'))
|
||||||
|
|
||||||
|
# call matrix method with data
|
||||||
|
matrix.line(x1, y1, x2, y2)
|
||||||
|
except Exception as e:
|
||||||
|
# error handling
|
||||||
|
print(e)
|
||||||
|
response['success'] = False
|
||||||
|
|
||||||
|
# respond to client
|
||||||
|
return jsonify(response)
|
||||||
|
|
||||||
@api.route('/color', methods=['POST'])
|
@api.route('/color', methods=['POST'])
|
||||||
@cross_origin()
|
@cross_origin()
|
||||||
def set_color():
|
def set_color():
|
||||||
@ -289,6 +316,10 @@ class Matrix(SampleBase):
|
|||||||
# set next pixel in rectangle
|
# set next pixel in rectangle
|
||||||
self.canvas.SetPixel(x+i, y+j, self.color.red, self.color.green, self.color.blue)
|
self.canvas.SetPixel(x+i, y+j, self.color.red, self.color.green, self.color.blue)
|
||||||
|
|
||||||
|
# display line from (x1,y1) to (x2,y2) in current color
|
||||||
|
def line(self, x1: int, y1: int, x2: int, y2: int):
|
||||||
|
graphics.DrawLine(self.canvas, x1, y1, x2, y2, self.color)
|
||||||
|
|
||||||
# set current image
|
# set current image
|
||||||
def set_image(self, url: str):
|
def set_image(self, url: str):
|
||||||
_, data = url.split(',')
|
_, data = url.split(',')
|
||||||
|
Loading…
Reference in New Issue
Block a user