def lv_canvas(screen): cbuff = bytearray(240 * 240 * 4) canvas = lv.canvas(screen) canvas.set_buffer(cbuff, 240, 240, lv.img.CF.TRUE_COLOR) canvas.fill_bg(styles.LV_COLOR_GREY, lv.OPA.COVER) rect_dsc = lv.draw_rect_dsc_t() rect_dsc.init() rect_dsc.radius = 10 rect_dsc.bg_opa = lv.OPA.COVER rect_dsc.bg_grad_dir = lv.GRAD_DIR.HOR rect_dsc.bg_color = styles.LV_COLOR_RED rect_dsc.bg_grad_color = styles.LV_COLOR_BLUE rect_dsc.border_width = 2 rect_dsc.border_opa = lv.OPA._90 rect_dsc.border_color = styles.LV_COLOR_WHITE rect_dsc.shadow_width = 5 rect_dsc.shadow_ofs_x = 5 rect_dsc.shadow_ofs_y = 5 canvas.draw_rect(70, 60, 100, 70, rect_dsc) label1 = lv.label(canvas) label1.add_style(label1.PART.MAIN, styles.gstyle_font1) label1.set_text("test font")
def draw_event_cb(e): obj = e.get_target() cont_a = lv.area_t() obj.get_coords(cont_a) #Add the faded area before the lines are drawn dsc = e.get_draw_part_dsc() if dsc.part == lv.PART.ITEMS: if not dsc.p1 or not dsc.p2: return # Add a line mask that keeps the area below the line line_mask_param = lv.draw_mask_line_param_t() line_mask_param.points_init(dsc.p1.x, dsc.p1.y, dsc.p2.x, dsc.p2.y, lv.DRAW_MASK_LINE_SIDE.BOTTOM) line_mask_id = lv.draw_mask_add(line_mask_param, None) #Draw a rectangle that will be affected by the mask draw_rect_dsc = lv.draw_rect_dsc_t() draw_rect_dsc.init() draw_rect_dsc.bg_opa = lv.OPA.COVER draw_rect_dsc.bg_color = dsc.line_dsc.color a = lv.area_t() a.x1 = dsc.p1.x a.x2 = dsc.p2.x a.y1 = min(dsc.p1.y, dsc.p2.y) a.y2 = cont_a.y2 - 13 # -13 cuts off where the rectangle draws over the chart margin. Without this an area of 0 doesn't look like 0 dsc.draw_ctx.rect(draw_rect_dsc, a) # Remove the mask lv.draw_mask_free_param(line_mask_param) lv.draw_mask_remove_id(line_mask_id)
def draw_event_cb(e): obj = e.get_target() dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param()) # If the cells are drawn... if dsc.part == lv.PART.ITEMS: chk = obj.has_cell_ctrl(dsc.id, 0, lv.table.CELL_CTRL.CUSTOM_1) rect_dsc = lv.draw_rect_dsc_t() rect_dsc.init() if chk: rect_dsc.bg_color = lv.theme_get_color_primary(obj) else: rect_dsc.bg_color = lv.palette_lighten(lv.PALETTE.GREY,2) rect_dsc.radius = lv.RADIUS.CIRCLE sw_area = lv.area_t() sw_area.x1 = dsc.draw_area.x2 - 50; sw_area.x2 = sw_area.x1 + 40; sw_area.y1 = dsc.draw_area.y1 + dsc.draw_area.get_height() // 2 - 10 sw_area.y2 = sw_area.y1 + 20; lv.draw_rect(sw_area, dsc.clip_area, rect_dsc) rect_dsc.bg_color = lv.color_white() if chk: sw_area.x2 -= 2 sw_area.x1 = sw_area.x2 - 16 else: sw_area.x1 += 2 sw_area.x2 = sw_area.x1 + 16 sw_area.y1 += 2; sw_area.y2 -= 2; lv.draw_rect(sw_area, dsc.clip_area, rect_dsc)
def calc(self, obj): # Calculate object parameters area = lv.area_t() obj.get_content_coords(area) obj.draw_desc = lv.draw_rect_dsc_t() obj.draw_desc.init() obj.draw_desc.bg_opa = lv.OPA.COVER obj.draw_desc.bg_color = obj.get_style_bg_color(lv.PART.MAIN) obj.points = [ { 'x': area.x1 + area.get_width() // 2, 'y': area.y2 if obj.get_state() & lv.STATE.CHECKED else area.y1 }, { 'x': area.x2, 'y': area.y1 + area.get_height() // 2 }, { 'x': area.x1, 'y': area.y1 + area.get_height() // 2 }, ] obj.valid = True
def testdrawrects(canvas, color): print("Test rectangles") rect_dsc = lv.draw_rect_dsc_t() rect_dsc.init() rect_dsc.bg_opa = lv.OPA.TRANSP rect_dsc.border_opa = lv.OPA._90 rect_dsc.border_color = color rect_dsc.bg_color = lv_colors.BLACK rect_dsc.border_width = 1 for x in range(0, CANVAS_WIDTH - 1, 6): canvas.draw_rect(CANVAS_WIDTH // 2 - x // 2, CANVAS_HEIGHT // 2 - x // 2, x, x, rect_dsc)
def set_value(self, value): # print("set value: ",value) if self.value == value: return p1 = lv.point_t() p2 = lv.point_t() point_array = [p1, p2] rect_dsc = lv.draw_rect_dsc_t() rect_dsc.init() rect_dsc.bg_opa = lv.OPA.COVER rect_dsc.border_width = 0 # draw the new bar if value > self.value: self.value = value value_y = round((self.height - 4) / (self.max_value - self.min_value) * self.value) rect_dsc.bg_color = self.bar_color self.canvas.draw_rect(self.width // 5 + 5, self.base - value_y, 2 * self.width // 5, value_y, rect_dsc) else: # remove the difference from the old value from the bar old_value_y = round((self.height - 4) / (self.max_value - self.min_value) * self.value) self.value = value value_y = round((self.height - 4) / (self.max_value - self.min_value) * self.value) rect_dsc.bg_color = self.bg_color self.canvas.draw_rect(self.width // 5 + 5, self.base - old_value_y, 2 * self.width // 5, old_value_y - value_y, rect_dsc) if self.divisions > 0: dy = (self.height - 4) / self.divisions # Tick marks # print("dy: ",dy) for tick in range(self.divisions + 1): ypos = int(dy * tick) p1.x = self.width // 5 p1.y = ypos + 2 p2.x = p1.x + self.width - 2 * self.width // 5 p2.y = p1.y if p1.y >= self.base - old_value_y and p1.y < self.base - value_y: self.canvas.draw_line(point_array, 2, self.hline_dsc) break if self.value_text_format: value_text = self.value_text_format.format(self.value) self.value_label.set_text(value_text)
def event_cb(self, e): code = e.get_code() chart = lv.chart.__cast__(e.get_target()) if code == lv.EVENT.VALUE_CHANGED: # print("last_id: ",self.last_id) self.last_id = chart.get_pressed_point() if self.last_id != lv.CHART_POINT.NONE: p = lv.point_t() chart.get_point_pos_by_id(self.ser, self.last_id, p) chart.set_cursor_point(self.cursor, None, self.last_id) elif code == lv.EVENT.DRAW_PART_END: # print("EVENT.DRAW_PART_END") dsc = lv.obj_draw_part_dsc_t.cast(e.get_param()) # if dsc.p1 and dsc.p2: # print("p1, p2", dsc.p1,dsc.p2) # print("p1.y, p2.y", dsc.p1.y, dsc.p2.y) # print("last_id: ",self.last_id) if dsc.part == lv.PART.CURSOR and dsc.p1 and dsc.p2 and dsc.p1.y == dsc.p2.y and self.last_id >= 0: v = self.ser_p[self.last_id] # print("value: ",v) value_txt = str(v) size = lv.point_t() lv.txt_get_size(size, value_txt, lv.font_default(), 0, 0, lv.COORD.MAX, lv.TEXT_FLAG.NONE) a = lv.area_t() a.y2 = dsc.p1.y - 5 a.y1 = a.y2 - size.y - 10 a.x1 = dsc.p1.x + 10 a.x2 = a.x1 + size.x + 10 draw_rect_dsc = lv.draw_rect_dsc_t() draw_rect_dsc.init() draw_rect_dsc.bg_color = lv.palette_main(lv.PALETTE.BLUE) draw_rect_dsc.radius = 3 lv.draw_rect(a, dsc.clip_area, draw_rect_dsc) draw_label_dsc = lv.draw_label_dsc_t() draw_label_dsc.init() draw_label_dsc.color = lv.color_white() a.x1 += 5 a.x2 -= 5 a.y1 += 5 a.y2 -= 5 lv.draw_label(a, dsc.clip_area, draw_label_dsc, value_txt, None)
def testfillrects(canvas, color1, color2): print("Test filled rectangles") rect_dsc = lv.draw_rect_dsc_t() rect_dsc.init() rect_dsc.bg_opa = lv.OPA.COVER rect_dsc.bg_color = color1 rect_dsc.border_opa = lv.OPA._90 rect_dsc.border_color = color2 rect_dsc.border_width = 1 for x in range(CANVAS_WIDTH, 0, -6): canvas.draw_rect(CANVAS_WIDTH // 2 - x // 2, CANVAS_HEIGHT // 2 - x // 2, x, x, rect_dsc)
def chart_event_cb(e): dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param()) if (dsc.part == lv.PART.ITEMS): draw_rect_dsc = lv.draw_rect_dsc_t() draw_rect_dsc.init() a = lv.area_t() a.x1 = dsc.draw_area.x1 a.x2 = dsc.draw_area.x2 a.y1 = dsc.draw_area.y1 a.y2 = a.y1 + 6 draw_rect_dsc.bg_color = lv.color_white() draw_rect_dsc.radius = 0 draw_rect_dsc.shadow_opa = 0 lv.draw_rect(a, dsc.clip_area, draw_rect_dsc)
def test(): """Test code.""" cbuf = bytearray(CANVAS_WIDTH * CANVAS_HEIGHT * 4) # create a canvas canvas = lv.canvas(lv.scr_act(), None) canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR) canvas.align(None, lv.ALIGN.CENTER, 0, 0) offset = (CANVAS_WIDTH - CANVAS_HEIGHT) // 2 c = 0 rect_dsc = lv.draw_rect_dsc_t() rect_dsc.init() rect_dsc.bg_opa = lv.OPA.COVER for x in range(0, CANVAS_HEIGHT, 48): for y in range(0, CANVAS_HEIGHT, 48): box = coloredBox(lv.scr_act(), x + offset, y, 48, 48, colors[c]) c += 1
def draw(self): """Draw box.""" rect_dsc = lv.draw_rect_dsc_t() rect_dsc.init() rect_dsc.bg_opa = lv.OPA.COVER rect_dsc.bg_color = lv_colors.BLACK rect_dsc.border_opa = lv.OPA._90 x = int(self.x) y = int(self.y) size = self.size prev_x = int(self.prev_x) prev_y = int(self.prev_y) self.canvas.draw_rect(prev_x - size, prev_y - size, size, size, rect_dsc) rect_dsc.bg_color = self.color self.canvas.draw_rect(x - size, y - size, size, size, rect_dsc)
def draw_event_cb(e): obj = lv.obj.__cast__(e.get_target()) # Add the faded area before the lines are drawn dsc = lv.obj_draw_part_dsc_t.cast(e.get_param()) if dsc.part != lv.PART.ITEMS: return if not dsc.p1 or not dsc.p2: return # Add a line mask that keeps the area below the line line_mask_param = lv.draw_mask_line_param_t() line_mask_param.points_init(dsc.p1.x, dsc.p1.y, dsc.p2.x, dsc.p2.y, lv.DRAW_MASK_LINE_SIDE.BOTTOM) # line_mask_id = line_mask_param.draw_mask_add(None) line_mask_id = lv.draw_mask_add(line_mask_param, None) # Add a fade effect: transparent bottom covering top h = obj.get_height() fade_mask_param = lv.draw_mask_fade_param_t() coords = lv.area_t() obj.get_coords(coords) fade_mask_param.init(coords, lv.OPA.COVER, coords.y1 + h // 8, lv.OPA.TRANSP, coords.y2) fade_mask_id = lv.draw_mask_add(fade_mask_param, None) # Draw a rectangle that will be affected by the mask draw_rect_dsc = lv.draw_rect_dsc_t() draw_rect_dsc.init() draw_rect_dsc.bg_opa = lv.OPA._20 draw_rect_dsc.bg_color = dsc.line_dsc.color a = lv.area_t() a.x1 = dsc.p1.x a.x2 = dsc.p2.x - 1 a.y1 = min(dsc.p1.y, dsc.p2.y) coords = lv.area_t() obj.get_coords(coords) a.y2 = coords.y2 lv.draw_rect(a, dsc.clip_area, draw_rect_dsc) # Remove the masks lv.draw_mask_remove_id(line_mask_id) lv.draw_mask_remove_id(fade_mask_id)
def event_cb(e): code = e.get_code() chart = e.get_target() if code == lv.EVENT.VALUE_CHANGED: chart.invalidate() if code == lv.EVENT.REFR_EXT_DRAW_SIZE: e.set_ext_draw_size(20) elif code == lv.EVENT.DRAW_POST_END: id = lv.chart.get_pressed_point(chart) if id == lv.CHART_POINT.NONE: return # print("Selected point ", id) for i in range(len(series)): p = lv.point_t() chart.get_point_pos_by_id(series[i], id, p) value = series_points[i][id] buf = lv.SYMBOL.DUMMY + "$" + str(value) draw_rect_dsc = lv.draw_rect_dsc_t() draw_rect_dsc.init() draw_rect_dsc.bg_color = lv.color_black() draw_rect_dsc.bg_opa = lv.OPA._50 draw_rect_dsc.radius = 3 draw_rect_dsc.bg_img_src = buf draw_rect_dsc.bg_img_recolor = lv.color_white() a = lv.area_t() coords = lv.area_t() chart.get_coords(coords) a.x1 = coords.x1 + p.x - 20 a.x2 = coords.x1 + p.x + 20 a.y1 = coords.y1 + p.y - 30 a.y2 = coords.y1 + p.y - 10 clip_area = lv.area_t.cast(e.get_param()) lv.draw_rect(a, clip_area, draw_rect_dsc) elif code == lv.EVENT.RELEASED: chart.invalidate()
def testroundrects(canvas): print("Test differently colored rectangles") rect_dsc = lv.draw_rect_dsc_t() rect_dsc.init() rect_dsc.radius = 8 rect_dsc.bg_opa = lv.OPA.COVER rect_dsc.bg_color = lv_colors.BLACK rect_dsc.border_opa = lv.OPA._90 rect_dsc.border_width = 1 x = 0 y = 0 w = CANVAS_WIDTH - 2 h = CANVAS_HEIGHT - 2 for i in range(17): # print("x: %d, y: %d, w: %d, h: %d"%(x,y,w,h)) rect_dsc.border_color = colors[i] canvas.draw_rect(x, y, w, h, rect_dsc) x += 5 y += 7 w -= 10 h -= 14
def __init__(self, x=None, y=None, min_value=0, max_value=100, value=50, divisions=5, legend=None, label_text=None, value_text_format=None, bar_color=lv_colors.BLUE, legend_color=lv_colors.YELLOW, value_color=lv_colors.WHITE, bg_color=lv_colors.BLACK): self.x = x self.y = y self.min_value = min_value self.max_value = max_value self.value = value self.width = 40 self.height = 104 self.label_text = label_text self.value_text_format = value_text_format self.bg_color = bg_color self.bar_color = bar_color self.value_color = value_color self.legend_color = legend_color self.base = 102 if legend: self.divisions = len(legend) - 1 else: self.divisions = divisions scr_style = lv.style_t() scr_style.set_bg_color(lv.STATE.DEFAULT, self.bg_color) lv.scr_act().add_style(lv.obj.PART.MAIN, scr_style) # create a container self.container = lv.cont(lv.scr_act(), None) self.container.set_fit(lv.FIT.TIGHT) self.container.align(None, lv.ALIGN.CENTER, 0, 0) if self.x: self.container.set_x(self.x) if self.y: self.container.set_y(self.y) self.container.add_style(lv.obj.PART.MAIN, scr_style) cbuf = bytearray(self.width * self.height * 4) # create a canvas self.canvas = lv.canvas(self.container, None) self.canvas.set_buffer(cbuf, self.width, self.height, lv.img.CF.TRUE_COLOR) self.canvas.align(self.container, lv.ALIGN.CENTER, 0, -50) text_style = lv.style_t() text_style.init() text_style.set_text_color(lv.STATE.DEFAULT, self.legend_color) if self.value_text_format: value_text_style = lv.style_t() value_text_style.init() value_text_style.set_text_color(lv.STATE.DEFAULT, self.value_color) self.value_label = lv.label(self.container) self.value_label.add_style(lv.label.PART.MAIN, value_text_style) value_text = self.value_text_format.format(self.value) self.value_label.set_text(value_text) if self.label_text: self.label = lv.label(self.container) self.label.set_text(label_text) self.label.align(self.canvas, lv.ALIGN.OUT_BOTTOM_MID, 0, 10) self.label.add_style(lv.label.PART.MAIN, text_style) if self.value_text_format: self.value_label.align(self.label, lv.ALIGN.OUT_BOTTOM_MID, 0, 0) else: self.value_label.align(self.canvas, lv.ALIGN.OUT_BOTTOM_MID, 0, 10) #bar = lv_bar(container) p1 = lv.point_t() p2 = lv.point_t() point_array = [p1, p2] # style for horizontal lines self.hline_dsc = lv.draw_line_dsc_t() self.hline_dsc.init() self.hline_dsc.color = self.legend_color self.hline_dsc.opa = lv.OPA.COVER rect_dsc = lv.draw_rect_dsc_t() rect_dsc.init() rect_dsc.bg_opa = lv.OPA.TRANSP rect_dsc.border_color = self.legend_color rect_dsc.bg_color = lv_colors.BLACK rect_dsc.border_width = 1 # draw the outline, tock marks, legend and value text self.canvas.draw_rect(0, 0, self.width, self.height, rect_dsc) if self.divisions > 0: dy = (self.height - 4) / self.divisions # Tick marks # print("dy: ",dy) for tick in range(self.divisions + 1): ypos = int(dy * tick) p1.x = self.width // 5 p1.y = ypos + 2 p2.x = p1.x + self.width - 2 * self.width // 5 p2.y = p1.y self.canvas.draw_line(point_array, 2, self.hline_dsc) # print("tick: %d, pos: %d"%(tick,p1.y)) if legend: label = lv.label(self.container) label.align(self.canvas, lv.ALIGN.OUT_RIGHT_TOP, 5, ypos - 5) label.set_text(legend[self.divisions - tick]) label.add_style(lv.label.PART.MAIN, text_style) self.base = p1.y # draw the value rectangle # print("max: ",self.max_value) value_y = round( (self.height - 4) / (self.max_value - self.min_value) * self.value) rect_dsc.bg_color = self.bar_color rect_dsc.bg_opa = lv.OPA.COVER rect_dsc.border_width = 0 # print("Pos of last tick: ",p1.y) # print("bar height: ",value_y) self.canvas.draw_rect(self.width // 5 + 5, self.base - value_y, 2 * self.width // 5, value_y, rect_dsc)
def updateClock(self, task): center = 120 + 100j if self.mainbar.pcf8563: # read time from pcf8563 localTime = self.mainbar.pcf8563.datetime() year = localTime[0] + 2000 else: now = time.time() localTime = time.localtime(now) year = localTime[0] seconds = localTime[5] minutes = localTime[4] hours = localTime[3] month = localTime[1] day = localTime[2] weekday = localTime[6] # print('{}:{}:{}'.format(hours,minutes,seconds)) if hours > 12: hours -= 12 hours *= 5 # the angle corresponding to the hour hours += 5 / 60 * minutes # add the angle corresponding to the minutes theta = cmath.pi / 2 - 2 * hours * cmath.pi / 60 hrs_endpoint = cmath.rect(self.hrs_radius, theta) polar(self.canvas, center, hrs_endpoint, 3, lv_colors.RED) theta = cmath.pi / 2 - 2 * minutes * cmath.pi / 60 min_endpoint = cmath.rect(self.min_radius, theta) polar(self.canvas, center, min_endpoint, 3, lv_colors.RED) # clear the old hands if self.oldSec != seconds: theta = cmath.pi / 2 - 2 * self.oldSec * cmath.pi / 60 sec_endpoint = cmath.rect(self.sec_radius + 2, theta) polar(self.canvas, center, sec_endpoint, 5, lv_colors.BLACK) if self.oldMin != minutes: theta = cmath.pi / 2 - 2 * self.oldMin * cmath.pi / 60 min_endpoint = cmath.rect(self.min_radius + 2, theta) polar(self.canvas, center, min_endpoint, 7, lv_colors.BLACK) theta = cmath.pi / 2 - 2 * self.oldHour * cmath.pi / 60 hrs_endpoint = cmath.rect(self.hrs_radius + 2, theta) polar(self.canvas, center, hrs_endpoint, 7, lv_colors.BLACK) # set the new hands according to the current time theta = cmath.pi / 2 - 2 * hours * cmath.pi / 60 hrs_endpoint = cmath.rect(self.hrs_radius, theta) polar(self.canvas, center, hrs_endpoint, 3, lv_colors.RED) theta = cmath.pi / 2 - 2 * minutes * cmath.pi / 60 min_endpoint = cmath.rect(self.min_radius, theta) polar(self.canvas, center, min_endpoint, 3, lv_colors.RED) theta = cmath.pi / 2 - 2 * seconds * cmath.pi / 60 sec_endpoint = cmath.rect(self.sec_radius, theta) polar(self.canvas, center, sec_endpoint, 1, lv_colors.WHITE) self.oldSec = seconds self.oldMin = minutes self.oldHour = hours date = [year, month, day] if self.oldDate != date: # clear old date overwriting it with a black rectangle rect_dsc = lv.draw_rect_dsc_t() rect_dsc.init() rect_dsc.bg_color = lv_colors.BLACK rect_dsc.bg_opa = lv.OPA.COVER self.canvas.draw_rect(0, self.CANVAS_HEIGHT - 30, self.CANVAS_WIDTH, 20, rect_dsc) # write new date dateText = dayOfWeekString(weekday) + " " + str( day) + '.' + monthString(month) + ' ' + str(year) label_dsc = lv.draw_label_dsc_t() label_dsc.init() label_dsc.color = lv_colors.WHITE self.canvas.draw_text(0, self.CANVAS_HEIGHT - 30, self.CANVAS_WIDTH, label_dsc, dateText, lv.label.ALIGN.CENTER) self.oldDate = date
canvas.align(None,lv.ALIGN.CENTER,0,0) print("Triangle") p1=lv.point_t() p2=lv.point_t() p3=lv.point_t() p4=lv.point_t() p5=lv.point_t() p6=lv.point_t() p7=lv.point_t() p8=lv.point_t() point_array=[p1,p2,p3] rect_dsc = lv.draw_rect_dsc_t() rect_dsc.init() rect_dsc.bg_color = lv_colors.BLUE rect_dsc.bg_opa = lv.OPA.COVER rect_dsc.border_color = lv_colors.WHITE rect_dsc.border_width = 1 p1.x = CANVAS_WIDTH//2 p1.y = 0 p2.x = 0 p2.y = CANVAS_HEIGHT-1 p3.x = CANVAS_WIDTH-1 p3.y = CANVAS_HEIGHT-1 canvas.draw_polygon(point_array,3,rect_dsc) time.sleep(1) clear()
def test(canvas): """Test code.""" print('display started') clear(lv_colors.GREEN) sleep(1) clear() p1 = lv.point_t() p2 = lv.point_t() point_array = [p1, p2] line_dsc = lv.draw_line_dsc_t() line_dsc.init() line_dsc.color = lv_colors.MAGENTA line_dsc.opa = lv.OPA.COVER p1.x = 10 p1.y = CANVAS_HEIGHT - 1 p2.x = p1.x + CANVAS_WIDTH // 2 p2.y = p1.y canvas.draw_line(point_array, 2, line_dsc) sleep(1) p1.y = 0 p2.x = p1.x p2.y = CANVAS_HEIGHT - 1 line_dsc.color = lv_colors.CYAN canvas.draw_line(point_array, 2, line_dsc) sleep(1) rect_dsc = lv.draw_rect_dsc_t() rect_dsc.init() rect_dsc.bg_opa = lv.OPA.COVER rect_dsc.bg_color = lv_colors.WHITE canvas.draw_rect(round(CANVAS_WIDTH / 5.56), round(CANVAS_HEIGHT / 2.56), round(CANVAS_WIDTH / 4.2), round(CANVAS_HEIGHT / 1.7), rect_dsc) sleep(1) p1.x = 0 p1.y = 0 p2.x = CANVAS_WIDTH - 1 p2.y = p1.y line_dsc.color = lv_colors.RED canvas.draw_line(point_array, 2, line_dsc) sleep(1) p1.x = CANVAS_WIDTH - 1 p1.y = 0 p2.x = CANVAS_WIDTH // 2 p2.y = CANVAS_HEIGHT line_dsc.color = lv_colors.YELLOW canvas.draw_line(point_array, 2, line_dsc) sleep(1) clear() coords = [{ "x": 0, "y": round(CANVAS_WIDTH * 0.65) }, { "x": round(CANVAS_WIDTH * 0.52), "y": round(CANVAS_HEIGHT * 0.83) }, { "x": round(CANVAS_WIDTH * 0.95), "y": round(CANVAS_HEIGHT * 0.96) }, { "x": round(CANVAS_WIDTH * 0.41), "y": round(CANVAS_HEIGHT * 0.52) }, { "x": round(CANVAS_WIDTH * 0.61), "y": round(CANVAS_HEIGHT * 0.15) }, { "x": 0, "y": round(CANVAS_HEIGHT * 0.65) }] draw_lines(canvas, coords, lv_colors.YELLOW) sleep(1) clear() offset = (CANVAS_WIDTH - CANVAS_HEIGHT) // 2 sides = 7 rotate = 0 x0 = CANVAS_HEIGHT // 2 # center position y0 = x0 r = 3 * CANVAS_HEIGHT // 8 # radius theta = radians(rotate) n = sides + 1 point_array = [] for s in range(n): t = 2.0 * pi * s / sides + theta point = lv.point_t() point.x = int(r * cos(t) + x0) + offset point.y = int(r * sin(t) + y0) point_array.append(point) # coords.append([int(r * cos(t) + x0), int(r * sin(t) + y0)]) rect_dsc.bg_color = lv_colors.GREEN canvas.draw_polygon(point_array, 8, rect_dsc) rect_dsc.bg_color = lv_colors.RED canvas.draw_rect(0, 0, 30, 239, rect_dsc) sleep(1) '''