예제 #1
0
def draw():
    colors = ("red", "orange", "yellow", "green", "blue", "purple", "black")
    t_names = ["r", "o", "y", "g", "b", "p", "bl"]
    turtles = []
    usr_quit = False
    q_btn = turtle.Turtle()
    q_btn.pu()
    q_btn.hideturtle()
    q_btn.goto(290, -300)
    q_btn.showturtle()
    q_btn.write("Quit", align="center", font=("Cooper Black", 12, "normal"))
    
    ##screen.onclick(usr_turtle.goto)
    usr_turtle.ondrag(usr_turtle.goto)
    screen.listen()
    screen.onclick(p_goto)
    screen.onkeypress(usr_turtle.reset, "r")
    T_xLoc = -200
    for index, i in enumerate(colors):
        n = t_names[index]
        t = turtle.Turtle(name = n)
        turtles.append(t)#, t.name)
        t.hideturtle()
        t.pu()
        t.goto(T_xLoc, -300)
        t.showturtle()
        t.pencolor(i)
        t.fillcolor(i)
        t.write(i, "%s Pallete" % i, align="right", font=("Cooper Black", 12, "normal"))
        t.onclick(usr_turtle.pencolor, args=i)
        print (i)
        T_xLoc += 60
        ##print ("#DEBUG", t.name)
    screen.onkeypress(quit, "q")
    print (turtles)
예제 #2
0
def create_turtle():
    name = input("Please give your turtle a name: \n")
    isRight = "You named your turtle %s, are you sure? \n [y] or [n] \n" % name
    valids = ['y', 'n']
    ans = good_input(isRight, valids)
    if (ans == 'y'):
        print ("You created a turtle! \n His/Her name is %s" % name)
        usr_turtle = turtle.Turtle(name=name)
        return usr_turtle
    else:
        create_turtle()
    if bu == 'green':
        player_start()
        g.checked = False
    elif bu == 'red':
        player.stop()
    elif bu == 'cyan':
        next1()
        buttons.off('cyan')
    elif bu == 'white':
        player.clear()
    elif bu == 'turtle':
        player.toggle_turtle()


# initialisation
aim = my_turtle.Turtle(.014, 8, (6, 1))
aim_setup()
player = my_turtle.Turtle(.028, 15, (15.5, 1))
player.draw_turtle()
angler = angler.Angler(8, 16.5, 5)
# buttons
x = g.sx(4)
y = g.sy(7.5)
buttons.Button("cyan", (x, y))
x = g.sx(18.6)
y = g.sy(17.8)
dx = (g.sx(27.6) - x) / 3.0
buttons.Button("green", (x, y))
x += dx
buttons.Button("red", (x, y))
x += dx
예제 #4
0
                pairs.append((i, values[index + 1]))
    #ODD:
    else:
        print (len(values), "# of values \n")
        """BREAK:"""
        for index, i in enumerate(values):
            ##print (index, i)
            if not(index == (len(values) - 1)):
                #if not(last value in values):
                if (index % 2 == 0):
                    pairs.append((i, values[index + 1]))
            else:
                pairs.append(i)
                
    return pairs, is_even

def srt_pairs(values, is_even, t):
    print ("#VALUES: \n %s" % values)
    for i
    

screen = turtle.Screen()
my_turtle = turtle.Turtle(name="main")


test_values = [3, 2, 5, 1, 7, 10, 20, 3, 16, 50, 100, 32, 40, 11, 13, 2, 1, 3, 5, 78, 40]#, 42] #42 == even
#mk_graph(test_values, my_turtle)
pairs, is_even = mk_pairs(test_values)#, my_turtle)

srtd_pairs = srt_pairs(test_values, is_even, my_turtle)
예제 #5
0
import my_turtle
import math

turtle = my_turtle.Turtle()
turtle.turtle(900, 900, 400, 400)

# ### A my_turtle library in a separate file ###

#  ### B Relative vs absolute ###


def star(turtle, n, d):
    for i in range(n):
        # turtle.canvas.show()
        turtle.forward(d)
        if n % 2 == 1:
            turtle.left(180 - 180 / n)
        elif n % 4 == 0:
            turtle.left(180 - 360 / n)
        else:
            turtle.left(180 - 720 / n)


def squares(turtle, n, d, ratio):
    for i in range(n):
        turtle.polygon(4, d)
        turtle.forward(d * (1 - ratio))
        turtle.left(math.atan((1 - ratio) / ratio) * 180 / math.pi)
        d = math.sqrt(math.pow(d * ratio, 2) + math.pow(d * (1 - ratio), 2))