1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] how to draw a function from list coords?

Discussão em 'Python' iniciado por Stack, Setembro 14, 2025.

  1. Stack

    Stack Membro Participativo

    I have a list which stores the values of a position that I would like to draw a flag on however the position is stored as A OR G rather than a numerical value which means i am having trouble plotting it (cant plot a letter... ). I think the way about fixing this is to assign each letter to a numerical value which I can then plot as X,Y cords in my draw flag function.

    for competitor, direction in random_moves():

    if competitor == 'Competitor A':
    turtle.penup()
    if direction == 'Left':
    if positions[0][2] != 'A':
    positions[0][0] -= HORIZONTAL
    positions[0][2] = chr(ord(positions[0][2]) - 1)
    elif direction == 'Right':
    if positions[0][2] != 'G':
    positions[0][0] += HORIZONTAL
    positions[0][2] = chr(ord(positions[0][2]) + 1)
    elif direction == 'Up':
    if positions[0][3] != 7:
    positions[0][1] += VERTICAL
    positions[0][3] += 1
    elif direction == 'Down':
    if positions[0][3] != 1:
    positions[0][1] -= VERTICAL
    positions[0][3] -= 1

    turtle.setpos(positions[0][:2]) #MAKE A = 1
    turtle.write('ABC', align='left', font=20)
    turtle.dot(20, "blue")
    occupied[0].append((positions[0][2], positions[0][3]))


    I was also wondering why the turtle.write('ABC', align='left', font=20) and turtle.dot(20, "blue") commands work perfectly fine in the correct location however if I try to call my flag_germany function it draws the flag at 0,0 (not sure why) my draw flag function can be seen below. The stored list values can be seen as: and must be appended based on another random location function

    positions = [
    [-3*HORIZONTAL, 3*VERTICAL, 'A', 7],
    [3*HORIZONTAL, 3*VERTICAL, 'G', 7],
    [-3*HORIZONTAL, -3*VERTICAL, 'A', 1],
    [3*HORIZONTAL, -3*VERTICAL, 'G', 1]
    ]

    occupied = [ # To store the grid occupied
    [('A', 7)],
    [('G', 7)],
    [('A', 1)],
    [('G', 1)]
    ]


    draw flag function:

    def flag_germany():
    penup()
    color("black")
    fillcolor("white")
    seth(90)

    # origin_x = 0
    # origin_y = 0

    # goto(x, y)
    fillcolor("red")
    seth(90)
    begin_fill()
    forward(90 - 4)
    right(90)
    forward(120 - 4)
    right(90)
    forward(90 - 4)
    right(90)
    forward(120 - 4)
    right(90)
    end_fill()
    showturtle()
    #goto(origin_x, origin_y)

    # Orange Rectangle
    # goto(origin_x, origin_y+86)
    color("black")
    begin_fill()
    right(90)
    forward(120 - 4)
    right(-90)
    forward(32 - 4)
    left(90)
    forward(120 - 4)
    end_fill()
    # goto(origin_x, origin_y)

    # goto(origin_x, origin_y-4)
    color("yellow")
    begin_fill()
    penup()
    right(90)
    forward(58)
    pendown()
    right(90)
    forward(120-4)
    right(90)
    forward(32)
    right(90)
    forward(120-4)
    right(90)
    forward(30)
    end_fill()


    I have been playing around with using x and y inputs in my draw flag function however I am currently trying to get it to just draw from the location of the turtle just like the turtle.write('ABC', align='left', font=20) and turtle.dot(20, "blue") commands previously used for testing. Any ideas or pointers as to how I can get my flag drawing in the correct location would be much appreciated :) thanks for your time in advance. Sorry if I made a bad post im also new.

    Continue reading...

Compartilhe esta Página