Ejemplo n.º 1
0
def roof(x, y, fill, pen_colour="black", fill_color="white"):
    turtle.pensize(thick_pen)
    position(x, y)
    turtle.color(pen_colour, fill_color)
    turtle.fill(fill)
    turtle.seth(80)
    turtle.forward(85)
    turtle.right(80)
    turtle.forward(330)
    turtle.right(80)
    turtle.forward(85)
    turtle.right(100)
    turtle.forward(360)
    turtle.right(260)
    turtle.fill(False)
    position(x + 6, y + 32)
    for i in range(4):
        turtle.circle(23, 152)
        turtle.seth(284)
        turtle.circle(22, 152)
        turtle.seth(284)
    position(x + 11, y + 64)
    for i in range(8):
        turtle.circle(21.5, 152)
        turtle.seth(284)
Ejemplo n.º 2
0
def draw_triangle(turtle, length, fill):
    """Draw triange with given side length."""
    turtle.fill(fill)
    for side in xrange(0, 3):
        turtle.forward(length)
        turtle.left(120)
    turtle.fill(False)
Ejemplo n.º 3
0
def grassland():
    #Likewise, I draw a big rectangle on the bottom of the page and color it green
    turtle.color('peru')
    turtle.fill(True)
    block(-400, -500, 1000, 400)
    turtle.fill(False)
    turtle.color("black")
Ejemplo n.º 4
0
def putBlock(block):
    label = block[0]
    p = []
    for coord in block[1:]:
        p = p + coord

    color = fetchColor(label)

    turtle.fill(True)
    turtle.fillcolor(color)
    turtle.penup()

    k = p[0]
    turtle.setpos(k[0], k[1])
    turtle.pendown()
    for i in range(0, len(p)):
        k = p[i]
        turtle.setpos(k[0], k[1])
    k = p[0]
    turtle.setpos(k[0], k[1])

    turtle.fill(False)
    turtle.penup()

    return
Ejemplo n.º 5
0
def Sierpinski(side, steps):
    """Draw a Sierpinski triangle fractal, recursing the given number of steps.
       Assume we're starting from a black triangle of with sides of size side*2,
       point down, with the turtle at the bottom point.
    """
    if not steps:
        return

    # Clear a white triangle in the center.
    turtle.setheading(120)
    turtle.penup()
    turtle.forward(side)

    turtle.pendown()
    turtle.fill(True)
    turtle.fillcolor("white")
    turtle.right(120)
    turtle.forward(side)
    turtle.left(120)
    turtle.forward(side)
    turtle.left(120)
    turtle.forward(side)
    turtle.fill(False)

    # For each of the black sub-triangles left, run recursively.
    Sierpinski(side/2, steps-1)
    turtle.setheading(0)
    turtle.penup()
    turtle.forward(side)
    Sierpinski(side/2, steps-1)
    turtle.setheading(240)
    turtle.penup()
    turtle.forward(side)
    Sierpinski(side/2, steps-1)
Ejemplo n.º 6
0
def sky():
    #I draw a big rectangle on the top of the page and color it blue
    turtle.color(0.0, 1.0, 1.0)
    turtle.fill(True)
    block(-500, -100, 1000, 1000)
    turtle.fill(False)
    turtle.color("black")
def draw_triangle(turtle, length, fill):
    """Draw triange with given side length."""
    turtle.fill(fill)
    for side in xrange(0,3):
        turtle.forward(length)
        turtle.left(120)
    turtle.fill(False)
Ejemplo n.º 8
0
def Sierpinski(side, steps):
    """Draw a Sierpinski triangle fractal, recursing the given number of steps.
       Assume we're starting from a black triangle of with sides of size side*2,
       point down, with the turtle at the bottom point.
    """
    if not steps:
        return

    # Clear a white triangle in the center.
    turtle.setheading(120)
    turtle.penup()
    turtle.forward(side)

    turtle.pendown()
    turtle.fill(True)
    turtle.fillcolor("white")
    turtle.right(120)
    turtle.forward(side)
    turtle.left(120)
    turtle.forward(side)
    turtle.left(120)
    turtle.forward(side)
    turtle.fill(False)

    # For each of the black sub-triangles left, run recursively.
    Sierpinski(side / 2, steps - 1)
    turtle.setheading(0)
    turtle.penup()
    turtle.forward(side)
    Sierpinski(side / 2, steps - 1)
    turtle.setheading(240)
    turtle.penup()
    turtle.forward(side)
    Sierpinski(side / 2, steps - 1)
Ejemplo n.º 9
0
def redSquare():
    turtle.color("red")
    turtle.fill(True)
    for i in range(4):
        turtle.forward(20)
        turtle.right(90)
    turtle.fill(False)
    turtle.forward(20)
Ejemplo n.º 10
0
def planet():
    turtle.color('black')
    turtle.goto(0, -5000)
    turtle.down()
    turtle.fill(True)
    turtle.circle(2380)
    turtle.fill(False)
    turtle.up()
Ejemplo n.º 11
0
def planet():
	turtle.color('black')
	turtle.goto(0,-5000)
	turtle.down()
	turtle.fill(True)
	turtle.circle(2380)
	turtle.fill(False)	
	turtle.up()
