Example #1
0
def main():
    """
    Main routine
    """

    uio = oledui.UI() # pylint: disable-msg=invalid-name

    points = 5
    length = 20

    form = [
        [uio.UI_HEAD, 0, "Draw A Star"],
        [uio.UI_TEXT, 2, 0, "Points:"],
        [uio.UI_INT, 2, 8, 2, points],
        [uio.UI_TEXT, 4, 0, "Length:"],
        [uio.UI_INT, 4, 8, 2, length],
    ]

    result = uio.form(form)
    if result:
        points = form[2][uio.UI_VAL]
        length = form[4][uio.UI_VAL]

        bot = TurtlePlotBot()
        star(bot, points, length)
        bot.done()
Example #2
0
def main():
    """
    Write "Hello!"
    """
    bot = TurtlePlotBot()
    bot.setscale(2)
    bot.write("Hello!", "fonts/scripts.fnt")
    bot.done()
Example #3
0
def main(ui):
    """
    Write "Hello!"
    """
    message = "Hello!"
    ui.cls()
    width = ui.size(message, scale=2, font="fonts/scripts.fnt")
    column = ui.width // 2 - width // 2
    line = ui.height // 2 - 16
    ui.draw(message, column, line, scale=2, font="fonts/scripts.fnt")

    bot = TurtlePlotBot()
    bot.setscale(2)
    bot.write(message, "fonts/scripts.fnt")
    bot.done()
Example #4
0
def main():
    """
    Write text using user provided values
    """
    uio = oledui.UI() # pylint: disable-msg=invalid-name
    fonts = uos.listdir("/fonts")
    message = "Hello!"
    scale = 1

    form = [
        [uio.HEAD, 0, "Write A Message"],
        [uio.TEXT, 2, 0, "Message:"],
        [uio.STR, 3, 0, 16, message],
        [uio.TEXT, 5, 0, "Scale:"],
        [uio.INT, 5, 8, 2, scale],
    ]

    again = True
    while again:
        result = uio.form(form)
        if result:
            message = form[2][uio.VAL]
            scale = form[4][uio.VAL]
            font = 0
            response = 0
            font = uio.menu("Choose A Font", fonts, font)
            if font is not None:
                uio.cls(fonts[font], 0)
                uio.draw(message, 0, 32, "/fonts/" + fonts[font])
                response = uio.select(7, 0, ("Draw", "Back", "Cancel"), 0)
                if response[1] == 0:
                    uio.cls(0)
                    bot = TurtlePlotBot()
                    bot.setscale(scale)
                    bot.write(message, "/fonts/" + fonts[font])
                    bot.done()

                again = response[1] == 1
            else:
                again = False
        else:
            again = False
Example #5
0
def main(ui):
    """
    Main routine
    """
    points = 5
    length = 20
    ok = 0

    form = [
        [ui.HEAD, 0, "Draw A Star"],
        [ui.INT, 0, 2, "Points:", 8, 2, 2, points],
        [ui.INT, 0, 4, "Length:", 8, 4, 2, length],
        [ui.OK, 0, 7, ("Next", "Cancel"), ok],
    ]

    btn, ok = ui.form(form)
    if btn == button.CENTER and ok == 0:
        points = form[1][ui.VAL]
        length = form[2][ui.VAL]

        bot = TurtlePlotBot()
        star(bot, points, length)
Example #6
0
'''
Better way to draw a box
'''

from turtleplotbot import TurtlePlotBot
bot = TurtlePlotBot()
bot.pendown()

for _ in range(4):
    bot.forward(30)
    bot.left(90)

bot.done()

__import__("menu")  # optional return to turtleplotbot menu
Example #7
0
'''
Approximate a circle or ellipse using a `n` sided polygon
'''

import math

from turtleplotbot import TurtlePlotBot
bot=TurtlePlotBot()

def circle(bot, radius_x, radius_y, sides):
    '''
    Approximate a circle or ellipse by drawing a `n` sided polygon

    Args:
        radius_x: horizonal radius
        radius_y: vertical radius
        sides: number of line segments to draw

    Note:
        To draw circle use the same value for both radii

    '''
    step = 2 * math.pi / sides

    for theta in range(0, 2 * math.pi, step):
        x = radius_x * math.cos(theta)
        y = radius_y * math.sin(theta)

        if theta is 0:
            start_x = x
            start_y = y
Example #8
0
'''
Write a message.
'''

from turtleplotbot import TurtlePlotBot
bot = TurtlePlotBot()

# make the text 2 times larger then default
bot.setscale(2)
bot.write("Hello!", "fonts/scripts.fnt")
bot.done()

__import__("menu")  # optional return to turtleplotbot menu
Example #9
0
def main(ui):
    """
    Write text using user provided values
    """
    fonts = [f for f in uos.listdir("/fonts") if f.endswith(".fnt")]
    fonts_len = len(fonts)
    message = "Hello!"
    scale = 0
    ok = 0

    form = [
        [ui.HEAD, 0, "Write A Message"],
        [ui.STR, 0, 2, "Message:", 0, 3, 16, message],
        [ui.SEL, 0, 5, "Scale:", 6, 5, ("1", "2", "3"), scale],
        [ui.OK, 0, 7, ("Next", "Cancel"), ok],
    ]

    again = True
    while again:
        btn, ok = ui.form(form)
        if btn == button.CENTER and ok == 0:
            message = form[1][ui.VAL]
            scale = form[2][ui.VAL] + 1
            font = 0
            font = ui.menu("Choose A Font", fonts, font)
            if font is not None:

                while again:
                    ui.cls(fonts[font], 0)
                    font_file = "/fonts/" + fonts[font]
                    width = ui.size(message, font=font_file, scale=scale)

                    ui.draw(message,
                            ui.width // 2 - width // 2,
                            ui.height // 2,
                            ui.fg,
                            font=font_file,
                            scale=scale)

                    response = 0
                    btn, response = ui.select(0, 7, ("Draw", "Back", "Quit"),
                                              response)
                    if btn == button.CENTER:
                        if response == 0:
                            ui.cls(0)
                            bot = TurtlePlotBot()
                            bot.setscale(scale)
                            bot.write(message, "/fonts/" + fonts[font])
                            bot.done()
                            again = False
                        elif response == 2:
                            again = False

                    if btn == button.UP:
                        font -= 1
                        font %= fonts_len

                    elif btn == button.DOWN:
                        font += 1
                        font %= fonts_len

        else:
            again = False
Example #10
0
'''
Draw a star
'''

from turtleplotbot import TurtlePlotBot
bot = TurtlePlotBot()


def star(bot, points, length):
    '''
    Draw a 'n' pointed star with 'length' sides

    Args:
        sides: number of points
        length: length of each side
    '''
    angle = 180.0 - 180.0 / points
    bot.pendown()

    for _ in range(points):
        bot.forward(length)
        bot.left(angle)
        bot.forward(length)

    bot.penup()


star(bot, 5, 30)

__import__("menu")  # optional return to turtleplotbot menu
Example #11
0
from turtleplotbot import TurtlePlotBot

bot = TurtlePlotBot()
bot.pendown()
bot.circle(20, 360)
bot.done()

__import__("menu")  # optional return to turtleplotbot menu