Example #1
0
    def __startscreen(self) -> None:
        self.__l = 1  #level
        self.__d = SimonGame.DURATION  #initial note duration
        self.__u = SimonGame.SIMON  #current user
        self.__t = 0  #tries
        self.__c = [12, 6, 10, 10, 12, 10, 12, 12, 12, 12]  #character widths

        #draw start screen
        exp.set_pen(self.__pal(5))
        exp.clear()
        exp.set_pen(self.__pal(2))
        exp.text('DO SAME', 10, 20, 235, 6)
        exp.set_pen(0)
        exp.text('by: OneMadGypsy                                        2021',
                 10, 60, 240, 1)
        exp.text('A = Easy           10', 40, 100, 240, 2)
        exp.text('B = Medium       15', 40, 120, 240, 2)
        exp.text('X = Hard           25', 40, 140, 240, 2)
        exp.text('Y = Nightmare  50', 40, 160, 240, 2)
        exp.update()

        dfclt = [10, 15, 5, 50]  #difficulties
        self.__sl = 0  #sequence length
        #wait for difficulty selection
        while not self.__sl:
            for n in range(4):
                if exp.is_pressed(n):
                    self.__sl = dfclt[n]
                    break

        self.__s = [randint(0, 3) for _ in range(self.__sl)]  #sequence
        self.__gameboard()  #draw gameboard
        sleep(1)  #pause 1 second for player to prepare
        self.__gameloop()  #start game
Example #2
0
    def __gameboard(self, seq: int = -1, user: bool = False) -> int:
        bt, tn = -1, -1
        exp.set_pen(0)
        exp.clear()

        #draw squares ~ capture button presses (if avail) OR Simon ~ store button tone
        for n, d in enumerate([2093, 2249, 2637, 2794]):
            p = ((exp.is_pressed(n) and user) or (n == seq))
            bt = n if p else bt
            tn = d if p else tn
            x, y = (n > 1) * 120, (n % 2) * 120
            exp.set_pen(self.__pal(n + 8))
            exp.rectangle(x + 2, y + 2, 116, 116)
            exp.set_pen(self.__pal(n + (4 * p)))
            exp.rectangle(x + 7, y + 7, 106, 106)

        #center circle for level display
        exp.set_pen(0)
        exp.circle(120, 120, 40)
        exp.set_pen(self.__pal(12))
        exp.circle(120, 120, 36)
        exp.set_pen(self.__pal(13))
        exp.circle(120, 120, 31)
        exp.set_pen(65535)

        #find x for center placement of level display
        if self.__l < 10:
            c = self.__c[self.__l]
        else:
            a = self.__l // 10
            b = self.__l - int(a * 10)
            c = self.__c[a] + self.__c[b]

        #display level number
        exp.text("{}".format(self.__l), 121 - c, 108, 160, 4)
        exp.update()

        return bt, tn
Example #3
0
# reads from Pico's temp sensor and converts it into a more manageable number
sensor_temp = machine.ADC(4)
conversion_factor = 3.3 / (65535)

i = 0

while True:
    # the following two lines do some maths to convert the number from the temp sensor into celsius
    reading = sensor_temp.read_u16() * conversion_factor
    temperature = round(27 - (reading - 0.706) / 0.001721)

    # this if statement clears the display once the graph reaches the right hand side of the display
    if i >= (width + 1):
        i = 0
        display.set_pen(0, 0, 0)
        display.clear()

    # chooses a pen colour based on the temperature
    display.set_pen(0, 255, 0)
    if temperature > 20:
        display.set_pen(255, 0, 0)
    if temperature < 13:
        display.set_pen(0, 0, 255)

    # draws the reading as a tall, thin rectangle
    display.rectangle(i, height - (temperature * 6), 6, height)

    # draws a white background for the text
    display.set_pen(255, 255, 255)
    display.rectangle(1, 1, 65, 33)
Example #4
0
    i = i % 6
    if i == 0:
        return v, t, p
    if i == 1:
        return q, v, p
    if i == 2:
        return p, v, t
    if i == 3:
        return p, q, v
    if i == 4:
        return t, p, v
    if i == 5:
        return v, p, q


h = 0

while True:
    h += 1
    r, g, b = [int(255 * c)
               for c in hsv_to_rgb(h / 360.0, 1.0, 1.0)]  # rainbow magic
    display.set_pen(r, g, b)  # Set pen to a converted HSV value
    display.clear()  # Fill the screen with the colour
    display.set_pen(0, 0, 0)  # Set pen to black
    display.text("pico disco!", 25, 20, 240, 6)  # Add some text
    display.text("\o/ \o/ \o/ \o/ \o/ \o/ \o/ \o/ \o/", 25, 120, 240,
                 4)  # and some more text
    display.text("oontz oontz oontz", 25, 220, 240,
                 2)  # and a bit more tiny text
    display.update()  # Update the display
    utime.sleep(1.0 / 60)
Example #5
0
import time
import picoexplorer as explorer

width = explorer.get_width()
height = explorer.get_height()

display_buffer = bytearray(width * height * 2)  # 2-bytes per pixel (RGB565)
explorer.init(display_buffer)

explorer.set_audio_pin(0)

i = 1

while True:
    explorer.set_pen(120, 40, 60)
    explorer.clear()

    adc0 = int(explorer.get_adc(0) * 120)
    adc1 = int(explorer.get_adc(1) * 120)
    adc2 = int(explorer.get_adc(2) * 120)

    explorer.set_pen(255, 255, 255)

    explorer.text("ADC0:", 20, 20, 100)
    explorer.text("ADC1:", 20, 40, 100)
    explorer.text("ADC2:", 20, 60, 100)

    explorer.set_pen(adc0 * 2, 0, 0)
    explorer.circle(90 + adc0, 26, 10)

    explorer.set_pen(0, adc1 * 2, 0)
Example #6
0
def clear():  # this function clears Pico Explorer's screen to black
    display.set_pen(0, 0, 0)
    display.clear()
    display.update()
Example #7
0
def birdgame(width, height):

    #colours
    brightwhite = display.create_pen(255, 255, 255)
    white = display.create_pen(155, 155, 155)
    red = display.create_pen(155, 0, 0)
    green = display.create_pen(0, 155, 0)
    brown = display.create_pen(210, 105, 30)
    skyblue = display.create_pen(50, 50, 115)
    black = display.create_pen(0, 0, 0)

    birdgrid = [
        "00000011111100000", "00001144441510000", "00014444415551000",
        "00014444415515100", "01111444415515100", "15555144415555100",
        "15555514441555100", "14555414444111110", "01444144441333331",
        "00111222213111110", "00001222221333100", "00000112222111100",
        "00000001111000000"
    ]

    def drawbird(x, y, zoom):
        #draw the bird
        row = 0
        col = 0
        for line in birdgrid:
            #print(line)
            for pixel in line:
                #print(pixel)
                colour = str(pixel)
                if colour != "0":
                    if colour == "1":
                        display.set_pen(black)
                    if colour == "2":
                        display.set_pen(green)
                    if pixel == "3":
                        display.set_pen(brown)
                    if pixel == "4":
                        display.set_pen(red)
                    if pixel == "5":
                        display.set_pen(white)
                    display.rectangle(x + (col * zoom), y + (row * zoom), zoom,
                                      zoom)
                col += 1
            row += 1
            col = 0

    class Bird:
        def __init__(self, x, y):
            self.x = x
            self.y = y
            self.flying = True
            self.crashed = False

    class Pillar:
        def __init__(self, x, hole):
            self.x = x
            self.holetop = hole
            self.holebottom = hole + 70

    bird = Bird(5, 20)
    colonade = []
    score = 0

    # reset
    def reset():
        x = 0
        for i in range(0, 3):
            hole = random.randint(1, height - 100)
            colonade.append(Pillar(x + 100, hole))
            x += int(width / 3)

    reset()

    while bird.flying:
        display.set_pen(skyblue)
        display.clear()

        #draw the pillars
        for pillar in colonade:
            display.set_pen(white)
            display.rectangle(pillar.x, 0, 10, height)
            display.set_pen(skyblue)
            display.rectangle(pillar.x, pillar.holetop, 10, 70)
            if not bird.crashed:
                if pillar.x > -10:
                    pillar.x -= 1
                else:
                    pillar.x = width
                    hole = random.randint(1, height - 100)
                    pillar.holetop = hole
                    pillar.holebottom = hole + 50
                    score += 1
                if pillar.x < 39 and pillar.x > 6:
                    if bird.y < pillar.holetop or bird.y + 28 > pillar.holebottom:
                        bird.crashed = True


#draw the bird
        drawbird(bird.x, bird.y, 2)

        #draw score
        display.set_pen(white)
        display.text(str(score), width - 70, 5, 1, 5)

        #move the bird
        if not bird.crashed:
            if display.is_pressed(display.BUTTON_A):
                #flap
                if bird.y > -22:
                    bird.y -= 3
            else:
                if bird.y < height - 25:
                    bird.y += 3

        if display.is_pressed(display.BUTTON_B):
            colonade = []
            reset()
            bird.y = 20
            bird.crashed = False

        display.update()
Example #8
0
def clear():  # this function clears Pico Explorer's screen to black
    explorer.set_pen(0, 0, 0)
    explorer.clear()
    explorer.update()
Example #9
0
def clear():
    display.set_pen(0, 0, 0)
    display.clear()
    display.update()
                button = anykey()
            if button == buttons[colours[i] - 1]:
                lightup(colours[i], True)
                say("Your Turn")
                i += 1
            else:
                exp.set_tone(150)
                wrong.off()
                say("Wrong!")
                playing = False
                i = difficulty + 1
            time.sleep(1)
            all(False)
            wrong.on()
            say("Your turn")
            shhh()
        if playing:
            difficulty = difficulty + 1


exp.set_pen(black)
exp.clear()
exp.update()

all(False)
exp.update()

while True:
    attract()
    game()
Example #11
0
 def blk(self):
     display.set_pen(0, 0, 0)
     display.clear()
     display.update()