Example #1
0
def SetupClock(radius):  
    # 建立表的外框  
    turtle.reset()  
    turtle.pensize(7)  
    for i in range(60):  
        Skip(radius)  
        if i % 5 == 0:  
            turtle.forward(20)  
            Skip(-radius - 20)  
             
            Skip(radius + 20)  
            if i == 0:  
                turtle.write(int(12), align="center", font=("Courier", 14, "bold"))  
            elif i == 30:  
                Skip(25)  
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))  
                Skip(-25)  
            elif (i == 25 or i == 35):  
                Skip(20)  
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))  
                Skip(-20)  
            else:  
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))  
            Skip(-radius - 20)  
        else:  
            turtle.dot(5)  
            Skip(-radius)  
        turtle.right(6)  
Example #2
0
def initBannerCanvas( numChars , numLines, scale ):
    """
    Set up the drawing canvas to draw a banner numChars wide and numLines high.
    The coordinate system used assumes all characters are 20x20 and there
    are 10-point spaces between them.
    Precondition: The initial canvas is default size, then input by the first
    two user inputs, every input after that defines each letter's scale, probably between
    1 and 3 for the scale values to have the window visible on the screen.
    Postcondition: The turtle's starting position is at the bottom left
    corner of where the first character should be displayed, the letters are printed.
    """
    scale = int(input("scale, integer please"))
    
    # This setup function uses pixels for dimensions.
    # It creates the visible size of the canvas.
    canvas_height = 80 * numLines *scale
    canvas_width = 80 * numChars *scale
    turtle.setup( canvas_width *scale, canvas_height *scale)

    # This setup function establishes the coordinate system the
    # program perceives. It is set to match the planned number
    # of characters.
    height = 30 *scale
    width = 30 * numChars *scale
    margin = 5 # Add a bit to remove the problem with window decorations.
    turtle.setworldcoordinates(
        -margin+1 * scale, -margin+1 * scale, width + margin* scale, numLines*height + margin * scale)

    turtle.reset()
    turtle.up()
    turtle.setheading( 90 )
    turtle.forward( ( numLines - 1 ) * 30 )
    turtle.right( 90 )
    turtle.pensize( 1  *scale)
Example #3
0
def square():
    for i in range(4):
        turtle.forward(100)
        turtle.left(90)
    raw_input('Press Enter')    
    clear()
    turtle.reset()
Example #4
0
def drawCloud(words, num = 20):
    """ Draws a wordcloud with 20 random words, sized by frequency found in 
    the WORDS dictionary. """
    t.reset()
    t.up()
    t.hideturtle()
    topCounts = sorted([words[word] for word in list(words.keys()) if len(word) > 3])
    largest = topCounts[0]
    normalized_counts = {}
    for item in list(words.keys()):
        if len(item) > 3:
            newSize = int(float(words[item]) / largest * 24)
            normalized_counts[item] = newSize
    
    size = t.screensize()
    width_dim = (int(-1 * size[0] / 1.5), int(size[0] / 2))
    height_dim = (int(-1 * size[1] / 1.5), int(size[1] / 1.5))
    

    for item in random.sample(list(normalized_counts.keys()), num):
        t.goto(random.randint(*width_dim), random.randint(*height_dim))
        t.color(random.choice(COLORS))
        try:
            t.write(item, font = ("Arial", int(normalized_counts[item]), "normal"))
        except:
            try:
                t.write(str(item, errors = 'ignore'), font = ("Arial", int(normalized_counts[item]), "normal"))
            except:
                pass
Example #5
0
def drawSootSprite(N, R):
    # reset direction
    turtle.reset()
    # draw star
    drawStar(N, R)
    # draw body
    turtle.dot(0.8*2*R)
    # draw right eyeball
    turtle.fd(0.2*R)
    turtle.dot(0.3*R, 'white')
    # draw right pupil
    turtle.pu()
    turtle.bk(0.1*R)
    turtle.pd()
    turtle.dot(0.05*R)
    turtle.pu()
    # centre
    turtle.setpos(0, 0)
    # draw left eyeball
    turtle.bk(0.2*R)
    turtle.pd()
    turtle.dot(0.3*R, 'white')
    # draw left pupil
    turtle.pu()
    turtle.fd(0.1*R)
    turtle.pd()
    turtle.dot(0.05*R)

    turtle.hideturtle()
Example #6
0
def draw_walk(x, y, speed = 'slowest', scale = 20):
    ''' Animate a two-dimensional random walk.

    Args:
        x       x positions
        y       y positions
        speed   speed of the animation
        scale   scale of the drawing
    '''
    # Reset the turtle.
    turtle.reset()
    turtle.speed(speed)

    # Combine the x and y coordinates.
    walk = zip(x * scale, y * scale)
    start = next(walk)

    # Move the turtle to the starting point.
    turtle.penup()
    turtle.goto(*start)

    # Draw the random walk.
    turtle.pendown()
    for _x, _y in walk:
        turtle.goto(_x, _y)
