Example #1
0
def drawui():
    ugfx.init()
    buttons.init()
    ugfx.clear(ugfx.html_color(0x87F717))

    ugfx.set_default_font(ugfx.FONT_MEDIUM)

    ugfx.fill_circle(50,50, 20, ugfx.WHITE)
    ugfx.fill_circle(50, 100, 20, ugfx.WHITE)

    ugfx.text(45, 45, "A", ugfx.RED)
    ugfx.text(45, 95, "B", ugfx.RED)

    ugfx.text(95, 45, "Flash the lights", ugfx.WHITE)
    ugfx.text(95, 95, "Disco Inferno", ugfx.WHITE)

    ugfx.fill_polygon(270,50, [ [0,0], [40,0], [40, 175], [0, 175] ], ugfx.RED)#  , [230, 100], [230, 60]
    ugfx.fill_polygon(270,50, [ [0,0], [-20,10], [-20, 50], [0, 40] ], ugfx.RED)#  , [230, 100], [230, 60]

    ugfx.area(283, 61, 14, 10, ugfx.WHITE)
    ugfx.area(283, 79, 14, 10, ugfx.WHITE)
    ugfx.area(283, 97, 14, 10, ugfx.WHITE)
    ugfx.area(283, 115, 14, 10, ugfx.WHITE)
    ugfx.area(283, 133, 14, 10, ugfx.WHITE)
    ugfx.area(283, 151, 14, 10, ugfx.WHITE)
    ugfx.area(283, 169, 14, 10, ugfx.WHITE)
    ugfx.area(283, 187, 14, 10, ugfx.WHITE)
Example #2
0
def clear_screen():
    # Selectively clear the screen by re-rendering the previous frame in black
    global last_polygons
    global last_mode
    for poly in last_polygons:
        if last_mode == FLAT:
            ugfx.fill_polygon(0, 0, poly, ugfx.BLACK)
        ugfx.polygon(0, 0, poly, ugfx.BLACK)
Example #3
0
def clear_screen():
    # Selectively clear the screen by re-rendering the previous frame in black
    global last_polygons
    global last_mode
    for poly in last_polygons:
        if last_mode == FLAT:
            ugfx.fill_polygon(0,0, poly, ugfx.BLACK)
        ugfx.polygon(0,0, poly, ugfx.BLACK)
 def create_random_food(snake):
     x, y = randrange(10, 270, 5), randrange(10, 110,
                                             5)  # not in extreme corners
     if (Food.hits_snake(snake, x, y)):
         Food.create_random_food(snake)
     food = Food(x, y)
     ugfx.fill_polygon(x, y, [[10, 5], [10, 10], [5, 10], [5, 5]],
                       ugfx.BLACK)
     return food
Example #5
0
 def draw(self):
     """Draw the hexagon to the screen"""
     ugfx.fill_polygon(0, 0, self.corners, Hex.kinds[self.kind])
     text_offset = Hex.size * 0.5
     if self.robber:
         ugfx.text(round(self.centre[0] - text_offset),
                   round(self.centre[1] - text_offset), "Rb ", ugfx.BLACK)
     else:
         if self.kind != 5:
             ugfx.text(round(self.centre[0] - text_offset),
                       round(self.centre[1] - text_offset),
                       "{} ".format(self.number), ugfx.BLACK)
Example #6
0
def showPage():
    global current_page
    # avoid out of bounds errors
    current_page = max(1, min(current_page, total_pages))
    
    start = (current_page - 1) * APPS_PER_PAGE
    end = start + APPS_PER_PAGE
    apps_on_current_page = all_apps[start:end]

    # Refresh page
    ugfx.clear(ugfx.html_color(EMF_PURPLE))

    # Write current page number and arrows
    ugfx.Label(0, 20, ugfx.width(), 20, "Page {} of {}".format(current_page, total_pages), justification=ugfx.Label.CENTER)

    if current_page > 1:
        ugfx.fill_polygon(10, 16, [[0, 10], [15, 20], [15, 0]], ugfx.WHITE)
        
    if current_page < total_pages:
        ugfx.fill_polygon(ugfx.width() - 30, 16, [[0, 0], [15, 10], [0, 20]], ugfx.WHITE)
    
    # Write app numbers and names
    i = 0
    yOffset = 45
    xOffset = 0
    for a in apps_on_current_page:
        # xOffset = (i % 3) * 8  # offset lines to match the physical layout of the keypad
        ugfx.area(20 + xOffset, yOffset + 2, 20, 20, ugfx.WHITE)
        ugfx.text(23 + xOffset, yOffset + 3, keypadLabels[i] + " ", EMF_PURPLE)

        ugfx.Label(46 + xOffset, yOffset + 3, ugfx.width(), 20, a['title'], justification=ugfx.Label.LEFT)
        yOffset = yOffset + 22
        i = i + 1

    while True:
        for key in keypad:
            keyIndex = keypad.index(key)
            if buttons.is_pressed(key) and (keyIndex < len(apps_on_current_page)):
                apps_on_current_page[keyIndex]['app'].boot()
                break

        if buttons.is_triggered(Buttons.JOY_Right) and (current_page is not total_pages):
            current_page = current_page + 1
            return
        if buttons.is_triggered(Buttons.JOY_Left) and (current_page is not 1):
            current_page = current_page - 1
            return
