Esempio n. 1
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
Esempio n. 2
0
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)
    explorer.circle(90 + adc1, 46, 10)

    explorer.set_pen(0, 0, adc2 * 2)
    explorer.circle(90 + adc2, 66, 10)

    # example for the on-board A/B/X/Y buttons
    if explorer.is_pressed(explorer.BUTTON_A):
        explorer.set_pen(255, 255, 255)
        explorer.text("Button A pressed", 20, 110, 200)
    elif explorer.is_pressed(explorer.BUTTON_B):
        explorer.set_pen(255, 255, 255)
        explorer.text("Button B pressed", 20, 110, 200)
    elif explorer.is_pressed(explorer.BUTTON_X) and explorer.is_pressed(
Esempio n. 3
0
#Calls the line procedure above but uses start and end points
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
        description = "good"
    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)
Esempio n. 5
0
            (14 - r) / 2,
            (14 - r) / 2,
            display.create_pen(random.randint(0, 255), random.randint(0, 255),
                               random.randint(0, 255)),
        ))

while True:
    display.set_pen(40, 40, 40)
    display.clear()

    for ball in balls:
        ball.x += ball.dx
        ball.y += ball.dy

        xmax = width - ball.r
        xmin = ball.r
        ymax = height - ball.r
        ymin = ball.r

        if ball.x < xmin or ball.x > xmax:
            ball.dx *= -1

        if ball.y < ymin or ball.y > ymax:
            ball.dy *= -1

        display.set_pen(ball.pen)
        display.circle(int(ball.x), int(ball.y), int(ball.r))

    display.update()
time.sleep(0.01)
Esempio n. 6
0
 def circle(self, x, y, r, color):
     self.set_pen(color)
     display.circle(x, y, r)