Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Copyright (c) 2014 Adafruit Industries
- # Author: Tony DiCola
- #
- # Permission is hereby granted, free of charge, to any person obtaining a copy
- # of this software and associated documentation files (the "Software"), to deal
- # in the Software without restriction, including without limitation the rights
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- # copies of the Software, and to permit persons to whom the Software is
- # furnished to do so, subject to the following conditions:
- #
- # The above copyright notice and this permission notice shall be included in
- # all copies or substantial portions of the Software.
- #
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- # THE SOFTWARE.
- from PIL import Image
- from PIL import ImageDraw
- from PIL import ImageFont
- import time
- import ST7735
- Tetsel = 0
- def rr(point):
- return(point[1], -point[0])
- def rl(point):
- return (-point[1], point[0])
- def trans (point, move):
- return (point[0]+move[0], point[1]+move[1])
- def flip (fliped):
- return (-fliped[0], -fliped[1])
- class Tetris:
- def __init__(self, ax, ay, bx, by, cx, cy, dx, dy):
- self.bax = (ax, ay)
- self.bbx = (bx, by)
- self.bcx = (cx, cy)
- self.bdx = (dx, dy)
- def println(self):
- print(self.bax, self.bbx, self.bcx, self.bdx)
- def drawrec(self, imagy):
- imagy.rectangle((self.bax[0], self.bax[1] ,10+self.bax[0], 10+self.bax[1]), outline=(255,255,0), fill=(255,0,255))
- imagy.rectangle((self.bbx[0], self.bbx[1] ,10+self.bbx[0], 10+self.bbx[1]), outline=(255,255,0), fill=(255,0,255))
- imagy.rectangle((self.bcx[0], self.bcx[1] ,10+self.bcx[0], 10+self.bcx[1]), outline=(255,255,0), fill=(255,0,255))
- imagy.rectangle((self.bdx[0], self.bdx[1] ,10+self.bdx[0], 10+self.bdx[1]), outline=(255,255,0), fill=(255,0,255))
- def moves(self, point):
- self.bax = trans(self.bax,point)
- self.bbx = trans(self.bbx,point)
- self.bcx = trans(self.bcx,point)
- self.bdx = trans(self.bdx,point)
- def rotateL(self):
- temp = self.bbx
- self.moves(flip(self.bbx))
- self.bax = rl(self.bax)
- self.bcx = rl(self.bcx)
- self.bdx = rl(self.bdx)
- self.moves(temp)
- def getO(x, y):
- return Tetris(x, y, x+10, y+0, x+0, y+10, x+10, y+10)
- def getI(x, y):
- return Tetris(x-10, y+0, x, y, x+10, y+0, x+20, y+0)
- def getS(x, y):
- return Tetris(x+0, y-10, x, y, x+10, y-10, x-10, y)
- def getZ(x, y):
- return Tetris(x-10, y+0, x, y, x+0, y+10, x+10, y+10)
- def getL(x, y):
- return Tetris(x+10, y+0, x, y, x+0, y-10, x+0, y-20)
- def getJ(x, y):
- return Tetris(x-10, y+0, x, y, x+0, y-10, x+0, y-20)
- def getT(x, y):
- return Tetris(x+10, y+0, x, y, x+0, y+10, x-10, y+0)
- print("""
- shapes.py - Display test shapes on the LCD using PIL.
- If you're using Breakout Garden, plug the 0.96" LCD (SPI)
- breakout into the rear slot.
- """)
- # Create ST7735 LCD display class.
- disp = ST7735.ST7735(
- port=0,
- cs=0, # BG_SPI_CSB_BACK or BG_SPI_CS_FRONT
- dc=24,
- rst=25,
- invert=False,
- spi_speed_hz=4000000
- )
- # Initialize display.
- disp.begin()
- WIDTH = disp.width
- HEIGHT = disp.height
- # Clear the display to a red background.
- # Can pass any tuple of red, green, blue values (from 0 to 255 each).
- # Get a PIL Draw object to start drawing on the display buffer.
- img = Image.new('RGB', (WIDTH, HEIGHT), color=(255, 0, 0))
- draw = ImageDraw.Draw(img)
- # Draw a purple rectangle with yellow outline.
- y = 0
- while True:
- draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
- Buttonimp = input("what is your imput:")
- if(Buttonimp == "a"):
- Tetsel = Tetsel - 1
- if(Buttonimp == "d"):
- Tetsel = Tetsel + 1
- if(Tetsel > 6):
- Tetsel = 0
- if(Tetsel < 0):
- Tetsel = 6
- if(Tetsel == 0 ):
- tetras = getI(40, 40)
- if(Tetsel == 1 ):
- tetras = getS(40, 40)
- if(Tetsel == 2 ):
- tetras = getZ(40, 40)
- if(Tetsel == 3 ):
- tetras = getJ(40, 40)
- if(Tetsel == 4 ):
- tetras = getO(40, 40)
- if(Tetsel == 5 ):
- tetras = getL(40, 40)
- if(Tetsel == 6 ):
- tetras = getT(40, 40)
- # tetras = getI(20, 20)
- # draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
- # tetras.drawrec(draw)
- # disp.display(img)
- # time.sleep(2)
- # tetras = getS(20, 20)
- # draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
- # tetras.drawrec(draw)
- # disp.display(img)
- # time.sleep(2)
- # tetras = getZ(20, 20)
- # draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
- # tetras.drawrec(draw)
- # disp.display(img)
- # time.sleep(2)
- # tetras = getJ(20, 20)
- # draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
- # tetras.drawrec(draw)
- # disp.display(img)
- # time.sleep(2)
- # tetras = getO(20, 20)
- # draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
- # tetras.drawrec(draw)
- # disp.display(img)
- # time.sleep(2)
- # tetras = getL(20, 20)
- # draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
- # tetras.drawrec(draw)
- # disp.display(img)
- # time.sleep(2)
- # tetras = getT(20, 20)
- # draw.rectangle((0, 0, WIDTH, HEIGHT), outline=(255, 255, 0), fill=(255, 0, 0))
- # tetras.drawrec(draw)
- # disp.display(img)
- # time.sleep(2)
- # Write buffer to display hardware, must be called to make things visible on the
- # display!
- disp.display(img)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement