Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.13 KB | None | 0 0
  1. # Copyright (c) 2014 Adafruit Industries
  2. # Author: Tony DiCola
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. from PIL import Image
  22. from PIL import ImageDraw
  23. from PIL import ImageFont
  24.  
  25. import time
  26.  
  27. import ST7735
  28.  
  29. Tetsel = 0
  30.  
  31. def rr(point):
  32. return(point[1], -point[0])
  33.  
  34. def rl(point):
  35. return (-point[1], point[0])
  36.  
  37. def trans (point, move):
  38. return (point[0]+move[0], point[1]+move[1])
  39.  
  40. def flip (fliped):
  41. return (-fliped[0], -fliped[1])
  42.  
  43. class Tetris:
  44. def __init__(self, ax, ay, bx, by, cx, cy, dx, dy):
  45. self.bax = (ax, ay)
  46. self.bbx = (bx, by)
  47. self.bcx = (cx, cy)
  48. self.bdx = (dx, dy)
  49.  
  50. def println(self):
  51. print(self.bax, self.bbx, self.bcx, self.bdx)
  52.  
  53. def drawrec(self, imagy):
  54. imagy.rectangle((self.bax[0], self.bax[1] ,10+self.bax[0], 10+self.bax[1]), outline=(255,255,0), fill=(255,0,255))
  55. imagy.rectangle((self.bbx[0], self.bbx[1] ,10+self.bbx[0], 10+self.bbx[1]), outline=(255,255,0), fill=(255,0,255))
  56. imagy.rectangle((self.bcx[0], self.bcx[1] ,10+self.bcx[0], 10+self.bcx[1]), outline=(255,255,0), fill=(255,0,255))
  57. imagy.rectangle((self.bdx[0], self.bdx[1] ,10+self.bdx[0], 10+self.bdx[1]), outline=(255,255,0), fill=(255,0,255))
  58.  
  59.  
  60. def moves(self, point):
  61. self.bax = trans(self.bax,point)
  62. self.bbx = trans(self.bbx,point)
  63. self.bcx = trans(self.bcx,point)
  64. self.bdx = trans(self.bdx,point)
  65.  
  66. def rotateL(self):
  67.  
  68. temp = self.bbx
  69.  
  70. self.moves(flip(self.bbx))
  71.  
  72. self.bax = rl(self.bax)
  73. self.bcx = rl(self.bcx)
  74. self.bdx = rl(self.bdx)
  75.  
  76. self.moves(temp)
  77.  
  78. def getO(x, y):
  79. return Tetris(x, y, x+10, y+0, x+0, y+10, x+10, y+10)
  80.  
  81. def getI(x, y):
  82. return Tetris(x-10, y+0, x, y, x+10, y+0, x+20, y+0)
  83.  
  84. def getS(x, y):
  85. return Tetris(x+0, y-10, x, y, x+10, y-10, x-10, y)
  86.  
  87. def getZ(x, y):
  88. return Tetris(x-10, y+0, x, y, x+0, y+10, x+10, y+10)
  89.  
  90. def getL(x, y):
  91. return Tetris(x+10, y+0, x, y, x+0, y-10, x+0, y-20)
  92.  
  93. def getJ(x, y):
  94. return Tetris(x-10, y+0, x, y, x+0, y-10, x+0, y-20)
  95.  
  96. def getT(x, y):
  97. return Tetris(x+10, y+0, x, y, x+0, y+10, x-10, y+0)
  98.  
  99. print("""
  100. shapes.py - Display test shapes on the LCD using PIL.
  101.  
  102. If you're using Breakout Garden, plug the 0.96" LCD (SPI)
  103. breakout into the rear slot.
  104.  
  105. """)
  106.  
  107. # Create ST7735 LCD display class.
  108. disp = ST7735.ST7735(
  109. port=0,
  110. cs=0, # BG_SPI_CSB_BACK or BG_SPI_CS_FRONT
  111. dc=24,
  112. rst=25,
  113. invert=False,
  114. spi_speed_hz=4000000
  115. )
  116.  
  117. # Initialize display.
  118. disp.begin()
  119.  
  120. WIDTH = disp.width
  121. HEIGHT = disp.height
  122.  
  123.  
  124. # Clear the display to a red background.
  125. # Can pass any tuple of red, green, blue values (from 0 to 255 each).
  126. # Get a PIL Draw object to start drawing on the display buffer.
  127. img = Image.new('RGB', (WIDTH, HEIGHT), color=(255, 0, 0))
  128.  
  129. draw = ImageDraw.Draw(img)
  130.  
  131.  
  132. # Draw a purple rectangle with yellow outline.
  133. y = 0
  134. while True:
  135. draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
  136.  
  137. Buttonimp = input("what is your imput:")
  138.  
  139. if(Buttonimp == "a"):
  140. Tetsel = Tetsel - 1
  141.  
  142. if(Buttonimp == "d"):
  143. Tetsel = Tetsel + 1
  144.  
  145. if(Tetsel > 6):
  146. Tetsel = 0
  147.  
  148. if(Tetsel < 0):
  149. Tetsel = 6
  150.  
  151. if(Tetsel == 0 ):
  152. tetras = getI(40, 40)
  153.  
  154. if(Tetsel == 1 ):
  155. tetras = getS(40, 40)
  156.  
  157. if(Tetsel == 2 ):
  158. tetras = getZ(40, 40)
  159.  
  160. if(Tetsel == 3 ):
  161. tetras = getJ(40, 40)
  162.  
  163. if(Tetsel == 4 ):
  164. tetras = getO(40, 40)
  165.  
  166. if(Tetsel == 5 ):
  167. tetras = getL(40, 40)
  168.  
  169. if(Tetsel == 6 ):
  170. tetras = getT(40, 40)
  171. # tetras = getI(20, 20)
  172. # draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
  173. # tetras.drawrec(draw)
  174. # disp.display(img)
  175. # time.sleep(2)
  176.  
  177. # tetras = getS(20, 20)
  178. # draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
  179. # tetras.drawrec(draw)
  180. # disp.display(img)
  181. # time.sleep(2)
  182.  
  183. # tetras = getZ(20, 20)
  184. # draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
  185. # tetras.drawrec(draw)
  186. # disp.display(img)
  187. # time.sleep(2)
  188.  
  189. # tetras = getJ(20, 20)
  190. # draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
  191. # tetras.drawrec(draw)
  192. # disp.display(img)
  193. # time.sleep(2)
  194.  
  195. # tetras = getO(20, 20)
  196. # draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
  197. # tetras.drawrec(draw)
  198. # disp.display(img)
  199. # time.sleep(2)
  200.  
  201. # tetras = getL(20, 20)
  202. # draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
  203. # tetras.drawrec(draw)
  204. # disp.display(img)
  205. # time.sleep(2)
  206.  
  207. # tetras = getT(20, 20)
  208. # draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
  209. # tetras.drawrec(draw)
  210. # disp.display(img)
  211. # time.sleep(2)
  212.  
  213.  
  214.  
  215.  
  216. # Write buffer to display hardware, must be called to make things visible on the
  217. # display!
  218. disp.display(img)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement