from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import math
import time
def light_dot(x, y):
oled.pixel(x, y, 1)
def draw_line(x1, y1, x2, y2, isRectangle=0):
'''
绘制线段
:param: x1 y1 x2 y2 线段两端
:param: isRetangle 是否为矩形
:return: None
'''
if (x1 == x2):
step = 1
if (y1 > y2):
step *= -1
while (y1 != y2):
light_dot(x1, y1)
y1 = y1 + step
light_dot(x2, y2)
else:
# y = kx+a
k = (y2 - y1) / (x2 - x1)
a = y1 - (k * x1)
step = 1
if (x1 > x2):
step *= -1
while (x1 != x2):
light_dot(x1, round(k * x1 + a))
x1 += step
light_dot(x2, y2)
if not isRectangle:
oled