pyb.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # pyboard testing functions for CPython
  2. import time
  3. def delay(n):
  4. #time.sleep(float(n) / 1000)
  5. pass
  6. rand_seed = 1
  7. def rng():
  8. global rand_seed
  9. # for these choice of numbers, see P L'Ecuyer, "Tables of linear congruential generators of different sizes and good lattice structure"
  10. rand_seed = (rand_seed * 653276) % 8388593
  11. return rand_seed
  12. # LCD testing object for PC
  13. # uses double buffering
  14. class LCD:
  15. def __init__(self, port):
  16. self.width = 128
  17. self.height = 32
  18. self.buf1 = [[0 for x in range(self.width)] for y in range(self.height)]
  19. self.buf2 = [[0 for x in range(self.width)] for y in range(self.height)]
  20. def light(self, value):
  21. pass
  22. def fill(self, value):
  23. for y in range(self.height):
  24. for x in range(self.width):
  25. self.buf1[y][x] = self.buf2[y][x] = value
  26. def show(self):
  27. print('') # blank line to separate frames
  28. for y in range(self.height):
  29. for x in range(self.width):
  30. self.buf1[y][x] = self.buf2[y][x]
  31. for y in range(self.height):
  32. row = ''.join(['*' if self.buf1[y][x] else ' ' for x in range(self.width)])
  33. print(row)
  34. def get(self, x, y):
  35. if 0 <= x < self.width and 0 <= y < self.height:
  36. return self.buf1[y][x]
  37. else:
  38. return 0
  39. def pixel(self, x, y, value):
  40. if 0 <= x < self.width and 0 <= y < self.height:
  41. self.buf2[y][x] = value