set pixel endpoint

This commit is contained in:
waltem01 2023-11-23 10:46:15 +01:00
parent a7ae976d67
commit 3bac768b06

View File

@ -27,6 +27,23 @@ def display_text():
return jsonify(response)
@api.route('/pixel', methods=['POST'])
def set_pixel():
response = { 'success': True }
try:
global matrix
data = request.get_json()
x_coord = data.get('x')
y_coord = data.get('y')
matrix.pixel(x_coord, y_coord)
except Exception as e:
print(e)
response['success'] = False
return jsonify(response)
@api.route('/update', methods=['GET'])
def update_matrix():
response = { 'success': True }
@ -63,6 +80,12 @@ class Matrix(SampleBase):
self.canvas = self.matrix.SwapOnVSync(self.canvas)
self.clear()
def set_color(self, r, g, b):
self.color = graphics.Color(r, g, b)
def pixel(self, x, y):
self.canvas.SetPixel(x, y, self.color.red, self.color.green, self.color.blue)
def text(self, x, y, t):
graphics.DrawText(self.canvas, self.font, x*9, (y+1)*18, self.color, t)