Ejemplo n.º 12
0
def blackSquare():
    turtle.color("black")
    turtle.fill(True)
    for i in range(4):
        turtle.forward(20)
        turtle.right(90)
    turtle.fill(False)
    turtle.forward(20)
Ejemplo n.º 13
0
def main():
	turtle.color('red')
	turtle.heading()
	turtle.left(80)
	turtle.speed(5)
	turtle.pendown()
	turtle.fill(True)

	turtle.circle(30,90)
Ejemplo n.º 14
0
def drawSpring(xpos, ypos):
    turtle.fillcolor(0.5, 1, 1)

    turtle.setpos(xpos, ypos)
    turtle.fill(True)
    turtle.circle(10)
    turtle.fill(False)
    turtle.setpos(xpos, ypos)
    return
def draw_unfilled_square(size, loop_range):    
    """Draw a square by drawing a line and turning through 90 degrees 4 times"""
    turtle.pendown()
    turtle.fill(False)
    for _ in range(loop_range):
        turtle.forward(size)
        turtle.left(90)
    turtle.fill(False)
    turtle.penup()   
Ejemplo n.º 16
0
def main():
    turtle.color('red')
    turtle.heading()
    turtle.left(80)
    turtle.speed(5)
    turtle.pendown()
    turtle.fill(True)

    turtle.circle(30, 90)
Ejemplo n.º 17
0
 def sun(self, x, y, r):
     '''
 	Creates a yellow circular sun at position (x,y) with radius r
 	'''
     turtle.fill(True)
     self.color('yellow')
     self.place(x, y, 0)
     turtle.circle(r)
     turtle.fill(False)
Ejemplo n.º 18
0
def draw_unfilled_square(size, loop_range):
    """Draw a square by drawing a line and turning through 90 degrees 4 times"""
    turtle.pendown()
    turtle.fill(False)
    for _ in range(loop_range):
        turtle.forward(size)
        turtle.left(90)
    turtle.fill(False)
    turtle.penup()
Ejemplo n.º 19
0
def radar_chart(data):
    # Some "typical" test data
    #print "Hello"
    length=len(data) # stores the length of the data provided
    turtle.home()   # Sets the turtle to position (0,0)
    division=360/length #what angle is needed for invidual lines
    poslist=[] #list to store current position
    valpos=[]   #list to store position
    j=0
    turtle.hideturtle() #hides the arrow
        #Draw the foundation of the Radar Chart
    for i in range(length): # Loop until all the given data is plotted
        turtle.forward(200) #move turtle forward
        turtle.dot(10,"black") # Draw the black dot at the end of each data
        nowpos=turtle.pos() # store the current position
        poslist.append(nowpos) #append the current position to list
        #turtle.hideturtle()
        turtle.setpos(nowpos[0]+10,nowpos[1]) #get the turtle to new postion to write data
        turtle.write(data[i], True, align="center") # Write the label of data
        turtle.setpos(nowpos[0],nowpos[1]) #return to the previous position
        turtle.back(200) #return home
        turtle.left(division) # rotate by the specific angle
    turtle.home()    # return to turtle home
    #Connect the ends points of the radar chart
    for i in poslist: #
        turtle.setpos(i[0],i[1])
        #turtle.setpos(i[j],i[j+1])
        #turtle.forward(100)
        #turtle.home()
        #turtle.degree(division)
        #turtle.heading()
        #turtle.forward(100)
    turtle.setpos(poslist[0][0],poslist[0][1])
    turtle.home()
    #Draw green Dots 
    for i in range(length):
        incval=data[i]
        turtle.forward(incval*2)
        turtle.dot(15,"green")
        nowpos=turtle.pos()
        valpos.append(nowpos) 
        turtle.back(incval*2)
        turtle.left(division)
    turtle.begin_poly()
    turtle.fill(True)
    #Fill the green Dots
    for i in valpos:
        turtle.setpos(int(i[0]),int(i[1]))
    turtle.setpos(valpos[0][0],valpos[0][1])
    turtle.end_poly()
    p = turtle.get_poly()
    turtle.register_shape("jpt", p)
    turtle.color("Green", "Green")
    turtle.begin_fill()
    #turtle.p(80)
    turtle.end_fill()
    turtle.fill(False)
def square_with_color(side_length, color, fillIt=False):
    turtle.color(t_color)  ## Makes the shape the selected color
    turtle.fill(fillIt)  ## Will fill in shape with color if fillit==True
    for i in range(4):
        turtle.forward(side_length)
        turtle.left(90)

    turtle.fill(fillIt)

    return
Ejemplo n.º 21
0
def draw_triangle(turtle,length,fill):
    i=0
    if (fill):
        turtle.fill(True)
    while (i<3):
        turtle.forward(length)
        turtle.left(120)
        i=i+1
    if (fill):
        turtle.fill(False)
Ejemplo n.º 22
0
 def draw(self):
     t.penup()
     t.goto(self.x, self.y)
     t.pendown()
     t.begin_fill()
     t.width(7)
     t.color(self.color)
     t.fill(self.fill)
     t.circle(self.r)
     t.end_fill()