Example #7
0
def drawStar(N, R):
    turtle.reset()
    a = 360/N
    for i in range(N):
        turtle.fd(R)
        turtle.bk(R)
        turtle.left(a)
Example #8
0
def initBannerCanvas( numChars, numLines ):
    """
    Set up the drawing canvas to draw a banner numChars wide and numLines high.
    The coordinate system used assumes all characters are 20x20 and there
    are 10-point spaces between them.
    Postcondition: The turtle's starting position is at the bottom left
    corner of where the first character should be displayed.
    """
    # This setup function uses pixels for dimensions.
    # It creates the visible size of the canvas.
    canvas_height = 80 * numLines 
    canvas_width = 80 * numChars 
    turtle.setup( canvas_width, canvas_height )

    # This setup function establishes the coordinate system the
    # program perceives. It is set to match the planned number
    # of characters.
    height = 30 
    width = 30  * numChars
    margin = 5 # Add a bit to remove the problem with window decorations.
    turtle.setworldcoordinates(
        -margin+1, -margin+1, width + margin, numLines*height + margin )

    turtle.reset()
    turtle.up()
    turtle.setheading( 90 )
    turtle.forward( ( numLines - 1 ) * 30 )
    turtle.right( 90 )
    turtle.pensize( 2 * scale)
Example #9
0
def spiral():
    n=5
    while n<100:
        turtle.circle(n, 180)
        n +=5
    raw_input('Press Enter')    
    clear()
    turtle.reset()
Example #10
0
def tree(trunkLength,height):
    turtle.speed(1)
    turtle.reset()
    turtle.left(90)
    turtle.pu()
    turtle.backward(200)
    turtle.pd()
    grow(trunkLength,height)
def init_screen():
    # Delete the turtle's drawings from the screen, re-center the turtle and
    # set variables to the default values
    screen = turtle.Screen()
    screen.setup(width=500, height=500)
    screen.title('Yin Yang')
    turtle.reset()
    turtle.bgcolor('#E8E8F6')
    turtle.hideturtle()
Example #12
0
def trianglespiral():
    n=10
    while n<100:
        turtle.forward(n)
        turtle.left(120)
        n +=10
    raw_input('Press Enter')    
    clear()
    turtle.reset()
Example #13
0
def circle():
    import math
    circunference = 2 * math.pi * 10
    n = int(circunference / 3) + 1
    length = circunference / n
    polygon(18, n, length)
    raw_input('Press Enter')
    clear()
    turtle.reset()
Example #14
0
def new():
    """Aids save and load functionality, and provides a 'blank-slate' method.

    Clears the current command list of all commands, refreshes the screen and
    returns the turtle to home.
    """
    global commandList
    commandList = []
    turtle.reset()
Example #15
0
def rectangle():
    for i in range(2):
        turtle.forward(100)
        turtle.left(90)
        turtle.forward(50)
        turtle.left(90)
    raw_input('Press Enter')    
    clear()
    turtle.reset()
Example #16
0
def triangle():
    turtle.forward(100)
    turtle.left(120)
    turtle.forward(100)
    turtle.left(120)
    turtle.forward(100)
    turtle.left(120)
    raw_input('Press Enter')
    clear()
    turtle.reset()
def main():
    """
    :pre:(relative) pos (0,0), heading (east), up
    :post:(relative) pos (X,0), heading (east), up
    :return: none 
    """
    
    numberOfTree=int(raw_input("How many trees in your forest ?"))
    treeHome=["Mapel","Pine","bodhiTree"]
    dummy_house=raw_input("Is there a house in the forest (y/n)?")
    highestHeight=50

    treeHomeRandom=[treeHome[r.randint(0,2)] for n in range(numberOfTree) ]
    if dummy_house in ['Y','y']:
        if numberOfTree>2:
           treeHomeRandom.insert(r.randint(1,numberOfTree-2),"House")
        elif numberOfTree<=2:
             treeHomeRandom.insert(1,"House")  
    if numberOfTree <= 11:
        if dummy_house in ['Y','y']:
          init(-(numberOfTree+1)*100/2,-100)
        else: 
          init(-(numberOfTree)*100/2,-100)
    else:
         init(-600,-100)

    #print(treeHomeRandom)
    totalWood=0
    for myTree in treeHomeRandom:
       (length,totalWood)=treeAndHouse(myTree,totalWood)
       if length>highestHeight:
           highestHeight=length
       t.up()
       t.forward(100)
       t.down()
    t.up()
    t.back(100)
    star2(highestHeight+10)
    
    raw_input("Night is done Press Enter for day")
    
    t.reset()
    print("We have " + str(totalWood) +" units of lumber for building." )
    print ("We will build a house with walls " + str((totalWood)/(2+math.sqrt(2)))+ " tall.")
    init(0,-300)
    house((totalWood)/(2+math.sqrt(2)))
    t.left(90)
    t.forward(3*abs((totalWood)/(2+math.sqrt(2)))/2+30)
    t.right(90)
    maple_shape(30)
    t.right(90)
    t.up()
    t.back(3*abs((totalWood)/(2+math.sqrt(2)))/2+30)
    t.right(90)
    raw_input("Day is done, house is build, Press enter to quit")
Example #18
0
def show_result(convex,usetime,color,algorithm):
    drawpoint(pointset,'black')
    drawpoint(convex,color)
    drawline(convex,color)
    turtle.up()
    #turtle.pensize(400)
    turtle.goto(-60,min_y-30)
    turtle.down()
    turtle.write('%s,use time:%s'%(algorithm,str(usetime)))
    time.sleep(10)
    turtle.reset()
Example #19
0
def squaredspiral():
    n=10
    while n<100:
        turtle.forward(n)
        turtle.left(90)
        turtle.forward(n)
        turtle.left(90)
        n +=10
    raw_input('Press Enter')    
    clear()    
    turtle.reset()
Example #20
0
 def __init__(self,actions,drawColour="black"):
     self.actions = actions
     self.stack = []
     t.setup()
     # Try to make the animation of drawing reasonably fast.
     t.tracer(100,0) # Only draw every 50th update, set delay to zero.
     t.title ("Jose Javier's L System demo")
     t.reset()
     t.degrees()
     t.color(drawColour)
     t.hideturtle() # don't draw the turtle; increase drawing speed.
Example #21
0
def mkHand(name, length):  
    # 注册Turtle形状,建立表针TuConsolartle  
    turtle.reset()  
    Skip(-length * 0.1)  
    # 开始记录多边形的顶点。当前的乌龟位置是多边形的第一个顶点。  
    turtle.begin_poly()  
    turtle.forward(length * 1.1)  
    # 停止记录多边形的顶点。当前的乌龟位置是多边形的最后一个顶点。将与第一个顶点相连。  
    turtle.end_poly()  
    # 返回最后记录的多边形。  
    handForm = turtle.get_poly()  
    turtle.register_shape(name, handForm)  
Example #22
0
def mkHand(name, length):
    #注册turtle形状,建立表针turtle
    turtle.reset()
    Skip(-length*0.1)
    #开始记录多边形的顶点,当前的位置是多边形的第一个顶点
    turtle.begin_poly()
    turtle.forward(length*1.1)
    #停止记录多边形的顶点,当前位置是多边形的最后一个顶点,将于第一个顶点相连
    turtle.end_poly()
    #返回最后记录的多边形
    handForm = turtle.get_poly()
    turtle.register_shape(name, handForm)
Example #23
0
def pentagon():
    turtle.forward(50)
    turtle.left(72)
    turtle.forward(50)
    turtle.left(72)
    turtle.forward(50)
    turtle.left(72)
    turtle.forward(50)
    turtle.left(72)
    turtle.forward(50)
    raw_input('Press Enter')
    clear()
    turtle.reset()
def reset(goal, turtle, info) : 
	turtle.reset()
	turtle.clear()
	goal.reset()
	goal.clear()
	while True :
		goalPos=setGoal(goal)
		pos=turtle.pos()
		if(goalPos[0]<=pos[0]<=goalPos[0]+100 and goalPos[1]<=pos[1]<=goalPos[1]+100) :
			continue
		else :
			info["goalPos"]=goalPos
			info["tracks"]=[turtle.pos()]
			break
Example #25
0
def main():
    t.reset()
    t.down()
    t.speed(22)
    a = 1
    for i in range(1000):
        if a > 0:
            t.pencolor("red")
            a -= 2
        else:
            t.pencolor("blue")
            a += 2
        t.forward(i)
        t.right(98)
Example #26
0
def flowers_3():
    turtle.speed (150)
    # Flower 1
    move_turtle(turtle, -100)
    flowers(turtle, 7, 60.0, 60.0)
    # Flower 2
    move_turtle(turtle, 100)
    flowers(turtle, 10, 40.0, 80.0)
    # Flower 3
    move_turtle(turtle, 100)
    flowers(turtle, 20, 140.0, 20.0)
    raw_input('Press Enter')
    clear()
    turtle.reset()
Example #27
0
def init():

    """
    Initialisation function which takes input from user
    and displays output.
    :pre: (relative) pos (0,0), heading (east), right
    :post: (relative) pos (0,0), heading (east), right
    :return: None
    """

    global totalWood
    global maxHeight
    trees = int(input("How many trees in your forest?"))
    house = input("Is there a house in the forest (y/n)?")
    if trees < 2 and house == "y":
        print("we need atleast two trees for drawing house")
    else:
        turtle.penup()
        turtle.setposition(-330, -100)
        position_of_house = random.randint(1, trees - 1)
        counter = 0
        if house != "y":
            counter = counter + 1
        while counter <= trees:
            if counter == position_of_house and house == "y":
                y = drawHouse(100)
                totalWood = totalWood + y
                spaceBetween(counter, trees)
            else:
                type_of_tree = random.randint(1, 3)
                wood, height = drawTrees(type_of_tree)
                spaceBetween(counter, trees)
                totalWood = totalWood + wood
                if height > maxHeight:
                    maxHeight = height
            counter = counter + 1

        draw_star(maxHeight)
        turtle.hideturtle()
        input("Night is done, press enter for day")
        new_wall_size = calculate_wall_size(totalWood)
        print("We have " + str(totalWood) + " units of lumber for building.")
        print("We will build a house with walls " + str(new_wall_size) + " tall.")
        turtle.reset()
        turtle.penup()
        turtle.setposition(-250, -250)
        drawHouse(new_wall_size)
        draw_sun(3 * new_wall_size / 2)
        turtle.hideturtle()
        input("Day is done, house is built, press enter to quit")
 def setupboundingbox():
     turtle.reset()
     turtle.setup(1100, 1100)
     turtle.screensize(canvwidth=1100, canvheight=1100)
     turtle.up()
     turtle.goto(-500, -500)
     turtle.setheading(90)
     turtle.down()
     turtle.forward(1000)
     turtle.right(90)
     turtle.forward(1000)
     turtle.right(90)
     turtle.forward(1000)
     turtle.right(90)
     turtle.forward(1000)
