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
def draw_bar(v, i):
    current_bar_top = int(bar_height - (bar_height * v))
    # Drawing outside of the display region will cause horrible, horrible crashes
    current_bar_top = max(0, current_bar_top)
    current_bar_height = bar_height - current_bar_top
    display.rectangle(i * bar_width, current_bar_top, bar_width,
                      current_bar_height - 1)
def say(string):
    x = half_width // 2
    y = height // 3
    h = half_width
    w = height // 3
    exp.set_pen(black)
    exp.rectangle(x, y, h, w)
    exp.set_pen(white)
    exp.text(string, x + 10, y + 10, 15)
    exp.update()
def say(string):
    x = int(half_width / 2)
    y = int(height / 3)
    h = half_width
    w = int(height / 3)
    explorer.set_pen(black)
    explorer.rectangle(x, y, h, w)
    explorer.set_pen(white)
    explorer.text(string, x + 10, y + 10, 15)
    explorer.update()
Exemple #5
0
def playsong(song):  # this function plays your song
    a = 0  # this variable keeps track of the visualiser bars
    for i in range(len(song)):
        if (song[i] == "P"):
            bequiet()
        else:
            playtone(tones[song[i]])
            explorer.set_pen(0, 255, 0)  # switch to green pen
            explorer.rectangle(
                a, 240 - (int((tones[song[i]]) / 21)), 5, 240
            )  # draw a green bar corresponding to the frequency of the note
            a += 7
        if a >= 240:  # clears the screen if the green bars reach the right hand edge
            clear()
            a = 0
        explorer.update()
        utime.sleep(
            0.15
        )  # change this number if you want to alter how long the notes play for
    bequiet()
Exemple #6
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
Exemple #7
0
    # 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)

    # writes the reading as text in the white rectangle
    display.set_pen(0, 0, 0)
    display.text("{:.0f}".format(temperature) + "c", 3, 3, 0, 4)

    # time to update the display
    display.update()

    # waits for 5 seconds
    utime.sleep(5)
Exemple #8
0
# show all channel names
for i in range(4):
    display.set_pen(*colors[i])
    display.text(button_names[i], 128 + (i * 22), 0, 1, 1)

# x coordinate of trace goes from 0 (left) to the width of the screen then back to 0
x = 0

# ADC values are stored as 16 bit values (2^16 = 65535). First 20 pixels are used for the title
scale_factor = (HEIGHT - 20) / 65535

# loop forever
while True:
    # clear current x position of screen in black
    display.set_pen(0, 0, 0)
    display.rectangle(128, 20, WIDTH - 128, 10)
    display.rectangle(x, 20, 1, HEIGHT)

    # loop through each ADC channel and toggle
    for i in range(4):
        # toggle ADC channel enabled if button is pressed
        if display.is_pressed(buttons[i]):
            while display.is_pressed(buttons[i]):
                utime.sleep(0.1)
            enabled[i] = not enabled[i]

        # draw channel name in black if disabled, or in correct colour if enabled
        if enabled[i]:
            display.set_pen(*colors[i])

            # draw trace
Exemple #9
0
 y = int(joystick[0].read_u16() / 65536 * 8)
 
 # pull joystick down to shoot
 if y < 2 and last_fired_player + RELOAD_TIME_MS < utime.ticks_ms():
     shots.append([x, HEIGHT])
     last_fired_player = utime.ticks_ms()
     print("Fire", shots)
 
 # clear screen
 display.set_pen(0,0,0)
 display.clear()
 
 # draw all shelters
 display.set_pen(255, 255, 0)
 for shelter in shelters:
     display.rectangle(shelter[0], shelter[1], SHELTER_WIDTH, shelter[2])
 
 # draw all aliens
 display.set_pen(0,255,0)
 for alien in aliens:
     # move right
     if alien[2] == 1:
         if alien[0] < WIDTH:
             alien[0] += 1
         else:
             alien[1] += 10
             alien[2] = 0
     # move left
     else:
         if alien[0] > 0:
             alien[0] -= 1