def draw_wand(size):
    turtle.fill(True)
    turtle.setheading(90)
    turtle.forward(size)
    turtle.right(90)
    turtle.forward(size / 25)
    turtle.right(90)
    turtle.forward(size)
    turtle.right(90)
    turtle.forward(size / 25)
    turtle.fill(False)
Ejemplo n.º 24
0
 def tegnCelle(i,j,farve):
     x,y = toXY(i,j)
     tt.goto(x+1,y+1)
     tt.setheading(0) # øst
     tt.color(farve)
     tt.fill(True)
     tt.pendown()
     for k in range(4):
         tt.forward(cs-2)
         tt.left(90)
     tt.fill(False)
     tt.penup()
Ejemplo n.º 25
0
 def tegnCelle(i, j, farve):
     x, y = toXY(i, j)
     tt.goto(x + 1, y + 1)
     tt.setheading(0)  # øst
     tt.color(farve)
     tt.fill(True)
     tt.pendown()
     for k in range(4):
         tt.forward(cs - 2)
         tt.left(90)
     tt.fill(False)
     tt.penup()
Ejemplo n.º 26
0
def drawTown(xpos, ypos):
    turtle.fillcolor(1, 0, 0)
    turtle.fill(True)
    turtle.setpos(xpos, ypos)
    turtle.setpos(xpos - 7, ypos)
    turtle.setpos(xpos - 7, ypos + 10)
    turtle.setpos(xpos - 10, ypos + 10)
    turtle.setpos(xpos, ypos + 20)
    turtle.setpos(xpos + 10, ypos + 10)
    turtle.setpos(xpos + 7, ypos + 10)
    turtle.setpos(xpos + 7, ypos)
    turtle.setpos(xpos, ypos)
    return
Ejemplo n.º 27
0
def monolith():
    x = -175  #top left
    y = 125
    turtle.color('black')
    turtle.goto(x, y)
    turtle.down()
    turtle.fill(True)
    turtle.goto(x + 100, y)
    turtle.goto(x + 100, y - 200)
    turtle.goto(x, y - 200)
    turtle.goto(x, y)
    turtle.fill(False)
    turtle.up()
Ejemplo n.º 28
0
def monolith():
	x = -175 #top left
	y = 125
	turtle.color('black')
	turtle.goto(x,y)
	turtle.down()
	turtle.fill(True)
	turtle.goto(x+100,y)
	turtle.goto(x+100,y-200)
	turtle.goto(x,y-200)
	turtle.goto(x,y)
	turtle.fill(False)
	turtle.up()
Ejemplo n.º 29
0
def target():
    turtle.speed(.3)
    r = 100
    i = 0
    while i < 5:
        if i % 2 == 0:
            turtle.color("red")
            turtle.fill(True)
            turtle.circle(r)
            turtle.penup()
            turtle.left(90)
            turtle.forward(20)
            turtle.right(90)
            turtle.pendown()
            turtle.fill(False)
        else:
            turtle.color("white")
            turtle.fill(True)
            turtle.circle(r)
            turtle.penup()
            turtle.left(90)
            turtle.forward(20)
            turtle.right(90)
            turtle.pendown()
            turtle.fill(False)

        i = i + 1
        r = r - 20
Ejemplo n.º 30
0
def circle(x,
           y,
           radius,
           angle,
           size,
           fill=False,
           pen_colour="black",
           fill_colour="white"):
    turtle.pensize(size)
    turtle.color(pen_colour, fill_colour)
    position(x, y)
    turtle.fill(fill)
    turtle.circle(radius, angle)
    turtle.fill(False)
Ejemplo n.º 31
0
def love(size, shape, color):
    """ Draws a single heart"""
    t.pensize(5)
    t.pencolor(color)
    t.fillcolor(color)
    radius = size * sin(shape * pi / 180) / (1 + sin((90 - shape) * pi / 180))
    t.fill(True)
    t.left(shape)
    t.forward(size)
    t.circle(radius, 180 + shape)
    t.right(180)
    t.circle(radius, 180 + shape)
    t.forward(size)
    t.left(180 - shape)
    t.fill(False)
Ejemplo n.º 32
0
def striangle(depth,base):
   turtle.down()
   if depth == 0:
      turtle.fill(1)
      for i in 0,1,2:
         turtle.forward(base)
         turtle.left(120)
      turtle.fill(0)
   else:
      for i in 0,1,2:
         striangle(depth-1,base)
         turtle.up()
         turtle.forward(base*2**depth)
         turtle.left(120)
         turtle.down()
Ejemplo n.º 33
0
def stars():
	starpos = []
	turtle.color('white')
	for n in range(1,5000):
		x = random.randrange(-500,500)
		y = random.randrange(-500,500)
		starpos.append((x,y))
	for star in starpos:
		turtle.up()
		turtle.goto(star)
		turtle.down()
		turtle.fill(True)
		turtle.circle(0.1)
		turtle.fill(False)
		turtle.up()
Ejemplo n.º 34
0
def stars():
    starpos = []
    turtle.color('white')
    for n in range(1, 5000):
        x = random.randrange(-500, 500)
        y = random.randrange(-500, 500)
        starpos.append((x, y))
    for star in starpos:
        turtle.up()
        turtle.goto(star)
        turtle.down()
        turtle.fill(True)
        turtle.circle(0.1)
        turtle.fill(False)
        turtle.up()