Example #29
0
def hexagon():
    turtle.forward(50)
    turtle.left(60)
    turtle.forward(50)
    turtle.left(60)
    turtle.forward(50)
    turtle.left(60)
    turtle.forward(50)
    turtle.left(60)
    turtle.forward(50)
    turtle.left(60)
    turtle.forward(50)
    raw_input('Press Enter')
    clear()
    turtle.reset()
Example #30
0
import turtle as p
p.reset()
p.Pen()
p.pencolor('blue')
p.bgcolor('pink')
p.pensize(5)
p.fillcolor('red')
p.begin_fill()

p.left(72)  #(108°-36°)/2=72°
p.forward(150)
p.right(144)  #180-36=144
p.forward(150)
p.right(144)
p.forward(150)
p.right(144)
p.forward(150)
p.right(144)
p.forward(150)

p.end_fill()
"""
知识点:
画五角星
五边形五个顶角读数和=540°
五角形五个顶角读数和=180°,每个角36°


"""
Example #31
0
def WASD(W):
    if (W == "/n"):
        nothing = (".")
    elif (W == "w input"):
        far = input("how many units?")
        far = float(far)
        turtle.forward(far)
    elif(W == 'w'):
        turtle.forward(20)
    elif (W == 'a'):
        turtle.left(90)
    elif (W == 'd'):
            turtle.right(90)
    elif (W == 'ss'):
        turtle.backward(25)
    elif (W == 'c'):
        turtle.clear()
    elif (W == 'r'):
        turtle.reset()
    elif (W == "bgc"):
       color = input("What color?")
       turtle.bgcolor(color)
    elif (W == "shape"):
        shape = input("What shape?")
        turtle.shape(shape)
    elif (W == "pic"):
        pic = input("Type the name of the pic")
        turtle.bgpic(pic)
    elif (W == "efill"):
        turtle.end_fill()
    elif (W == "fill"):
        turtle.begin_fill()
    elif (W == "2x2"):
        WASD("w")
        WASD("a")
        WASD("w")
        WASD("a")
        WASD("w")
        WASD("a")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        
        
    elif (W == "ww"):
        turtle.forward(25)
    elif (W == "www"):
        turtle.forward(100)
    elif (W == "wwww"):
        turtle.forward(200)
    elif (W == "b"):
        return(True)
    elif (W == " "):
        turtle.penup()
        WASD("w")
        turtle.pendown()
    else:
        print("invalid move")
        return ("invalid")
Example #32
0
def drawSecond ():
	turtle.clear()
	turtle.reset()
	turtle.speed(100)
	array = [22, 24, 55, 84, 30]
	adjacentSort(array)
Example #33
0
# https://server.179.ru/tasks/python/old/turtle.html

import turtle  # Подключаем модуль turtle

turtle.reset()  # Приводим черепашку в начальное положение
turtle.down()  # Опускаем перо перо (начало рисования)
turtle.forward(200)  # Проползти 20 пикселей вперед
turtle.left(90)  # Поворот влево на 90 градусов
turtle.forward(200)  # Рисуем вторую сторону квадрата
turtle.left(90)
turtle.forward(200)  # Рисуем третью сторону квадрата
turtle.left(90)
turtle.forward(200)  # Рисуем четвертую сторону квадрата
turtle.up()  # Поднять перо (закончить рисовать)
turtle.forward(100)  # Отвести черепашку от рисунка в сторону
# turtle._root.mainloop() # Задержать окно на экране

turtle.pendown()
turtle.circle(30)
turtle.penup()

turtle.goto(150, 200)
turtle.pendown()
turtle.circle(30)
turtle.penup()

turtle.goto(-70, 200)
turtle.pendown()
turtle.circle(30)