Example #7
0
def render(mode, rotation):
    # Rotate all the vertices in one go
    vertices = [rotation.mul(vertex) for vertex in obj_vertices]
    # Calculate normal for each face (for lighting)
    if mode == FLAT:
        face_normal_zs = [normal(face, vertices).z for face in obj_faces]
    # Project (with camera) all the vertices in one go as well
    vertices = [camera_projection.mul(vertex) for vertex in vertices]
    # Calculate projected normals for each face
    if mode != WIREFRAME:
        proj_normal_zs = [
            normal(face, vertices, False).z for face in obj_faces
        ]
    # Convert to screen coordinates all at once
    # We could do this faster by only converting vertices that are
    # in faces that will be need rendered, but it's likely that test
    # would take longer.
    vertices = [toScreenCoords(v) for v in vertices]
    # Render the faces to the screen
    vsync()
    clear_screen()

    global last_polygons
    global last_mode
    last_polygons = []
    last_mode = mode

    for index in range(len(obj_faces)):
        # Only render things facing towards us (unless we're in wireframe mode)
        if (mode == WIREFRAME) or (proj_normal_zs[index] > 0):
            # Convert polygon
            poly = [vertices[v] for v in obj_faces[index]]
            # Calculate colour and render
            ugcol = ugfx.WHITE
            if mode == FLAT:
                # Simple lighting calculation
                colour5 = int(face_normal_zs[index] * 31)
                colour6 = int(face_normal_zs[index] * 63)
                # Create a 5-6-5 grey
                ugcol = (colour5 << 11) | (colour6 << 5) | colour5
                # Render polygon
                ugfx.fill_polygon(0, 0, poly, ugcol)
            # Always draw the wireframe in the same colour to fill gaps left by the
            # fill_polygon method
            ugfx.polygon(0, 0, poly, ugcol)
            last_polygons.append(poly)
Example #8
0
def render(mode, rotation):
    # Rotate all the vertices in one go
    vertices = [rotation * vertex for vertex in obj_vertices]
    # Calculate normal for each face (for lighting)
    if mode == FLAT:
        face_normal_zs = [normal(face, vertices).z for face in obj_faces]
    # Project (with camera) all the vertices in one go as well
    vertices = [camera_projection * vertex for vertex in vertices]
    # Calculate projected normals for each face
    if mode != WIREFRAME:
        proj_normal_zs = [normal(face, vertices, False).z for face in obj_faces]
    # Convert to screen coordinates all at once
    # We could do this faster by only converting vertices that are
    # in faces that will be need rendered, but it's likely that test
    # would take longer.
    vertices = [toScreenCoords(v) for v in vertices]
    # Render the faces to the screen
    vsync()
    clear_screen()    

    global last_polygons
    global last_mode
    last_polygons = []
    last_mode = mode

    for index in range(len(obj_faces)):
        # Only render things facing towards us (unless we're in wireframe mode)
        if (mode == WIREFRAME) or (proj_normal_zs[index] > 0):
            # Convert polygon
            poly = [vertices[v] for v in obj_faces[index]]
            # Calculate colour and render
            ugcol = ugfx.WHITE
            if mode == FLAT:
                # Simple lighting calculation
                colour5 = int(face_normal_zs[index] * 31)
                colour6 = int(face_normal_zs[index] * 63)
                # Create a 5-6-5 grey
                ugcol = (colour5 << 11) | (colour6 << 5) | colour5
                # Render polygon        
                ugfx.fill_polygon(0,0, poly, ugcol)
            # Always draw the wireframe in the same colour to fill gaps left by the
            # fill_polygon method
            ugfx.polygon(0,0, poly, ugcol)
            last_polygons.append(poly)
Example #9
0
def draw_polygon(polygon, colour):
    ugfx.fill_polygon(polygon.x, polygon.y, polygon.points, colour)
    ugfx.polygon(polygon.x, polygon.y, polygon.points, ugfx.BLACK)
 def clear_square(self, pointx, pointy):
     ugfx.fill_polygon(pointx, pointy, [[10, 5], [10, 10], [5, 10], [5, 5]],
                       ugfx.WHITE)
 def render_square(self, pointx, pointy):
     ugfx.fill_polygon(pointx, pointy, [[10, 5], [10, 10], [5, 10], [5, 5]],
                       ugfx.BLACK)
Example #12
0
 def clear(self):
     ugfx.fill_polygon(0, 0, self.corners, ugfx.BLACK)