Ejemplo n.º 35
0
def flowers(x, y):
    position(x + 109, y + 12)
    turtle.seth(90)
    turtle.color("#8b0000", "#DC143C")
    turtle.fill(True)
    turtle.pensize(thin_pen)
    for i in range(6):
        turtle.forward(5)
        turtle.circle(8.5, 180)
        turtle.forward(5)
        turtle.seth(90)
    turtle.right(90)
    turtle.forward(100)
    turtle.fill(False)
    rectangle(x, y, 12, 115, thin_pen, 90, True, "#003d00", "#006500")
Ejemplo n.º 36
0
def drawRuin(xpos, ypos):

    turtle.fillcolor(0.95, 0.95, 0.95)
    turtle.fill(True)
    turtle.setpos(xpos - 5, ypos)
    turtle.setpos(xpos - 5, ypos + 10)
    turtle.setpos(xpos, ypos + 15)
    turtle.setpos(xpos + 5, ypos + 20)
    turtle.setpos(xpos + 5, ypos)
    turtle.setpos(xpos - 5, ypos)
    turtle.fill(False)
    turtle.setpos(xpos - 10, ypos)
    turtle.setpos(xpos + 10, ypos)

    return
Ejemplo n.º 37
0
def dessiner(chaine, distance, angle, position, direction, xpos, ypos):
    """Fonction qui dessine la chaine qu'on lui donne en entrée"""
    import turtle as tt
    import random as rd
    L = []
    wasdown = tt.isdown()  # on vérifie si il faut dessiner ou pas
    tt.penup()
    #on "lève le crayon" pour ne pas dessiner lorsque l'on initialise la tortue
    tt.setheading(direction)
    tt.goto(position
            )  #on commence à la position voulue et avec la direction voulue
    if wasdown:
        tt.pendown()
    tt.speed(0)  #on prend la vitesse maximale de la tortue
    tt.hideturtle()  #on cache le curseur
    for k in chaine:
        # On peut définir l'angle avec une borne inférieure et une borne supérieure
        if not tt.fill():
            if type(angle) == tuple:
                theta = rd.uniform(angle[0], angle[1])
            else:
                theta = angle
        if k == 'F':
            tt.fd(distance)  #on fait un trait simple
        elif k == 'f':  #on "lève le crayon" pour avancer sans tracer
            tt.penup()
            tt.fd(distance)
            if wasdown:
                tt.pendown()
        elif k == '+':  #on tourne la tortue à gauche
            tt.left(theta)
        elif k == '-':
            tt.right(theta)  #on tourne à droite
        elif k == '|':  #on tourne de 180°
            tt.right(180)
        elif k == '[':  #on enregistre la position et la direction dans une liste
            x, y = tt.pos()
            d = tt.heading()
            L.append((x, y, d))


#tuple composé de la position (x,y) et de la direction (d)
        elif k == ']':  #on déplace à la dernière position enregistrée dans la liste
            tt.penup()
            x, y, d = L.pop()
            #on sort la dernière position enregistrée et on l'affecte à x,y,d
            tt.goto((x, y))  #on déplace la tortue à la position x,y
            tt.setheading(d)  #et on lui donne la direction d
            if wasdown:
                tt.pendown()
        elif k == '{':
            tt.fillcolor('green')
            tt.begin_fill()
        elif k == '}':
            tt.end_fill()
        (x, y) = tt.pos()
        xpos.append(x)  #liste des positions en x
        ypos.append(y)  #et des positions en y
    return xpos, ypos  #on renvoie les positions
Ejemplo n.º 38
0
def draw_cube(cube, colors, camera, viewer):
	a,b,c = camera
	faces = zip([[0,1,2,3],[0,7,4,3],[0,1,6,7],[2,5,4,3],[1,2,5,6],[5,6,7,4]], colors)
	d = [((a-x)**2 + (b-y)**2 + (c-z)**2)**0.5 for (x,y,z) in cube]
	ps = list(apply_perspective(cube, camera, viewer))
	faces.sort(key=lambda ((r,s,t,u),v): (d[r]+d[s]+d[t]+d[u])/4, reverse=True)
	for face, color in faces:
		r,s,t,u = face
		turtle.fillcolor(color)
		turtle.up()
		turtle.goto(ps[r])
		turtle.down()
		turtle.fill(True)
		turtle.goto(ps[s])
		turtle.goto(ps[t])
		turtle.goto(ps[u])
		turtle.goto(ps[r])
		turtle.fill(False)
Ejemplo n.º 39
0
def polygon(sides, length):

    count = 0

    turtle.fill(True)

    if sides % 2 == 0:

        turtle.color("blue")
    else:
        turtle.color("red")
    
    while count < sides:
        turtle.forward(length)
        turtle.right(360/sides)
        count = count + 1

    turtle.fill(False)
