Esempio n. 1
0
 def setup():
     global second_hand, minute_hand, hour_hand, writer
     mode("logo")
     make_hand_shape("second_hand", 125, 25)
     make_hand_shape("minute_hand", 130, 25)
     make_hand_shape("hour_hand", 90, 25)
     clockface(160)
     second_hand = Turtle()
     second_hand.shape("second_hand")
     second_hand.color("gray20", "gray80")
     minute_hand = Turtle()
     minute_hand.shape("minute_hand")
     minute_hand.color("blue1", "red1")
     hour_hand = Turtle()
     hour_hand.shape("hour_hand")
     hour_hand.color("blue3", "red3")
     for hand in second_hand, minute_hand, hour_hand:
         hand.resizemode("user")
         hand.shapesize(1, 1, 3)
         hand.speed(0)
     ht()
     writer = Turtle()
     #writer.mode("logo")
     writer.ht()
     writer.pu()
     writer.bk(85)
Esempio n. 2
0
def draw_tree_v2(height: int, turtle: Turtle):
    if height > 0:
        turtle.fd(height)
        turtle.rt(20)
        draw_tree_v2(height - 5, turtle)

        turtle.lt(40)
        draw_tree_v2(height - 5, turtle)

        if height < 25:
            turtle.pencolor('green')
        turtle.rt(20)
        turtle.bk(height)
        turtle.pencolor('black')
def main():
    global d, SHS, SF, A
    A = 42 # answer to the ultimate question ... (you know)
    SHS = A / 20.
    SF = 1.0
    DSF = 1.0038582416
    s = Screen()
    s.setup(800, 600)
    s.reset()
    s.tracer(0)
    d = Turtle(visible=False)
    for i in range(6):
        d.fd(500)
        d.bk(500)
        d.left(60)   

    triangles = []
    for c in range(-5,6,2):
        if abs(c) != 1:
            triangles.append(TriTurtle(c, 1, 1))
            triangles.append(TriTurtle(c, -1, 2))
    for c in range(-4,5,2):
        if c != 0:
            triangles.append(TriTurtle(c, 2, 2))
            triangles.append(TriTurtle(c, -2, 1))
        triangles.append(TriTurtle(c, -4, 2))
        triangles.append(TriTurtle(c, 4, 1))
    for c in range(-3,4,2):
        triangles.append(TriTurtle(c, 5, 2))
        triangles.append(TriTurtle(c, -5, 1))
        triangles.append(TriTurtle(c, -7, 2))
        triangles.append(TriTurtle(c, 7, 1))
    for c in range(-2,3,2):
        triangles.append(TriTurtle(c, 8, 2))
        triangles.append(TriTurtle(c, -8, 1))
    for c in (-1, 1):
        triangles.append(TriTurtle(c, 1, 1))
        triangles.append(TriTurtle(c, -1, 2))
    triangles.append(TriTurtle(0, 2, 2))
    triangles.append(TriTurtle(0, -2, 1))
    s.tracer(1)
                         
    for phi in range(1,361):
        SF = SF*DSF
        s.tracer(0)
        for t in triangles:
            t.setturn(phi)
        #s.tracer(1)
        s.update()
    return "DONE!"
Esempio n. 4
0
def main():
    global d, SHS, SF, A
    A = 42  # answer to the ultimate question ... (you know)
    SHS = A / 20.
    SF = 1.0
    DSF = 1.0038582416
    s = Screen()
    s.setup(800, 600)
    s.reset()
    s.tracer(0)
    d = Turtle(visible=False)
    for i in range(6):
        d.fd(500)
        d.bk(500)
        d.left(60)

    triangles = []
    for c in range(-5, 6, 2):
        if abs(c) != 1:
            triangles.append(TriTurtle(c, 1, 1))
            triangles.append(TriTurtle(c, -1, 2))
    for c in range(-4, 5, 2):
        if c != 0:
            triangles.append(TriTurtle(c, 2, 2))
            triangles.append(TriTurtle(c, -2, 1))
        triangles.append(TriTurtle(c, -4, 2))
        triangles.append(TriTurtle(c, 4, 1))
    for c in range(-3, 4, 2):
        triangles.append(TriTurtle(c, 5, 2))
        triangles.append(TriTurtle(c, -5, 1))
        triangles.append(TriTurtle(c, -7, 2))
        triangles.append(TriTurtle(c, 7, 1))
    for c in range(-2, 3, 2):
        triangles.append(TriTurtle(c, 8, 2))
        triangles.append(TriTurtle(c, -8, 1))
    for c in (-1, 1):
        triangles.append(TriTurtle(c, 1, 1))
        triangles.append(TriTurtle(c, -1, 2))
    triangles.append(TriTurtle(0, 2, 2))
    triangles.append(TriTurtle(0, -2, 1))
    s.tracer(1)

    for phi in range(1, 361):
        SF = SF * DSF
        s.tracer(0)
        for t in triangles:
            t.setturn(phi)
        s.tracer(1)
    return "DONE!"