Exemple #10
0
    if day_progress < 0:
        day_progress = 0
    if day_progress > 1:
        day_progress = 1

    # fill the screen yellow
    display.set_pen(255, 255, 0)
    display.clear()

    # draw title
    display.set_pen(0, 0, 0)
    display.text("Sunflower", 0, 0, 240, 5)

    # draw bar to show how far through the day we are
    display.set_pen(255, 0, 0)
    display.rectangle(0, 50, int(240 * day_progress), 10)

    display.set_pen(0, 0, 0)

    # manually control servo 1
    if mode == 0:

        # move the servos if the button is pressed
        if display.is_pressed(display.BUTTON_A):
            display.text("A", 0, 50, 240, 8)
            if angle1 > 0:
                angle1 -= 2
        elif display.is_pressed(display.BUTTON_B):
            display.text("B", 0, 150, 240, 8)
            if angle1 < 180:
                angle1 += 2
Exemple #11
0
def pointline(p1, p2):
    line(p1.X, p1.Y, p2.X, p2.Y)


def update():
    display.update()


# Clears screen to black and sets pen for the rest of the drawing
display.set_pen(155, 155, 155)
display.clear()
display.set_pen(purple)

# Now lets play with the built in objects
display.circle(100, 100, 50)
display.rectangle(0, 00, 25, 25)
display.rectangle(0, 0, 25, 25)
display.pixel_span(0, 200, 120)
#Use this for vertical line
display.rectangle(120, 0, 1, 25)

#should be diagonal across the screen
line(0, 0, 240, 240)

# Create and print a point
p = Point(200, 200)
print(p)
pointline(p, Point(100, 50))

# Create and print a triangle
t = Triangle(Point(0, 0), Point(120, 120), Point(0, 240))
    else:
        description = "bad"
    return description


while True:
    # read the sensors
    temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read()

    # pressure comes in pascals which is a reight long number, lets convert it to the more manageable hPa
    pressurehpa = pressure / 100

    # draw a thermometer/barometer thingy
    display.set_pen(125, 125, 125)
    display.circle(190, 190, 40)
    display.rectangle(180, 45, 20, 140)

    # switch to red to draw the 'mercury'
    display.set_pen(red)
    display.circle(190, 190, 30)
    thermometerheight = int(120 / 30 * temperature)
    if thermometerheight > 120:
        thermometerheight = 120
    if thermometerheight < 1:
        thermometerheight = 1
    display.rectangle(186, 50 + 120 - thermometerheight, 10, thermometerheight)

    # drawing the temperature text
    display.set_pen(white)
    display.text("temperature:", 10, 10, 240, 3)
    display.set_pen(tempcolour)
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()
Exemple #14
0
import time, random
import picoexplorer as explorer

# set up screem
WIDTH = explorer.get_width()
HEIGHT = explorer.get_height()
display_buffer = bytearray(WIDTH * HEIGHT * 2)  # 2-bytes per pixel (RGB565)
explorer.init(display_buffer)

# main loop (forever)
while True:
    # clear screen and display controle
    explorer.set_pen(0, 0, 0)
    explorer.rectangle(0, 0, WIDTH, HEIGHT)
    explorer.set_pen(0, 0, 255)
    explorer.text("A/B Motor 1", 0, 0, WIDTH, 4)
    explorer.text("X/Y Motor 2", 0, 50, WIDTH, 4)

    # Press A/B to control motor 1
    if explorer.is_pressed(explorer.BUTTON_A):
        explorer.set_motor(0, 0, 1)
        explorer.text("Motor 1 Forwards", 0, 100, WIDTH, 2)
    elif explorer.is_pressed(explorer.BUTTON_B):
        explorer.set_motor(0, 1, 1)
        explorer.text("Motor 1 Backwards", 0, 100, WIDTH, 2)
    else:
        explorer.set_motor(0, 0, 0)

    # Press X/Y to control motor 2
    if explorer.is_pressed(explorer.BUTTON_X):
        explorer.set_motor(1, 0, 1)
def block(letter, x, y, colour):
    exp.set_pen(colour)
    exp.rectangle(x, y, half_width, half_height)
    exp.set_pen(black)
    exp.text(letter, x + 50, y + 50, 4)