Ejemplo n.º 40
0
def chessboard(xstart=None,
               ystart=None,
               side=40,
               color='black',
               background='white'):
    turtle.pensize(3)
    turtle.speed('fastest')
    turtle.hideturtle()

    turtle.setposition(xstart, ystart)
    turtle.pendown()
    turtle.color(background)
    turtle.fill(True)
    for _ in range(4):
        turtle.forward(side)
        turtle.left(90)
    turtle.fill(False)
    turtle.color(color)
    turtle.fill(False)
    for _ in range(4):
        turtle.forward(side)
        turtle.left(90)
    turtle.fill(False)
    turtle.penup()
    for k in range(4):
        if k == 0 or k == 2:
            turtle.setposition(xstart, (ystart + (k * (side / 4))))
            for i in range(4):
                if i % 2 == 0:
                    draw_filled_square((side / 4), (side / 4))
                else:
                    draw_unfilled_square((side / 4), (side / 4))
                turtle.forward((side / 4))
            turtle.penup()
        elif k == 1:
            turtle.setposition(xstart, (ystart + side / 4))
            for j in range(4):
                if j % 2 == 0:
                    draw_unfilled_square((side / 4), (side / 4))
                else:
                    draw_filled_square((side / 4), (side / 4))
                turtle.forward((side / 4))
            turtle.penup()
        else:
            turtle.setposition(xstart, (ystart + (k * (side / 4))))
            for j in range(4):
                if j % 2 == 0:
                    draw_unfilled_square((side / 4), (side / 4))
                else:
                    draw_filled_square((side / 4), (side / 4))
                turtle.forward((side / 4))
        turtle.penup()
    k += (side / 4)
    return
Ejemplo n.º 41
0
def putSymbol(tuple):
    k = tuple[0]
    xpos = k[0]
    ypos = k[1]
    label = tuple[1]
    turtle.penup()
    turtle.fill(False)
    turtle.setpos(xpos, ypos)
    turtle.pendown()

    if (label == 'ruin'):
        drawRuin(xpos, ypos)
    elif (label == 'cave'):
        drawCave(xpos, ypos)
    elif (label == 'town'):
        drawTown(xpos, ypos)
    elif (label == 'spring'):
        drawSpring(xpos, ypos)
    return
def sign():
    turtle.color("chocolate")
    turtle.width(5)
    Base((-250,-200))
    turtle.setheading(0)
    turtle.fd(100)
    Tip = turtle.pos()
    turtle.fill(True)
    for x in range (1,5):
        
        
        
        turtle.setheading(turtle.heading() + 90)
        if x % 2 != 0:
            turtle.fd(150)
        else:
            turtle.fd(75)
        if turtle.heading() == 180:
            turtle.fd(25)
            turtle.bk(25)
    turtle.fillcolor('chocolate')
    turtle.fill(False)
    

    def writing():
        turtle.width(1)
        turtle.color("white")
        Base((-250,-100))
        turtle.setheading(162)
        turtle.pu()
        turtle.fd(28)
        turtle.setheading(180)
        turtle.fd(10)
        turtle.write("Raphaella and Danes' ", font=("Calibri", 12, "italic"))
        turtle.fd(14)
        turtle.pd()
        turtle.write("   Apple Tree",font = ("Calibri",12,"bold"))
        
    
    writing()
    turtle.setheading(0)
def chessboard(xstart = None, ystart = None, side = 40, color = 'black', background = 'white'):
    turtle.pensize(3)
    turtle.speed('fastest')
    turtle.hideturtle()
    
    turtle.setposition(xstart, ystart)
    turtle.pendown()
    turtle.color(background)
    turtle.fill(True)
    for _ in range(4):
        turtle.forward(side)
        turtle.left(90)
    turtle.fill(False)
    turtle.color(color)
    turtle.fill(False)
    for _ in range(4):
        turtle.forward(side)
        turtle.left(90)
    turtle.fill(False)
    turtle.penup()  
    for k in range(4):
        if k == 0 or k == 2:
            turtle.setposition(xstart, (ystart + (k * (side / 4))))
            for i in range(4):
                if i % 2 == 0:
                    draw_filled_square((side / 4), (side/4))
                else:
                    draw_unfilled_square((side / 4), (side / 4))
                turtle.forward((side / 4))
            turtle.penup()
        elif k == 1:
            turtle.setposition(xstart, (ystart + side / 4))
            for j in range(4):
                if j % 2 == 0:
                    draw_unfilled_square((side / 4), (side / 4))
                else:
                    draw_filled_square((side / 4), (side / 4))
                turtle.forward((side / 4))
            turtle.penup()
        else:
            turtle.setposition(xstart, (ystart + (k * (side / 4))))
            for j in range(4):
                if j % 2 == 0:
                    draw_unfilled_square((side / 4), (side / 4))
                else:
                    draw_filled_square((side / 4), (side / 4))
                turtle.forward((side / 4))
        turtle.penup()      
    k += (side / 4)
    return
Ejemplo n.º 44
0
def eclipse():
	turtle.color('white')
	turtle.goto(-390,225)
	turtle.down()
	turtle.fill(True)
	turtle.circle(50)
	turtle.fill(False)
	turtle.up()
	turtle.color('black')
	turtle.goto(-388,223)
	turtle.down()
	turtle.fill(True)
	turtle.circle(50)
	turtle.fill(False)
	turtle.up()
Ejemplo n.º 45
0
def demo():    
    turtle.width(1)
    turtle.color("black")
    # move out of the way
    turtle.tracer(0)
    turtle.up()
    turtle.right(90)
    turtle.forward(100)
    turtle.right(90)
    turtle.forward(100)
    turtle.right(180)
    turtle.down()        
    turtle.write("start", 1)
    turtle.color("red")    
    for i in range(5):
        turtle.forward(20)
        turtle.left(90)
        turtle.forward(20)
        turtle.right(90)    
    turtle.fill(0)
    turtle.tracer(1)
    # more text
    turtle.write("end")
Ejemplo n.º 46
0
turtle.speed("slowest")

avance = turtle.forward
recule = turtle.backward
td = turtle.right
tg = turtle.left

cercle = turtle.circle

dessine = turtle.pendown
ne_dessine_pas = turtle.penup

couleur_feutre = turtle.pencolor
couleur_remplissage = turtle.fillcolor

commence_a_remplir = turtle.fill(True)
finis_de_remplir = turtle.fill(False)

montre_tortue = turtle.showturtle
cache_tortue = turtle.hideturtle

annule = turtle.undo
efface = turtle.clear
recommence = turtle.reset
au_revoir = turtle.bye

turtle.colormode(255)

blanc = (255, 255, 255)
noir = (0, 0, 0)
bleu = (0, 0, 255)
Ejemplo n.º 47
0
        t.fd(length)    # forward
        t.pu()          # penup
        return

    for angle in [60, -120, 60, 0]:
        f(length/3, depth-1, anti)
        t.lt(angle * anti)


# main
t.reset()
t.speed(0)          # fast++
t.ht()              # hideturtle
t.pu()              # penup
screen = t.getscreen()
screen.bgcolor("black")
sleep(1)

for i in range(n):
    screen.tracer(49152, 0) # i
    # a b/w version
    cl = float(i+2) / float(n+2)
    t.color((cl, cl, cl))

    t.fill(True)        # 
    snowflake(sz, 5, 1) # i+2
    sz = sz - (sz / 8)  #
    t.fill(False)       #

t.mainloop()
Ejemplo n.º 48
0
def quad2draw(TF,col,vert):
	turtle.goto(vert[1])
	turtle.color(col)
	turtle.down()
	#right face
	turtle.fill(TF)
	if TF==True:
		turtle.color(rightcolor)
	turtle.goto(vert[5])
	turtle.goto(vert[6])
	turtle.goto(vert[2])
	turtle.goto(vert[1])
	turtle.fill(False)
	#bottom face
	turtle.fill(TF)
	if TF==True:
		turtle.color(bottomcolor)
	turtle.goto(vert[5])
	turtle.goto(vert[4])
	turtle.goto(vert[0])
	turtle.goto(vert[1])
	turtle.fill(False)
	#front face
	turtle.fill(TF)
	if TF==True:
		turtle.color(frontcolor)
	turtle.goto(vert[2])
	turtle.goto(vert[3])
	turtle.goto(vert[0])
	turtle.goto(vert[1])
	turtle.fill(False)
	turtle.up()
	if TF == False:
		return
	col = linecolor
	TF = False
	quad2draw(TF,col,vert)
Ejemplo n.º 49
0
def drawO(x,y):
    global isRunning,a,pink,cursor_pos,grid_pos,o_positions,one_count,two_count,cat_count,again
    if isRunning:
        return
    else:
        isRunning=True
        turtle.up()
        turtle.speed(0)
        turtle.fillcolor(pink)
        turtle.width(5)
        turtle.goto(x,y)
        turtle.setheading(270)
        turtle.forward(a)
        turtle.setheading(0)
        turtle.down()

        #start drawing O
        turtle.fill(True)
        turtle.circle(a)
        turtle.fill(False)
        #finish drawing O)
        
        isRunning=False        
        cursor_pos=(x,y)
        
        x,y=cursor_pos

        if x>=-b/2.0 and x<=b/2.0 and y>=-b/2.0 and y<=b/2.0:
            grid_pos=4
        elif x>b/2.0 and y>=-b/2.0 and y<=b/2.0:
            grid_pos=5
        elif x<-b/2.0 and y>=-b/2.0 and y<=b/2.0:
            grid_pos=3
        elif x>=-b/2.0 and x<=b/2.0 and y>b/2.0:
            grid_pos=1
        elif x>b/2.0 and y>b/2.0:
            grid_pos=2
        elif x<-b/2.0 and y>b/2.0:
            grid_pos=0
        elif x>=-b/2.0 and x<=b/2.0 and y<-b/2.0:
            grid_pos=7
        elif x>b/2.0 and y<-b/2.0:
            grid_pos=8
        elif x<-b/2.0 and y<-b/2.0:
            grid_pos=6

        o_positions.append(grid_pos)

        if xWins():
            print "X wins!"
            again=raw_input("Would you like to play again? (y/n): ")
            one_count+=1
            if again!="y" and again!="Y":
                print "X won",one_count,"times, O won",two_count,"times, and cat won",cat_count,"times. Click anywhere to exit."
                turtle.exitonclick()
            else:
                turtle.clear()
                restartGame()
        elif oWins():
            print "O wins!"
            again=raw_input("Would you like to play again? (y/n): ")
            two_count+=1
            if again!="y" and again!="Y":
                print "X won",one_count,"times, O won",two_count,"times, and cat won",cat_count,"times. Click anywhere to exit."
                turtle.exitonclick()
            else:
                turtle.clear()
                restartGame()
        elif catWins():
            print "Cat wins!"
            again=raw_input("Would you like to play again? (y/n): ")
            cat_count+=1
            if again!="y" and again!="Y":
                print "X won",one_count,"times, O won",two_count,"times, and cat won",cat_count,"times. Click anywhere to exit."
                turtle.exitonclick()
            else:
                turtle.clear()
                restartGame()
        else:
            pass
Ejemplo n.º 50
0
	def drawString(self, dstring, distance, angle):
		stack = []
		cstack = []
		modstring = ''
		modval = None
		modgrab = False
		for c in dstring:
			if c == '(':
				modstring = ''
				modgrab = True
				continue
			elif c == ')':
				modval = float(modstring)
				modgrab = False
				continue
			elif modgrab:
				modstring += c
				continue
			elif c == 'F' or c ==  'f':
				if modval == None:
					self.forward(distance)
				else:
					self.forward(distance*modval)
			elif c == '-':
				if modval == None:
					turtle.right(angle)
				else:
					turtle.right(modval)
			elif c == '+':
				if modval == None:
					turtle.left(angle)
				else:
					turtle.left(modval)
			elif c == '!':
				if modval == None:
					w = turtle.width()
					if w > 1:
						turtle.width(w-1)
				else:
					turtle.width(modval)
			elif c == '[':
				stack.append(turtle.position())
				stack.append(turtle.heading())
			elif c == ']':
				turtle.up()
				turtle.setheading(stack.pop())
				turtle.goto(stack.pop())
				turtle.down()
			elif c == 'L':
				#draws a leaf
				#begin and end fil calls work better in this section of code
				turtle.begin_fill()
				turtle.circle(5)
				turtle.end_fill()
			elif c == 'Q':
				#created for task3
				#draws a flower
				pos = turtle.position()
				heading = turtle.heading()
				turtle.begin_fill()
				turtle.right(90)
				turtle.forward(5)
				turtle.left(120)
				turtle.forward(10)
				turtle.left(120)
				turtle.forward(10)
				turtle.left(120)
				turtle.forward(10)
				turtle.end_fill()
				turtle.up()
				turtle.goto(pos)
				turtle.setheading(heading)
				turtle.down()
			elif c == 'P':
				#draws a petal
				#CREATED FOR EXTENSION1
				turtle.begin_fill()
				for i in range(12):
					turtle.forward(5)
					turtle.right(108)
					turtle.forward(5)
					turtle.left(144)
				turtle.end_fill()
			elif c == '<':
				color = turtle.color()[0]
				cstack.append(color)
			elif c == '>':
				turtle.color(cstack.pop())
			elif c == 'g':
				#makes the leaf color medium orchid
				turtle.color("Medium Orchid")
			elif c == 'y':
				#makes the leaf color turquoise
				turtle.color("Turquoise")
			elif c == 'r':
				#makes the leaf color salmon
				turtle.color("Salmon")
			elif c == 'b':
				#CREATED FOR EXTENSION1
				#makes the leaf color salmon
				turtle.color("Plum")
			elif c == 'o':
				#CREATED FOR EXTENSION1
				#makes the leaf color salmon
				turtle.color("Khaki")
			elif c == '{':
				turtle.fill(True)
			elif c == '}':
				turtle.fill(False)
		
			modval = None	
			
		turtle.update()
Ejemplo n.º 51
0
def quad4draw(TF,col,vert):
	turtle.goto(vert[3])
	turtle.color(col)
	turtle.down()
	#left face
	turtle.fill(TF)
	if TF==True:
		turtle.color(leftcolor)
	turtle.goto(vert[7])
	turtle.goto(vert[4])
	turtle.goto(vert[0])
	turtle.goto(vert[3])
	turtle.fill(False)
	#top face
	turtle.fill(TF)
	if TF==True:
		turtle.color(topcolor)
	turtle.goto(vert[7])
	turtle.goto(vert[6])
	turtle.goto(vert[2])
	turtle.goto(vert[3])
	turtle.fill(False)
	#front face
	turtle.fill(TF)
	if TF==True:
		turtle.color(frontcolor)
	turtle.goto(vert[0])
	turtle.goto(vert[1])
	turtle.goto(vert[2])
	turtle.goto(vert[3])
	turtle.fill(False)
	turtle.up()
	if TF == False:
		return
	col = linecolor
	TF = False
	quad4draw(TF,col,vert)
Ejemplo n.º 52
0
def setFill(fill):
    t.fill(fill)
Ejemplo n.º 53
0
def draw_square(turtle, size):
	turtle.fill(True)
	for i in range(1,5):
		turtle.forward(size)
		turtle.right(90)
	turtle.fill(False)