Esempio n. 5
0
     coach.up()
     coach.goto(-50, 50)
     coach.down()
     coach.seth(90)
     coach.fd(150)
     coach.rt(90)
     coach.fd(100)
     coach.rt(90)
     coach.fd(25)
 elif num == 1:
     coach.seth(0)
     coach.circle(-10, 540)
 elif num == 2:
     coach.left(90)
     coach.fd(25)
     coach.bk(20)
 elif num == 3:
     coach.right(15)
     coach.fd(10)
     coach.bk(10)
 elif num == 4:
     coach.left(30)
     coach.fd(10)
     coach.bk(10)
     coach.right(15)
     coach.fd(20)
 elif num == 5:
     coach.right(25)
     coach.fd(7)
     coach.bk(7)
 else:
Esempio n. 6
0
class NCSimVisualizer:
    def __init__(self, cfg_os):
        # Create Screen Object
        self.screen = Screen()

        # Add app icon
        LOGO_PATH = "assets/favicon.ico"
        # do not forget "@" symbol and .xbm format for Ubuntu
        LOGO_LINUX_PATH = "@assets/favicon_linux.xbm"

        # Use the same Tk root with turtle:
        # noinspection PyProtectedMember
        # assert isinstance(self.screen._root, tk.Tk)  # True
        # noinspection PyProtectedMember
        self.root = self.screen.getcanvas().winfo_toplevel()
        self.root.title("Network Coding Simulator")

        if cfg_os.lower() == "linux":
            self.root.iconbitmap(LOGO_LINUX_PATH)
        else:
            self.root.iconbitmap(LOGO_PATH)

        # tkinter use same root
        self.controls = tk.Frame(self.root)

        # Create Screen Layout Cursor
        self.layout_cursor = Turtle()
        self.layout_cursor.ht()
        self.layout_cursor.penup()
        self.layout_cursor.pensize(3)
        self.layout_cursor.color("slate grey")

        # Create Screen Message Cursor
        self.msg_cursor = Turtle()
        self.msg_cursor.ht()
        self.msg_cursor.penup()
        self.msg_cursor.color("midnight blue")

        # Create Screen coverage Cursor
        self.coverage_cursor = Turtle()
        self.coverage_cursor.ht()
        self.coverage_cursor.penup()
        self.coverage_cursor.pensize(2)
        self.coverage_cursor.color("saddle brown")

        # Create Screen Send Packet Cursor
        self.snd_pckt = Turtle()
        self.snd_pckt.ht()
        self.snd_pckt.penup()
        self.snd_pckt.pensize(2)
        self.snd_pckt.color("saddle brown")

        # Call Screen Init Method
        self.screen_init()

    def screen_init(self):
        # Set Screen Dimensions and Coloring
        self.screen.setup(TOTAL_WIDTH, TOTAL_HEIGHT)
        self.screen.bgcolor(SCREEN_BGCOLOR)

        self.layout_cursor.color("slate grey")
        self.layout_cursor.setposition(-((TOTAL_WIDTH / 2) - SCREEN_MARGIN),
                                       -((TOTAL_HEIGHT / 2) - SCREEN_MARGIN))

        self.layout_cursor.speed(8)
        self.layout_cursor.pendown()
        self.layout_cursor.fd(SCREEN_WIDTH)
        self.layout_cursor.rt(-90)
        self.layout_cursor.fd(SCREEN_HEIGHT)
        self.layout_cursor.rt(-90)
        self.layout_cursor.fd(SCREEN_WIDTH)
        self.layout_cursor.rt(-90)
        self.layout_cursor.fd(SCREEN_HEIGHT)
        self.layout_cursor.setheading(90)
        self.layout_cursor.fd(MESSAGE_MARGIN)
        self.layout_cursor.setheading(0)
        self.layout_cursor.fd(SCREEN_WIDTH)

        self.layout_cursor.penup()
        self.layout_cursor.speed("fastest")
        self.layout_cursor.color("midnight blue")

        x_cor = 0
        y_cor = int((TOTAL_HEIGHT / 2) - (3 / 4 * HEAD_MARGIN))
        self.layout_cursor.setposition(x_cor, y_cor)
        self.layout_cursor.write(f"{SCREEN_HEADER}",
                                 align="Center",
                                 font=("Calibri", HEADER_FONT_SIZE, "bold"))

        x_cor = 20 - (int(SCREEN_WIDTH / 2))
        y_cor = (int(TOTAL_HEIGHT / 2)) - (HEAD_MARGIN + 40)
        self.layout_cursor.setposition(x_cor, y_cor)
        self.layout_cursor.write(f"Topology: {TOPOLOGY_TYPE.title()}",
                                 align="Left",
                                 font=("Calibri", TEXT_FONT_SIZE, "bold"))

        x_cor = (int(SCREEN_WIDTH / 2)) - 20
        y_cor = (int(TOTAL_HEIGHT / 2)) - (HEAD_MARGIN + 40)
        self.layout_cursor.setposition(x_cor, y_cor)
        self.layout_cursor.write(f"Nodes: {NUM_OF_NODES}",
                                 align="Right",
                                 font=("Calibri", TEXT_FONT_SIZE, "bold"))

        self.visual_output_msg("This where the text message appears")

        # Stop Auto-update Screen changes
        self.screen.tracer(0)

    def visual_output_msg(self, message):
        x_cor = 20 - (int(SCREEN_WIDTH / 2))
        y_cor = (SCREEN_MARGIN + 15) - (int(TOTAL_HEIGHT / 2))
        self.msg_cursor.setposition(x_cor, y_cor)
        self.msg_cursor.clear()
        self.msg_cursor.write(f"{message}",
                              align="Left",
                              font=("Calibri", TEXT_FONT_SIZE, "bold"))

    def visual_send_packet(self, tx_node, rx_nodes):
        # draw arrow for all neighbors
        for rx_node in rx_nodes:
            self.snd_pckt.setposition(tx_node.pos())
            self.snd_pckt.pendown()
            self.snd_pckt.setheading(self.snd_pckt.towards(rx_node.pos()))
            self.snd_pckt.setposition(rx_node.pos())
            self.snd_pckt.bk(11)

            # Drawing arrow head
            self.snd_pckt.left(45)
            self.snd_pckt.backward(10)
            self.snd_pckt.forward(10)
            self.snd_pckt.right(90)
            self.snd_pckt.backward(10)
            self.snd_pckt.penup()

    def clear_send_packets(self):
        self.snd_pckt.pd()
        self.snd_pckt.clear()
        self.snd_pckt.pu()

    def show_coverage(self, node):
        self.coverage_cursor.goto(node.xcor(), node.ycor() - node.coverage)
        self.coverage_cursor.pendown()
        self.coverage_cursor.circle(node.coverage)
        self.coverage_cursor.penup()
        self.coverage_cursor.goto(node.pos())

    def hide_coverage(self):
        self.coverage_cursor.pendown()
        self.coverage_cursor.clear()
        self.coverage_cursor.penup()

    def screen_refresh(self):
        self.screen.update()

    def mainloop(self):
        while True:
            try:
                self.root.update()
                self.root.update_idletasks()
            except Exception as exp:
                print(exp)
                print("bye")
                break
Esempio n. 7
0
#                (46, 122, 86), (72, 43, 35), (145, 178, 148), (13, 99, 71), (233, 175, 164),
#                 (161, 142, 158), (105, 74, 77), (55, 46, 50), (183, 205, 171), (36, 60, 74),
#                 (18, 86, 90), (81, 148, 129), (148, 17, 20), (14, 70, 64), (30, 68, 100), (107, 127, 153),
#                 (174, 94, 97), (176, 192, 209)]

color_list = ["orange", "yellow", "light blue", "light green"]

tulip = Turtle()


#TODO: Create a dot painting with 10 by 10 rows of spots.
#Dots 20 in size, and 50 spaced between,

tulip.speed("fastest")
tulip.penup()
tulip.bk(300)
tulip.left(90)
tulip.forward(270)

# tulip.dot(20, random.choice(color_list))
# tulip.right(90)
# for _ in range(12):
#     tulip.forward(50)
#     tulip.dot(20, random.choice(color_list))


tulip.right(90)
tulip.forward(50)
for _ in range(10):
    tulip.dot(20, random.choice(color_list))
    tulip.forward(50)
Esempio n. 8
0
    angle: peak angle in degrees
    """
    y = r * math.sin(angle * math.pi / 180)

    t.rt(angle)
    t.fd(r)
    t.lt(90 + angle)
    t.fd(2 * y)
    t.lt(90 + angle)
    t.fd(r)
    t.lt(180 - angle)


# create the world and bob
bob = Turtle(shape='turtle')
bob._delay(50)
bob.pu()
bob.bk(130)
bob.pd()

# draw polypies with various number of sides
size = 40
draw_pie(bob, 5, size)
draw_pie(bob, 6, size)
draw_pie(bob, 7, size)
draw_pie(bob, 8, size)
screen = Screen()
screen.exitonclick()

# dump the contents of the campus to the file canvas.eps