input('Press Enter')
Example #34
0
2.2 pen movement
'''
t.penup()  # alias pu() and up()
t.pendown()  # alias pd() and down()
t.forward(10)  # alias fd()
t.backward(10)  # alias bd()
t.right(10)  # right(radian) alias rt() for right()
t.left(10)  # left(radian)  alias lt() for left()
t.goto(5, 5)  # goto(x, y)    alias setpos() and setposition() for goto()
t.circle(100, 360, 50)  # circle(radius, radian=360, step=0)
# The center is radius units left of the turtle
'''
2.3 pen controller
'''
t.fillcolor('yellow')
t.color('red', 'yellow')  # pencolor() and fillcolor()
t.filling()  # Is current state a filling state?
t.begin_fill()  # begin to fill
t.end_fill()  # end fill
t.hideturtle()  # alias ht() make the arrow of the turtle invisible
t.showturtle()  # alias st() make the arrow of the turtle visible
'''
2.4 global control command
'''
t.clear()  # clear windows but perverse current state of turtle
t.reset()  # clear windows and reset turtle state
t.undo()  # undo last operation
t.isvisible()  # return
# stamp()       # copy current graphics
t.done()  # end turtle
Example #35
0
def drawSquareLoop():
    for num in range(4):
        turtle.forward(100)
        turtle.left(90)
    turtle.reset()
Example #36
0
def drawCircle():
    turtle.circle(90)
    turtle.reset()
Example #37
0
puzzle_3 = [[0, 0, 0, 0], [2, 3, 4, 1], [3, 4, 1, 2],
            [0, 0, 0,
             0]]  # Solution: [[4,1,2,3],[2,3,4,1],[3,4,1,2],[1,2,3,4]]
puzzle_4 = [[0, 2, 4, 0], [1, 0, 0, 3], [4, 0, 0, 2],
            [0, 1, 3,
             0]]  # Solution: [[3,2,4,1],[1,4,2,3],[4,3,1,2],[2,1,3,4]]
puzzle_5 = [[0, 4, 2, 0], [2, 0, 0, 0], [0, 0, 0, 3],
            [0, 3, 1,
             0]]  # Solution: [[3,4,2,1],[2,1,3,4],[1,2,4,3],[4,3,1,2]]

all_puzzles = [puzzle_1, puzzle_2, puzzle_3, puzzle_4, puzzle_5]

# ---------------------------------------------   Start the game   ---------------------------------------------------------- #

while True:
    turtle.reset()  # Start with a clean canvas in case user wants to replay
    setWorld()
    game_won = False
    turtle.pd()
    drawGrid()

    # --------- Draw the lines in bold, across and down -------- #
    turtle.pu()
    turtle.goto(-75, 0)
    turtle.pd()
    turtle.fd(150)
    turtle.pu()
    turtle.goto(0, 75)
    turtle.lt(270)
    turtle.pd()
    turtle.fd(150)
Example #38
0
def hpy_d790d7aad797d79c():
    """אתחל את לוח הציור"""
    turtle.reset()
Example #39
0
def main():
    turtle.pensize(5)
    turtle.speed(0)
    init_turtle()
    legend_region()

    general_data = read_data("worldbank_life_expectancy")

    data_asia = filter_region(general_data, "South Asia")
    data_middle = filter_region(general_data, "Middle East & North Africa")
    data_europe = filter_region(general_data, "Europe & Central Asia")
    data_america = filter_region(general_data, "North America")
    data_caribbean = filter_region(general_data, "Latin America & Caribbean")
    data_pacific = filter_region(general_data, "East Asia & Pacific")
    data_africa = filter_region(general_data, "Sub-Saharan Africa")

    plot_line(data_asia, "red")
    turtle.up()
    turtle.goto(-350, -300)
    plot_line(data_middle, "black")
    turtle.up()
    turtle.goto(-350, -300)
    plot_line(data_europe, "green")
    turtle.up()
    turtle.goto(-350, -300)
    plot_line(data_america, "yellow")
    turtle.up()
    turtle.goto(-350, -300)
    plot_line(data_caribbean, "orange")
    turtle.up()
    turtle.goto(-350, -300)
    plot_line(data_pacific, "purple")
    turtle.up()
    turtle.goto(-350, -300)
    plot_line(data_africa, "blue")

    next_graph = input("Hit enter to see income graph: ")
    if next_graph == "":
        turtle.reset()

    turtle.speed(0)
    turtle.pensize(5)
    init_turtle()
    legend_income()

    data_low = filter_income(general_data, "Low income")
    data_upper = filter_income(general_data, "Upper middle income")
    data_lower = filter_income(general_data, "Lower middle income")
    data_high = filter_income(general_data, "High income")

    plot_line(data_low, "blue")
    turtle.up()
    turtle.goto(-350, -300)
    plot_line(data_upper, "red")
    turtle.up()
    turtle.goto(-350, -300)
    plot_line(data_lower, "green")
    turtle.up()
    turtle.goto(-350, -300)
    plot_line(data_high, "orange")

    turtle.done()
def main(show_AI = False):
    """

    :param show_AI:
    :return:
    """
    tt.bgcolor(0, 0, .25)
    # see_play_game(Human(), Game())

    players = []
    survival = []
    best_player = None
    if show_AI:
        for i in range(20):
            players.append(neural_simple.AI())
            tt.title(i)
            survival.append(see_AI_play_game(players[i], Game()))

        for round in range(300):
            best = 0
            highest = survival[0]
            for j in range(len(survival)):
                if survival[j] > highest:
                    best = j
                    highest = survival[j]
            best_player = players[best]
            players = []
            survival = []
            for j in range(20):
                tt.title(i)
                players.append(neural_simple.AI(best_player))
                survival.append(see_AI_play_game(players[j], Game()))
            best_player = players[best]
            tt.reset()
            Eat.print.print_player(best_player)
            time.sleep(1)

    if not show_AI:
        for i in range(20):
            players.append(neural_simple.AI())
            tt.title(i)
            survival.append(see_play_game(players[i], Game()))

        for round in range(300):
            best = 0
            highest = survival[0]
            for j in range(len(survival)):
                if survival[j] > highest:
                    best = j
                    highest = survival[j]
            best_player = players[best]
            players = []
            survival = []
            for j in range(20):
                tt.title(i)
                players.append(Eat.neural_simple.AI(best_player))
                survival.append(see_play_game(players[j], Game()))
            best_player = players[best]
            tt.reset()
            Eat.print.print_player(best_player)
            time.sleep(1)
    input()
    see_play_game(best_player, Game())
    Eat.print.print_player(best_player)
Example #41
0
def init():
    t.reset()
    t.up()
Example #42
0
def WASD(W):
    if (True):
        if (True):
            if (True):
                print("-")
                if (W == "w"):
                    turtle.forward(50)
                elif (W == "a"):
                    turtle.left(90)
                elif (W == "s"):
                    turtle.right(180)
                    turtle.forward(25)
                elif (W == "d"):
                    turtle.right(90)
                elif (W == "ss"):
                    turtle.backward(25)
                elif (W == "c"):
                    turtle.clear()
                elif (W == "r"):
                    turtle.reset()
                elif (W == "bgc"):
                    color = input("What color?")
                    turtle.bgcolor(color)
                elif (W == "shape"):
                    shape = input("What shape?")
                    turtle.shape(shape)
                elif (W == "pic"):
                    pic = input("Type the name of the pic")
                    turtle.bgpic(pic)
                elif (W == "efill"):
                    turtle.end_fill()
                elif (W == "sleep"):
                    print("Going to Sleep")
                    WASD("st")
                    wer = 0
                    while (wer < 10):
                        WASD("a")
                        wer = (wer + 1)
                    WASD("ht")
                    WASD("bcb")
                    input()
                    wer = 0
                    while (wer < 10):
                        WASD("a")
                        wer = (wer + 1)
                    WASD("ht")
                    WASD("r")
                    WASD("ht")
                    turtle.bgcolor("white")
                    WASD("stop")
                elif (W == "shutdown script"):
                    print("Running Shutdown Scripts")
                    turtle.shape("turtle")
                    wer = 0
                    WASD("st")
                    while (wer < 10):
                        WASD("a")
                        wer = (wer + 1)
                    WASD("ht")
                    #                 turtle.bgpic("shutdown")
                    WASD("bcb")
                    WASD("www")
                    WASD("d")
                    WASD("ww")
                elif (W == "fill"):
                    turtle.begin_fill()
                elif (W == "stop"):
                    return (3)
                elif (W == "bcb"):
                    turtle.bgcolor("black")
                elif (W == "2x2"):
                    WASD("w")
                    WASD("a")
                    WASD("w")
                    WASD("a")
                    WASD("w")
                    WASD("a")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")

                elif (W == "ww"):
                    turtle.forward(25)
                elif (W == "www"):
                    turtle.forward(100)
                elif (W == "wwww"):
                    turtle.forward(200)
                elif (W == "bgw"):
                    turtle.bgcolor("white")
                elif (W == "w2"):
                    turtle.forward(9500)
                elif (W == "w1"):
                    turtle.forward(4750)
                elif (W == "ht"):
                    turtle.ht()
                elif (W == "st"):
                    turtle.st()
                else:
                    print("invalid move")
            else:
                print("")
        else:
            print("")

    else:
        print("")
Example #43
0
turtle.pensize(12)  #绘制时的宽度
turtle.color('red')  #绘制时的颜色
turtle.fillcolor('red')  #绘制的填充颜色
turtle.fill(t)
turtle.fill(t)
degree = 22
speed = 10
turtle.forward(degree)  #向前移动距离degree代表距离
turtle.backward(degree)  #向后移动距离degree代表距离
turtle.right(degree)  #向右移动多少度
turtle.left(degree)  #向左移动多少度
turtle.goto(20, 40)  #将画笔移动到坐标为x,y的位置
turtle.stamp()  #复制当前图形
turtle.speed(speed)  #画笔绘制的速度范围[0,10]整数
turtle.clear()  #清空turtle画的笔迹
turtle.reset()  #清空窗口,重置turtle状态为起始状态
turtle.undo()  #撤销上一个turtle动作
turtle.isvisible()  #返回当前turtle是否可见
turtle.stamp()  #复制当前图形
turtle.write('string')  #写字符串'string'

turtle.circle(10)  #画一个R为10的圆形
turtle.circle(30, 270)  #圆弧为270度
turtle.circle(20, steps=3)  #画一个R为20的圆内切多边形

# line = 50
# for x in range(25):
#     if x % 5 ==0:
#         line += 20
#     turtle.forward(line)
#     turtle.right(144)
Example #44
0
def main():

    #define variables and objects
    list = []
    requiredColors = ["red", "yellow", "blue", "green"]

    # Create a loop
    loop = True
    while loop:

        # Create user menu
        print("(1)Enter Circle")
        print("(2)Enter Rectangle")
        print("(3)Remove Shape")
        print("(4)Draw Shapes")
        print("(5)Exit")
        menu = int(input("Select an option from the menu above (1-5): "))

        # Create menu for circle
            # User inputs position, radius, and color. The position is the CENTER of the circle
        if menu == 1:
            x, y, radius = eval(input("Enter the circles position (x,y) and radius: "))
            # Allow red, yellow, blue, and green only
            color = input("Enter the circles color (red, yellow, green, or blue): ")
            # Make sure that the color fits parameters
            while color != requiredColors:
                color = input("Must be red, yellow, green, or blue: ")
                if requiredColors.count(color) > 0:
                    break
            # Use the class
            circle = Circle(x, y, radius, color)
            # Add the object to the list
            list.append(circle)

        # Create menu for rectangle
            # User inputs position, height, width, color. The position is the lower left-hand corner
        elif menu == 2:
            x, y, height, width = eval(input("Enter the rectangles position (x,y), height and width: "))
            # Allow red, yellow, blue, and green only
            color = input("Enter the circles color (red, yellow, green, or blue): ")
            # Make sure that the color fits parameters
            while color != "red" or "yellow" or "green" or "blue":
                color = input("Must be red, yellow, green, or blue: ")
                if color == "red" or "yellow" or "green" or "blue":
                    break
            # Use the class
            rectangle = Rectangle(x, y, height, width, color)
            # Add the object to the list
            list.append(rectangle)

        # Show the number of items in the list and let the user enter a number and remove that shape from the list.
        elif menu == 3:
            # Show the list
            print(list)
            # Ask the user to remove an object from the list
            remove = int(input("What object would you like to remove from the list?: "))
            # Use pop to remove object from the list
            list.pop(remove - 1)
            print(list)

        elif menu == 4:
            # Clear the screen before drawing
            turtle.reset()
            for i in list:
                i.draw()
        # Exit the program
        else:
            break
Example #45
0
def drawThird ():
	turtle.clear()
	turtle.reset()
	turtle.speed(100)
	array = [12, 34, 99, 55, 20]
	adjacentSort(array)
Example #46
0
def drawFirst ():
	turtle.clear()
	turtle.reset()
	turtle.speed(100)
	array = [22, 11, 99, 88, 10]
	adjacentSort(array)
Example #47
0
print("Do you want to change square size ?")
turtle.bgcolor("gray")
turtle.color("black", "olive")
turtle.pensize(5)

turtle.begin_fill()
turtle.shape("square")  # create the square using shape method.
turtle.shapesize(15)  #shape size.
turtle.end_fill()

print()

b = int(input("So, enter the value for square in px : ")
        )  # Enter the any interger value for area of square.

turtle.reset()  #reset the python turtle graphic

print()

print('"Thank you, you can check your square in python turtle graphic."')

d = b * b  # area of square

window = turtle.Screen()  # Pop up a new window using turtle screen method.

# resizeable square
turtle.bgcolor("gray")
turtle.color("black", "olive")
turtle.pensize(5)

turtle.begin_fill()
        draw_2(length, level - 1)


def turn_left(width, step, draw):
    for _ in range(4):
        draw(width, step)
        turtle.left(90)


def turn_right(width, step, draw):
    for _ in range(4):
        draw(width, step)
        turtle.right(90)


# --- main ---

# clear everything
turtle.reset()

# the fastest turtle
turtle.speed(0)

turn_left(300, 3, draw_2)

# hide turtle
turtle.hideturtle()

# keep open window
turtle.exitonclick()
Example #49
0
        tur.pu()
        tur.goto(startx, starty)
        tur.pd()
        tur.goto(endx, endy)
        return
    thirdx = fullx / 3
    thirdy = fully / 3
    Ax = thirdx + startx
    Ay = thirdy + starty
    Cx = 2 * thirdx + startx
    Cy = 2 * thirdy + starty
    Bx, By = rotate([Ax, Ay], [startx, starty], -math.pi / 1.5)
    line(startx, starty, Ax, Ay)
    line(Ax, Ay, Bx, By)
    line(Bx, By, Cx, Cy)
    line(Cx, Cy, endx, endy)


length = 200
rt3 = math.sqrt(3)
while True:
    tur.ht()
    tur.speed(0)
    tur.color("cyan")
    tur.bgcolor("black")
    line(-length * rt3, length, length * rt3, length)
    line(length * rt3, length, 0, -length * 2)
    line(0, -length * 2, -length * rt3, length)
    time.sleep(10)
    tur.reset()
Example #50
0
def reset():
    # erase all of the targets
    turtle.reset()
    turtle.speed(0)
Example #51
0
import turtle  # turtle.reset()
from turtle import *  # reset()

#    from turtle import as t

#    print(dir(turtle))   # список всех имён, определённых в модуле

turtle.reset()  # отобразить холст
turtle.shape("turtle")
turtle.shapesize(3, 3)

turtle.pensize(5)
turtle.color("red")
turtle.penup()

turtle.speed(1)
turtle.forward(10)
turtle.left(90)
turtle.forward(10)

turtle.done()
Example #52
0
tl.pencolor('green')

tl.up()
tl.goto(-150, -150)
tl.down()
# shift turtle
tl.forward(100)
tl.left(90)
tl.forward(100)
tl.right(90)
tl.forward(50)
tl.backward(100)

tl.dot(20)

tl.reset()
# change turtle
tl.shape('turtle')
# control turtle speed
tl.speed(2)
tl.forward(100)
tl.speed(10)
tl.right(90)
tl.forward(100)

tl.reset()

tl.pen(pencolor='red', fillcolor='green', pensize=5, speed=5)
tl.begin_fill()
tl.circle(100)
tl.end_fill()
Example #53
0
import turtle as t

t.circle(80,180)
t.reset()
r.circle(80,90)
t.right(30)
t.left(30)
t.left 
Example #54
0
up()
#delay(10)
speed(0)
bgcolor("white")

fd(270)
lt(90)
down()
begin_poly()
draw_7_shape(270, 190)
lt(90)
fd(380)
lt(90)
draw_7_shape(190, 110)
lt(90)
fd(240)
lt(90)
draw_7_shape(110, 20)
#sleep(5)
end_poly()

spir = get_poly()
register_shape("spiral", spir)
shape("spiral")
reset()
speed(0)
fillcolor("black")
while True:
    rt(2)
#done()
Example #55
0
	turtle.right(195)
	turtle.pendown()
	turtle.forward(140)
	turtle.left(180)
	turtle.forward(70)
	turtle.left(45)
	turtle.penup()
	turtle.forward(20)
	turtle.right(45)
	turtle.pendown()
	turtle.circle(50)turtle.goto(-300,100)
	
SyntaxError: invalid syntax
>>> turtle.reset
<function reset at 0x00000183D2693040>
>>> turtle.reset()
>>> turtle.goto(-300,100)
>>> turtle.undo()
>>> turtle.penup()
>>> turtle.goto(-300,100)
>>> turtle.pendown()
>>> for n in range(1) :
	hhh()

	
>>> def hhh() :
	turtle.forward(100)
	turtle.left(195)
	turtle.penup()
	turtle.forward(120)
	turtle.right(195)
Example #56
0
def restart():
    turtle.reset()
    turtle.stamp()
Example #57
0
def restart():
    turtle.reset()
def name_input():
    while True:
        name = raw_input("Enter the Name: ")
        list(name)
        print(name)
        turtle.reset()
        turtle.speed("fastest")
        turtle.pensize(10)
        space(-(len(name) / 2 * 100))
        for i in name:
            shape_color = color[randint(0, len(color) - 1)]
            turtle.color(shape_color)
            if i == "A" or i == "a":
                A()
            elif i == "B" or i == "b":
                B()
            elif i == "C" or i == "c":
                C()
            elif i == "D" or i == "d":
                D()
            elif i == "E" or i == "e":
                E()
            elif i == "F" or i == "f":
                F()
            elif i == "G" or i == "g":
                G()
            elif i == "H" or i == "h":
                H()
            elif i == "I" or i == "i":
                I()
            elif i == "J" or i == "j":
                J()
            elif i == "K" or i == "k":
                K()
            elif i == "L" or i == "l":
                L()
            elif i == "M" or i == "m":
                M()
            elif i == "N" or i == "n":
                N()
            elif i == "O" or i == "o":
                O()
            elif i == "P" or i == "p":
                P()
            elif i == "Q" or i == "q":
                Q()
            elif i == "R" or i == "r":
                R()
            elif i == "S" or i == "s":
                S()
            elif i == "T" or i == "t":
                T()
            elif i == "U" or i == "u":
                U()
            elif i == "V" or i == "v":
                V()
            elif i == "W" or i == "w":
                W()
            elif i == "X" or i == "x":
                X()
            elif i == "Y" or i == "y":
                Y()
            elif i == "Z" or i == "z":
                Z()
 def do_reset(self, arg):
     'Clear the screen and return turtle to center:  RESET'
     turtle.reset()
 def __setScreen(self):
     """set the screen/window depending on view static attributes."""
     turtle.resizemode('noresize')
     self.width = self.GRID_MARGINLEFT + 2 * self.gridWidth + self.GAP_BETWEEN_GRIDS + self.GRID_MARGINRIGHT
     self.height = self.GRID_MARGINTOP + self.gridWidth + self.GRID_MARGINBOTTOM
     turtle.setup(width=self.width + 10, height=self.height + 10)
     turtle.screensize(self.width, self.height)
     turtle.bgpic("Ressources/fire_ocean.gif")
     turtle.reset()