Ejemplo n.º 54
0
	def core(self):
		turtle.screensize(10000,10000)
		turtle.clearscreen()
		turtle.bgcolor("black")

		# select the origin in middle of the map
		q = self.n/2
		p = self.m/2
		
		# origin
		turtle.pencolor("red")
		turtle.fill(True)
		for _ in range(3): turtle.forward(5); turtle.left(120)
		turtle.fill(False)
		
		# init
		x = 0
		y = 0
		
		#while(self.map[p][q]!=1) :
		while(True) :
			self.map[p][q]+=1
			
			# current color
			t = 0;
			if(self.map[p+1][q+1]==1) : t+=1
			if(self.map[p+1][q-1]==1) : t+=1
			if(self.map[p-1][q-1]==1) : t+=1
			if(self.map[p-1][q+1]==1) : t+=1
			if(t==0) : turtle.pencolor("white")
			if(t==1) : turtle.pencolor("green")
			if(t==2) : turtle.pencolor("blue")
			if(t==3) : turtle.pencolor("purple")
			if(t==4) : turtle.pencolor("red")

			# display progression with tk and turtle
			self.display(x)

			# random value
			x = self.randomMode(1)
			if(x>0 and x<=90):
				p += 1
				q += 1
			elif(x>90 and x<=180):
				p += 1
				q -= 1
			elif(x>180 and x<=270):
				p -= 1
				q -= 1
			elif(x>270 and x<=360):
				p -= 1
				q += 1
			else : print '>>>> ERROR !!!'


			y += 1
		print '>>> ESSAI '+str(self.c)
		print '>>> Nombre de coups : '+str(y)
		(self.s).append(y)
		self.v += y
		self.c += 1
		self.t -= 1
Ejemplo n.º 55
0
def tursq(len):
  turtle.fill(1)
  for x in range(4):
    turtle.forward(len)
    turtle.lt(90)
  turtle.fill(0)
Ejemplo n.º 56
0
Archivo: hturtle.py Proyecto: nirs/hpy
def hpy_d79ed79cd790(hpy_d793d792d79c):
    """קבע את אופי הציור להיות משטחים מלאים לפי אמת/שקר"""
    turtle.fill(hpy_d793d792d79c)
Ejemplo n.º 57
0
	print("Input MUST be a number")
	sides = raw_input("number of sides to shape ")
	i = sides.isdigit()

sides = int(sides)
shapeangle = 360 / sides

print shapeangle
#print turtle.pencolor()
#print turtle.fillcolor()
#print turtle.pensize()

turtle.pen(fillcolor="Red", pencolor="blue", pensize=1)

for x in range(0,72):
	turtle.fill(True)
	turtle.left(5)
	for n in range(0,sides):
		turtle.forward(150)
		turtle.left(shapeangle) 
		
#hide turtle once drawing complete
turtle.hideturtle()
#pause
time.sleep(1)

#grab screen
ts = turtle.getscreen()
#save canvas to filename specified earlier
ts.getcanvas().postscript(file=fname)
Ejemplo n.º 58
0
screen.bgcolor("red")
x_coordinates_array=[]
y_coordinates_array=[]

file_of_dots=file("ConnectDots.txt")

for line in file_of_dots:
    line=line.strip()
    coordinates=line.split(" ")
    x,y=coordinates
    x=int(x)
    y=int(y)
    x_coordinates_array.append(x)
    y_coordinates_array.append(y)
    
turtle.fill(True)
for i in range(len(x_coordinates_array)):
    if i==0:
        turtle.up()
        turtle.goto(x_coordinates_array[i],y_coordinates_array[i])
        turtle.down()
    turtle.goto(x_coordinates_array[i],y_coordinates_array[i])
turtle.fill(False)

turtle.up()
turtle.color("white")

turtle.fill(True)
for i in range(len(x_coordinates_array)):
    if i==0:
        turtle.up()
Ejemplo n.º 59
0
#!/usr/bin/python

import turtle

#print "Hello!"

turtle.up ( )
turtle.goto ( 0 , 35 )
turtle.down ( )
turtle.color ( "red" )
turtle.fill (1)
turtle.circle ( 20 )
turtle.fill (0)
turtle.up ( )
turtle.goto ( 0 , -20 )
turtle.down ( )
turtle.color ( "yellow" )
turtle.fill (1)
turtle.circle ( 20 )
turtle.fill (0)
turtle.up ( )
turtle.goto ( 0 , -75 )
turtle.down ( )
turtle.color ( "green" )
turtle.fill (1)
turtle.circle ( 20 )
turtle.fill (0)

#turtle.goto (0, 20)
#turtle.forward ( 50 )
#turtle.right ( 60 )
Ejemplo n.º 60
0

sides = int(sides)
shapeangle = 360 / sides

#these lines are for diagnostics

#print shapeangle
#print turtle.pencolor()
#print turtle.fillcolor()
#print turtle.pensize()

#turtle.pen(fillcolor="Red", pencolor="blue", pensize=1)

for x in range(25,50):
	turtle.fill(False)
	turtle.left(5)
	for n in range(0,sides):
		turtle.forward(x)
		turtle.left(shapeangle) 




#hide turtle once drawing complete
turtle.hideturtle()
#pause
time.sleep(1)

#grab screen
ts = turtle.getscreen()