Advertisement
Guest User

ESP32 MicroPython loboris ILI9341 Line Art Demo

a guest
Feb 19th, 2020
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. import display
  2. import random
  3. import utime
  4.  
  5. def draw(c, i):
  6.     global tmpx, tmpy, incx, incy, x1, y1, x2, y2, bc
  7.     tft.line(x1[i], y1[i], x2[i], y2[i], 0)
  8.     tmpx += incx
  9.     if (tmpx < 0 or tmpx > xmax):
  10.         incx = -incx
  11.         tmpx += incx
  12.     tmpy += incy
  13.     if (tmpy < 0 or tmpy > ymax):
  14.         incy = -incy
  15.         tmpy += incy
  16.     x1[i] = x2[i]
  17.     y1[i] = y2[i]
  18.     x2[i] = tmpx
  19.     y2[i] = tmpy
  20.     bc[i] = c
  21.     tft.line(x1[i], y1[i], x2[i], y2[i], bc[i])
  22.  
  23. tft = display.TFT()
  24. tft.init(0, mosi=23, miso=19, clk=18, cs=5, dc=17, rst_pin=16, speed=40000000, bgr=True, rot=1)
  25. tft.set_bg(tft.BLACK)
  26. tft.clear()
  27.  
  28. random.seed(utime.ticks_ms())
  29. LINES = 80
  30. xmax = 320
  31. ymax = 240
  32. x1 = []
  33. y1 = []
  34. x2 = []
  35. y2 = []
  36. bc = []
  37.  
  38. for i in range(LINES):
  39.     x1.append(0)
  40.     y1.append(0)
  41.     x2.append(0)
  42.     y2.append(0)
  43.     bc.append(0)
  44.  
  45. tmpx = random.randint(0, xmax)
  46. tmpy = random.randint(0, ymax)
  47.  
  48. while True:
  49.     c = random.randint(0, 16777215)
  50.     incx = random.randint(0, 13) - 6
  51.     incy = random.randint(0, 13) - 6
  52.     for i in range(LINES):
  53.         draw(c, i)
  54.         utime.sleep(0.02)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement