Exemplo n.º 1
31
    def draw_state(self):
        """
        the core of the class

        Interprete character:

        F: move forward
        +: turn right
        -: turn left
        [: push (position, heading)
        ]: pop (position, heading)
        """
        import turtle

        state = self.lsystem().state()
        for c in state:
            if c == 'F':
                turtle.forward(self.length)
            if c == '+':
                turtle.right(self.angle)
            if c == '-':
                turtle.left(self.angle)
            if c == '[':
                self.stack.append((turtle.position(), turtle.heading()))
            if c == ']':
                if len(self.stack) == 0:
                    raise ValueError('inconsistant state: using to much `]`')
                pos, head = self.stack.pop()
                turtle.penup()
                turtle.setpos(pos)
                turtle.setheading(head)
                turtle.pendown()
        return self
Exemplo n.º 2
0
    def __init__(self, length=10, angle=90, colors=None, lsystem=None):
        import turtle
        self.length = length
        self.angle = angle
        if colors is None:
            self.colors = ['red', 'green', 'blue', 'orange', 'yellow', 'brown']
        if lsystem is not None:
            self.lsystem(lsystem)

        # draw number
        self.ith_draw = 0

        # origin of next draw
        self.origin = [0, 0]

        # bounding_box
        self._box = 0, 0, 0, 0


        # turtle head north and positive angles is clockwise
        turtle.mode('world')
        turtle.setheading(90)
        turtle.speed(0) # fastest
        turtle.hideturtle()
        turtle.tracer(0, 1)
	
        # set pencolor
        self.pencolor()
Exemplo n.º 3
0
    def show_particles(self, particles):
        self.update_cnt += 1
        if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1:
            return

        # turtle.clearstamps()
        turtle.shape('tri')

        draw_cnt = 0
        px = {}
        for p in particles:
            draw_cnt += 1
            if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 1:
                # Keep track of which positions already have something
                # drawn to speed up display rendering
                scaled_x1 = int(p.x1 * self.one_px)
                scaled_y1 = int(p.y1 * self.one_px)
                scaled_xy1 = scaled_x1 * 10000 + scaled_y1
                if not scaled_xy1 in px:
                    px[scaled_xy1] = 1
                    turtle.setposition(*p.xy1)
                    turtle.setheading(math.degrees(p.h))
                    turtle.color("Red")
                    turtle.stamp()

                    turtle.setposition(*p.xy2)
                    turtle.setheading(math.degrees(p.h))
                    turtle.color("Blue")
                    turtle.stamp()
Exemplo n.º 4
0
def draw(cmds, size=2): #output tree
    stack = []
    for cmd in cmds:
        if cmd=='F':
            turtle.forward(size)
        elif cmd=='-':
            t = random.randrange(0,7,1)
            p = ["Red","Green","Blue","Grey","Yellow","Pink","Brown"]
            turtle.color(p[t])
            turtle.left(15) #slope left
        elif cmd=='+':
            turtle.right(15) #slope right
            t = random.randrange(0,7,1) #рандомная пер. для цвета
            p = ["Red","Green","Blue","Grey","Yellow","Pink","Brown"] #ряд цветов
            turtle.color(p[t]) #выбор цвета из ряда
        elif cmd=='X':
            pass
        elif cmd=='[':
            stack.append((turtle.position(), turtle.heading()))
        elif cmd==']':
            position, heading = stack.pop()
            turtle.penup()
            turtle.setposition(position)
            turtle.setheading(heading)  
            turtle.pendown()
    turtle.update()
Exemplo n.º 5
0
 def show_shark(self, shark):
     turtle.color(shark.color)
     turtle.shape('turtle')
     turtle.setposition(*shark.xy)
     turtle.setheading(math.degrees(shark.h))
     turtle.stamp()
     turtle.update()
Exemplo n.º 6
0
    def show_sharks(self, sharks):
        self.update_cnt += 1
        if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1:
            return

        turtle.clearstamps()
        draw_cnt = 0
        px = {}
        for shark in sharks:
            draw_cnt += 1
            shark_shape = 'classic' if shark.tracked else 'classic'
            if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 0:
                # Keep track of which positions already have something
                # drawn to speed up display rendering
                scaled_x = int(shark.x * self.one_px)
                scaled_y = int(shark.y * self.one_px)
                scaled_xy = scaled_x * 10000 + scaled_y
                turtle.color(shark.color)
                turtle.shape(shark_shape)
                turtle.resizemode("user")
                turtle.shapesize(1.5,1.5,1)
                if not scaled_xy in px:
                    px[scaled_xy] = 1
                    turtle.setposition(*shark.xy)
                    turtle.setheading(math.degrees(shark.h))
                    turtle.stamp()
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
0
    def drawLine(self,color,coord1,coord2): 
        """
        dessine une ligne entre deux coordonné sur la grille

        :param color: La couleur de la ligne
        :param coord1: La première coordonné en tuple (i,j,"joueur")
        :param coord2: La deuxième coordonné en tuple (i,j,"joueur")
        """
        if coord1[2] == coord2[2] and coord2[2] == "you":
            turtle.goto(38+coord1[1]*25,87-25*coord1[0])
        elif coord1[2] == coord2[2] and coord2[2] == "enemy":
            turtle.goto(-262+(25*coord1[1]),87-25*coord1[0])
        else:
            print('wrong player')
            return 0
        turtle.pensize(20)
        turtle.pencolor(color)
        if coord1[1] == coord2[1]: #Vertical
            turtle.pendown()
            turtle.setheading(270)
            turtle.fd((coord2[0]-coord1[0])*25)
        elif coord1[0] == coord2[0]: #horizontal
            turtle.pendown()
            turtle.setheading(0)
            turtle.fd((coord2[1]-coord1[1])*25)
        else:
            print('Ligne non Hori ou Vert')
            return 0
        turtle.penup()
        return 1
Exemplo n.º 10
0
 def show_robot(self, robot):
     turtle.color("green")
     turtle.shape('turtle')
     turtle.setposition(*robot.xy)
     turtle.setheading(robot.h)
     turtle.stamp()
     turtle.update()
Exemplo n.º 11
0
def drawS(turtle, height, width):
    """
    draw the letter S using turtle, with some height and width
    """
    # Pick pen up and move a little to the right
    turtle.penup()
    turtle.setheading(0)
    turtle.forward((1.0/6.0)*width)
    # Put pen down and draw bottom of S
    turtle.pendown()
    turtle.forward((2.0/3.0)*width)
    # Draw first curve
    turtle.left((180.0/math.pi)*math.atan((3.0/2.0)*height/width))
    turtle.forward(math.sqrt(((1.0/6.0)*width)**2+((1.0/4.0)*height)**2))
    turtle.left(180.0-(360.0/math.pi)*math.atan((3.0/2.0)*height/width))
    turtle.forward(math.sqrt(((1.0/6.0)*width)**2+((1.0/4.0)*height)**2))
    turtle.left((180.0/math.pi)*math.atan((3.0/2.0)*height/width))
    # Draw middle of S
    turtle.forward((2.0/3.0)*width)
    # Draw second curve
    turtle.right((180.0/math.pi)*math.atan((3.0/2.0)*height/width))
    turtle.forward(math.sqrt(((1.0/6.0)*width)**2+((1.0/4.0)*height)**2))
    turtle.right(180.0-(360.0/math.pi)*math.atan((3.0/2.0)*height/width))
    turtle.forward(math.sqrt(((1.0/6.0)*width)**2+((1.0/4.0)*height)**2))
    turtle.right((180.0/math.pi)*math.atan((3.0/2.0)*height/width))
    # Draw top of S, pick up pen, and move a little to the right
    turtle.forward((2.0/3.0)*width)
    turtle.penup()
    turtle.forward((1.0/6.0)*width)
Exemplo n.º 12
0
def entrance(pointOne):
    turtle.goto(pointOne[0], pointOne[1] + 36)
    turtle.setheading(270)
    turtle.pendown()
    turtle.forward(15)
    turtle.penup()
    drawArrows()
Exemplo n.º 13
0
def e(fill=False):
    '''draws a capital E.  Docstrings need to be the first line in a function definition'''
    turtle.setheading(0)
    if fill: bf()
    fd(40)
    lt(90)
    fd(10)
    lt(90)
    fd(30)
    rt(90)
    fd(40)
    rt(90)
    fd(30)
    lt(90)
    fd(10)
    lt(90)
    fd(30)
    rt(90)
    fd(40)
    rt(90)
    fd(30)
    lt(90)
    fd(10)
    lt(90)
    fd(40)
    lt(90)
    fd(110)
    lt(90)
    if fill: ef()
    pu()
    fd(50)
    pd()
Exemplo n.º 14
0
def main():
	'''Creates lsystem from filename and then creates an arrangement'''
	# creates object from lsystem
	l = ls.Lsystem('lsystemextension2.txt')
	
	#number of iterations
	# for growth effect in task 3, made iters a parameter
	num_iter = 4
	
	
	# creates buildstring function
	s = l.buildString(num_iter)
	
	#specific angle
	angle = 30
	
	#creates an object from TI class
	ti = it.TurtleInterpreter()
	
	# sets the colors of the tracer and calls the drawstring function
	turtle.pencolor('ForestGreen')
	'''tree with stem color of forestgreen'''
	turtle.up()
	turtle.setposition(0,0)
	turtle.setheading(90)
	turtle.down()
	ti.drawString(s, 50 ,angle)
	
	
	
	ti.hold()
Exemplo n.º 15
0
def a(fill=False):
    '''draws a capital A.'''
    turtle.setheading(0)
    if fill: bf()
    fd(10)
    turtle.goto(turtle.xcor() + 5, turtle.ycor() + 40)
    fd(10)
    turtle.goto(turtle.xcor() + 5, turtle.ycor() - 40)
    fd(10)
    turtle.goto(turtle.xcor() - 15, turtle.ycor() + 110)
    turtle.setx(turtle.xcor() - 10)
    turtle.goto(turtle.xcor() - 15, turtle.ycor() - 110)
    if fill: ef()
    pu()
    turtle.goto(turtle.xcor() + 17, turtle.ycor() + 50)
    pd()
    if fill:
        cfc = fc()
        fc(turtle.getscreen().bgcolor())
        bf()
    fd(6)
    turtle.goto(turtle.xcor() - 3, turtle.ycor() + 40)
    turtle.goto(turtle.xcor() - 3, turtle.ycor() - 40)
    if fill:
        ef()
        fc(cfc)
    pu()
    turtle.goto(turtle.xcor() + 33, turtle.ycor() - 50)
    pd()
Exemplo n.º 16
0
def h(fill=False):
    '''draws a capital H.
     This is a DOCstring, which is a special comment that DOCuments our code.  When you type help() in python it
     displays these strings.  Don't take my word for it... try it yourself!'''
    turtle.setheading(0)
    if fill: bf()
    fd(10)
    lt(90)
    fd(50)
    rt(90)
    fd(20)
    rt(90)  # These things after the .'s are functions we can use, just like this h function!
    fd(50)
    lt(90)
    fd(10)
    lt(90)
    fd(110)
    lt(90)
    fd(10)
    lt(90)
    fd(50)
    rt(90)
    fd(20)
    rt(90)
    fd(50)
    lt(90)
    fd(10)
    lt(90)
    fd(110)
    lt(90)
    if fill: ef()  # single statement 'if' can be put on the same line
    pu()
    fd(50)
    pd()
Exemplo n.º 17
0
def tree( x, y, scale ):
	'''draws a leaf given location and scale'''
	goto( x, y )
	turtle.setheading(0)
	turtle.begin_fill()
	turtle.color('dark green')
	turtle.forward(25*scale)
	turtle.left(150)
	turtle.forward(25*scale)
	turtle.right(150)
	turtle.forward(20*scale)
	turtle.left(150)
	turtle.forward(30*scale)
	turtle.left(60)
	turtle.forward(30*scale)
	turtle.left(150)
	turtle.forward(20*scale)
	turtle.right(150)
	turtle.forward(25*scale)
	turtle.left(150)
	turtle.end_fill()
	turtle.forward(30*scale)
	goto( x, y )
	turtle.begin_fill()
	turtle.color('brown')
	turtle.right(90)
	turtle.forward(15*scale)
	turtle.right(90)
	turtle.forward(5*scale)
	turtle.right(90)
	turtle.forward(15*scale)
	turtle.right(90)
	turtle.end_fill()
	turtle.forward(5*scale)
Exemplo n.º 18
0
def d(fill=False):
    '''draws a capital D'''
    turtle.setheading(0)
    if fill: bf()
    fd(20)
    circle(20, 90)
    fd(70)
    circle(20, 90)
    fd(20)
    lt(90)
    fd(110)
    lt(90)
    if fill: ef()
    pu()
    turtle.goto(turtle.xcor() + 10, turtle.ycor() + 10)
    pd()
    cfc = fc()
    fc(turtle.getscreen().bgcolor())
    bf()
    fd(10)
    circle(10, 90)
    fd(70)
    circle(10, 90)
    fd(10)
    lt(90)
    fd(90)
    ef()
    lt(90)
    pu()
    turtle.goto(turtle.xcor() + 40, turtle.ycor() - 10)
    pd()
    fc(cfc)
Exemplo n.º 19
0
Arquivo: 30.py Projeto: jpbat/freetime
def grid(side):
	turtle.color("blue")
	#horizontal
	for i in range(1, 5):
		move(-side*3, side*3-i*side)
		turtle.fd(6*side)

	#vertical
	turtle.setheading(-90)
	for i in range(1, 6):
		move(-side*3+i*side, side*3)
		turtle.fd(5*side)
	
	#big square
	turtle.color("red")
	turtle.width(2)
	turtle.setheading(0)
	move(-side*3, side*3)
	for i in range(4):
		if (i % 2 == 0):
			cena = side * 6
		else:
			cena = side * 5
		turtle.fd(cena)
		turtle.rt(90)
Exemplo n.º 20
0
    def tegnGitter(i0,i1,j0,j1):
        """Gitteret har søjler fra i0 til og med i1 og rækker fra
j0 til og med j1.  Først blankstilles lærredet"""
        xmin,ymin = toXY(i0,j0)
        xlen,ylen = (i1-i0+2)*cs,(j1-j0+2)*cs
        tt.clear()
        tt.penup()
        tt.color(kodefarve[4])
        # vandrette linjer
        x,y = xmin-cs/2,ymin
        tt.setheading(0) # øst
        for j in range(j0,j1+2):
            tt.goto(x,y)
            tt.pendown()
            tt.forward(xlen)
            tt.penup()
            y += cs
        # lodrette linjer
        x,y = xmin,ymin-cs/2
        tt.setheading(90) # nord
        for i in range(i0,i1+2):
            tt.goto(x,y)
            tt.pendown()
            tt.forward(ylen)
            tt.penup()
            x += cs
def draw_rectangle(x,y,width,height):
    """
    Draws a rectangle with the upper left hand corner starting at point (x,y).
    The said rectangle has the dimensions width x height.
    :param x:
    :param y:
    :param width:
    :param height:
    :return: None
    """
    turtle.penup()
    turtle.setx(x)
    turtle.sety(y)
    turtle.pendown()
    turtle.setheading(0)  # Set heading in x+ direction
    turtle.begin_fill()
    turtle.begin_poly()
    turtle.fd(width)
    turtle.right(90)
    turtle.fd(height)
    turtle.right(90)
    turtle.fd(width)
    turtle.right(90)
    turtle.fd(height)
    turtle.end_poly()
    turtle.end_fill()
    return None
Exemplo n.º 22
0
def drawFace(x=200, y=200, face=500):
    turtle.pendown()
    colour = random.choice(faceColors)
    drawHead(face, colour)    # Instruct python to use or method "drawSquare"
    turtle.penup()            # space things out before drawing the next Square
    turtle.setposition(x-face/18,y-face/9)

    turtle.pendown()
    turtle.pencolor("black")
    if(colour == "green"):
        drawCrossEye(face/8)
    else:
        drawRoundEye(face/16) 
    
    turtle.penup()            # space things out before drawing the next Square
    turtle.setposition(x+face/18,y-face/9)

    turtle.pendown()
    if(colour == "green"):
        drawCrossEye(face/8)
    else:
        drawRoundEye(face/16) 
    

    turtle.penup()            # space things out before drawing the next Square
    turtle.setposition(x+face/11,y-face/5.5)

    turtle.pendown()
    turtle.setheading(270)
    drawMouth(face/4)
    turtle.penup()
Exemplo n.º 23
0
def drawP(size):
    turtle.setheading(90)
    turtle.penup()
    turtle.forward(size*1.5);
    turtle.pendown()
    turtle.forward(size*0.5);
    drawSemi(size, direction="right", degrees=336, colour="black")
def makeTree(h, l, b, d, ad):
    
    Base(b)
    
    turtle.color("brown")
    
    
    if h > 0:
        
        if h == 1:
            turtle.color("green")

        if h== 4:
            Apple(b)
        if d == 0:
            
            makeTree(h-1 , l*.75, drawLimb(l, d*ad), d+1,ad)
        else:
            y = turtle.heading()
            
            makeTree(h-1 , l*.75, drawLimb(l*.75, d*ad/2.00), d,ad)
            Base(b)
            d = d*-1
            turtle.setheading(y)
            makeTree(h-1 , l*.75, drawLimb(l*.75, d*ad/2.00), d,ad)
        
    else:
        Base(b)
Exemplo n.º 25
0
 def show_robot(self, robot):
     turtle.color("blue")
     turtle.shape('square')
     turtle.setposition(*robot.xy)
     turtle.setheading(math.degrees(robot.h))
     turtle.stamp()
     turtle.update()
Exemplo n.º 26
0
def draw_l(word):
    turtle.up()
    turtle.clear()
    turtle.setposition(0, 0)
    turtle.setheading(0)
    turtle.bk(INITIAL_POS[0])
    turtle.down()
    turtle.st()
    stack = []
    for char in word:
        if char == '0':
            turtle.fd(SIZE[0])
        if char == '1':
            turtle.fd(SIZE[0])
        if char == '[':
            stack.append((turtle.position(), turtle.heading()))
            turtle.lt(45)
        if char == ']':
            position, heading = stack.pop()
            turtle.up()
            turtle.setposition(position)
            turtle.setheading(heading)
            turtle.rt(45)
            turtle.down()
    turtle.ht()
Exemplo n.º 27
0
def draw_circle(x,y,r,t):
    t.pu()
    t.goto(x+r,y)
    t.setheading(90)
    t.pd()
    t.circle(r)
    t.pu()
def circle(a,b):
    turtle.color("green")
    turtle.pu()
    turtle.goto(a,b)
    turtle.pd()
    turtle.setheading(90)
    turtle.circle(40)
Exemplo n.º 29
0
def move_to_start(x_start, y_start):    # в качестве параметром принимает координаты
    x = x_start
    y = y_start
    turtle.penup()                  # отключаем рисование
    turtle.setpos(x, y)             # перемещаем turtle
    turtle.setheading(DIRECT_DOWN)  # разворачиваем на юг
    turtle.pendown()                # включаем рисование
Exemplo n.º 30
0
def drawFins(size):
    
    turtle.fillcolor("red")    
    turtle.setheading(90)
    turtle.begin_fill()
    turtle.forward(0.2*size)
    turtle.left(120)
    turtle.forward(0.6*size) 
    turtle.right(120)
    turtle.forward(0.3*size) 
    turtle.right(40)
    turtle.forward(0.8*size)
    turtle.end_fill()    
    
    turtle.setheading(0)
    
    turtle.begin_fill()

    turtle.penup()
    turtle.forward(size)
    turtle.pendown()
    turtle.begin_fill()
    turtle.right(50)
    turtle.forward(0.8*size) 
    turtle.right(40)
    turtle.forward(0.3*size) 
    turtle.right(120)
    turtle.forward(0.6*size)
    turtle.end_fill()
Exemplo n.º 31
0
def turn_up():  # 위쪽으로 방향을 바꿉니다.
    t.setheading(90)
Exemplo n.º 32
0
def tscheme_setheading(h):
    """Set the turtle's heading H degrees clockwise from north (up)."""
    _check_nums(h)
    _tscheme_prep()
    turtle.setheading(h)
    return okay
Exemplo n.º 33
0
 def place(self, xpos, ypos, angle=None):
     turtle.up()
     turtle.goto(xpos, ypos)
     if angle != None:
         turtle.setheading(angle)
     turtle.down()
Exemplo n.º 34
0
    t.color("black")  # 거북이 색상을 검은색으로 되돌립니다.
    t.goto(-200, 10)  # 거북이 위치를 처음 발사했던 곳으로 되돌립니다.
    t.setheading(ang)  # 각도도 처음 기억해둔 각도로 되돌립니다.


# 땅을 그립니다.
t.goto(-300, 0)
t.down()
t.goto(300, 0)

# 목표 지점을 설정하고 그립니다.
target = random.randint(50, 150)  # 목표 지점을 50~150 사이에서 임의의 수로 지정합니다.
t.pensize(3)
t.color("green")
t.up()
t.goto(target - 25, 2)
t.down()
t.goto(target + 25, 2)

# 거북이 색상을 검은색으로 지정하고 처음 발사했던 곳으로 되돌립니다.
t.color("black")
t.up()
t.goto(-200, 10)
t.setheading(20)

# 거북이가 동작하는데 필요한 설정을 합니다.
t.onkeypress(turn_up, "Up")  # [↑]키를 누르면 turn_up 함수를 실행하도록 합니다.
t.onkeypress(turn_down, "Down")  # [↓]키를 누르면 turn_down 함수를 실행하도록 합니다.
t.onkeypress(fire, "space")  # [스페이스]키를 누르면 fire 함수를 실행하도록 합니다.
t.listen()  # 거북이 그래픽 창이 키보드 입력을 받도록 합니다.
Exemplo n.º 35
0
  
        self.beacons = []
        for y, line in enumerate(self.maze):
            for x, block in enumerate(line):
                if block:
                    nb_y = self.height - y - 1
                    self.blocks.append((x, nb_y))
                    if block == 2:
                        self.beacons.extend(((x, nb_y), (x+1, nb_y), (x, nb_y+1), (x+1, nb_y+1)))
  
    def draw(self):
        for x, y in self.blocks:
            turtle.up()
            turtle.setposition(x, y)
            turtle.down()
            turtle.setheading(90)
            turtle.begin_fill()
            for _ in range(0, 4):
                turtle.fd(1)
                turtle.right(90)
            turtle.end_fill()
            turtle.up()
  
        turtle.color("#00ffff")
        for x, y in self.beacons:
            turtle.setposition(x, y)
            turtle.dot()
        turtle.update()
  
    def weight_to_color(self, weight):
        return "#%02x00%02x" % (int(weight * 255), int((1 - weight) * 255))
Exemplo n.º 36
0
def main():
    t = BinarySearchTree()
    t.insert(5, 5)
    t.insert(3, 3)
    t.insert(8, 8)
    t.insert(10, 10)
    t.insert(7, 7)
    t.insert(2, 2)
    print(t)
    print('Maxheight', t.max_height())
    print("Current Height:", t.current_height())

    print('Inorder Traversal')
    t.traverse_inorder()
    print('Preorder Traversal')
    t.traverse_preorder()
    print('Postorder Traversal')
    t.traverse_postorder()

    #Drawing tree
    turtle_tree = BinarySearchTree()
    turtle.setup(1200, 800)
    window = turtle.Screen()
    window.title('Binary Search Tree')
    turtle.speed(10)

    #   Setting root as 4
    turtle_tree.insert(4, 4)
    turtle.pu()
    turtle.setpos(0, 260)
    turtle.pd()
    turtle.circle(60)
    rootpos = turtle.pos()
    turtle.pu()
    turtle.left(90)
    turtle.forward(70)
    draw4()
    turtle.pu()
    turtle.setpos(rootpos)

    #   Inserting 1
    turtle_tree.insert(1, 1)
    turtle.left(120)
    turtle.pd()
    turtle.forward(140)
    turtle.setheading(180)
    turtle.circle(60)
    prevpos = turtle.pos()
    turtle.left(90)
    turtle.pu()
    turtle.forward(30)
    turtle.pd()
    draw1()
    turtle.pu()

    #   Inserting 5
    turtle_tree.insert(5, 5)
    turtle.setpos(rootpos)
    turtle.setheading(90)
    turtle.right(120)
    turtle.pd()
    turtle.forward(140)
    turtle.setheading(180)
    turtle.circle(60)
    prevpos = turtle.pos()
    turtle.left(90)
    turtle.pu()
    turtle.forward(30)
    turtle.left(90)
    turtle.forward(-10)
    turtle.pd()
    draw5()
    turtle.pu()
    turtle.setpos(prevpos)
    turtle.left(90)
    turtle.forward(120)

    #   Inserting 7
    turtle_tree.insert(7, 7)
    turtle_tree.insert(5, 5)
    turtle.setheading(90)
    turtle.right(120)
    turtle.pd()
    turtle.forward(140)
    turtle.setheading(180)
    turtle.circle(60)
    prevpos = turtle.pos()
    turtle.left(90)
    turtle.pu()
    turtle.forward(30)
    turtle.pd()
    draw7()
    turtle.pu()
    turtle.setpos(prevpos)
    turtle.left(90)
    turtle.forward(120)

    #   Inserting 9
    turtle_tree.insert(9, 9)
    turtle.setheading(90)
    turtle.right(120)
    turtle.pd()
    turtle.forward(140)
    turtle.setheading(180)
    turtle.circle(60)
    prevpos = turtle.pos()
    turtle.left(90)
    turtle.pu()
    turtle.forward(30)
    turtle.pd()
    draw9()
    turtle.pu()
    turtle.setpos(prevpos)
    turtle.left(90)
    turtle.forward(120)

    print('Tree for turtle: ')
    print(turtle_tree)
    turtle.exitonclick()
    return t
Exemplo n.º 37
0
        n = 5
        t.begin_fill()
        for x in range(n):
            t.fd(100)
            t.lt(144)
        t.end_fill()
        t.up()
        t.fd(100)
        t.down()
    t.reset()
    t.color("salmon")
    for x in range(200):
        t.lt(144)
        t.fd(x)
        t.speed(0)

else:
    print("땡ㅜㅜ")  #답을 틀린다면 땡ㅜㅜ
    import turtle as t  #틀린다면 동그라미의 저주에 걸린 거북이의 악몽을 보여줄거에요
    import random
    t.shape("turtle")
    t.color("red")
    for x in range(1000):
        m = random.randint(1, 360)
        t.setheading(m)
        t.circle(m)
        t.speed(0)
    t.reset()
    for x in range(50):
        t.circle(x)
Exemplo n.º 38
0
turtle.left(15)
turtle.fd(45)
turtle.right(165)
turtle.fd(20)
turtle.left(155)
turtle.circle(150, 80)
turtle.left(50)
turtle.circle(150, 90)
turtle.end_fill()

# 花瓣1
turtle.left(150)
turtle.circle(-90, 70)
turtle.left(20)
turtle.circle(75, 105)
turtle.setheading(60)
turtle.circle(80, 98)
turtle.circle(-90, 40)

# 花瓣2
turtle.left(180)
turtle.circle(90, 40)
turtle.circle(-80, 98)
turtle.setheading(-83)

# 叶子1
turtle.fd(30)
turtle.left(90)
turtle.fd(25)
turtle.left(45)
turtle.fillcolor("green")
Exemplo n.º 39
0
import turtle
turtle.hideturtle()
turtle.speed(0)
turtle.tracer(False)


# defins how to draw a petal
def petal(r, steps):
    turtle.circle(r, 80, steps)
    turtle.left(90)
    turtle.circle(r, 80, steps)


turtle.color("red", "yellow")
# get the radius and steps and draw
r = input("Enter the petal radius")
steps = input("Enter the petal steps")
num = 20
turtle.setx(0)
turtle.sety(0)
for i in xrange(num):
    turtle.setheading(0)
    turtle.left(360 * i / num)
    petal(r, steps)
    turtle.setx(0)
    turtle.sety(0)
    turtle.pendown

turtle.tracer(True)
turtle.done()
Exemplo n.º 40
0
import turtle as t
from random import choice
from time import sleep

colors = ('red', 'green', 'blue', 'yellow', 'black')
t.speed('fastest')
t.pu()
t.goto(400, -100)
t.setheading(90)
t.pd()
t.pensize(10)
turn = 10
length = 100
while length > 20:
    t.color(choice(colors))
    t.fd(length)
    t.left(turn)
    turn += 0.1
    length *= 0.99

sleep(1000)
Exemplo n.º 41
0
def turn_up():
    t.setheading(90)
    t.fd(10)
Exemplo n.º 42
0
def orient_turtle(turtle, impact_pos):
    """
    This function orients the turtles to the projected impact position
    """
    turtle.setheading(0)
    turtle.left(turtle.towards(impact_pos))
Exemplo n.º 43
0
def turn_down():
    t.setheading(270)
    t.fd(10)
Exemplo n.º 44
0
def turn_right():
    t.setheading(0)
    t.fd(10)
Exemplo n.º 45
0
def turn_down():
    t.setheading(270)
Exemplo n.º 46
0
def turn_left():
    t.setheading(180)
    t.fd(10)
Exemplo n.º 47
0
def turn_up():
    t.setheading(90)
Exemplo n.º 48
0
def turn_lt():
    t.setheading(180)
Exemplo n.º 49
0
def draw_people (x,y):
    turtle.penup ()
    turtle.goto (x,y)
    turtle.pendown ()
    turtle.pensize (2)
    turtle.color ('black')
    turtle.setheading (0)
    turtle.circle (60,360)
    turtle.penup ()
    turtle.setheading (90)
    turtle.fd (75)
    turtle.setheading (180)
    turtle.fd (20)
    turtle.pensize (4)
    turtle.pendown ()
    turtle.circle (2,360)
    turtle.setheading (0)
    turtle.penup ()
    turtle.fd (40)
    turtle.pensize (4)
    turtle.pendown ()
    turtle.circle (-2,360)
    turtle.penup ()
    turtle.goto (x,y)
    turtle.setheading (-90)
    turtle.pendown ()
    turtle.fd (20)
    turtle.setheading (0)
    turtle.fd (35)
    turtle.setheading (60)
    turtle.fd (10)
    turtle.penup ()
    turtle.goto (x,y)
    turtle.setheading (-90)
    turtle.pendown ()
    turtle.fd (60)
    turtle.setheading (-135)
    turtle.fd (60)
    turtle.bk (60)
    turtle.setheading (-45)
    turtle.fd (30)
    turtle.setheading (-135)
    turtle.fd (35)
    turtle.penup ()
Exemplo n.º 50
0
def turn_rt():
    t.setheading(0)
Exemplo n.º 51
0
dig0 = [(90, 40), (90, 20), (90, 40), (90, 20)]
dig1 = [(135, diag), (180, diag), (135, 40)]
dig2 = [(180, 20), (180, 20), (90, 20), (45, diag), (-135, 20)]
dig3 = [(180, 20), (180, 20), (135, diag), (-135, 20), (135, diag)]
dig4 = [(90, 40), (180, 20), (-90, 20), (90, 20)]
dig7 = [(180, 20), (180, 20), (135, diag), (-45, 20)]
digits = [dig0, dig1, dig2, dig3, dig4, dig7]

font = open('lab_03_03.txt', 'w')
for str_line in range(len(digits)):
    font.write(str(digits[str_line]))
    font.write('\n')
font.close()

font1 = open('lab_03_03.txt')
lines = font1.readlines()
font1.close()

t.shape('turtle')
for digit in range(len(digits)):
    t.penup()
    t.goto(x, 0)
    t.setheading(0)
    t.pendown()
    for i in range(len(digits[digit])):
        mov1 = eval(lines[digit])
        t.right(mov1[i][0])
        t.forward(mov1[i][1])
    x += 30
input()
Exemplo n.º 52
0
def draw_line (length,angle,state):
    turtle.pensize (1)
    turtle.pendown ()
    turtle.setheading (angle)
    turtle.fd (length)
    turtle.bk (length) if state else turtle.penup ()
Exemplo n.º 53
0
def turn_down():  # 아래쪽으로 방향을 바꿉니다.
    t.setheading(270)
Exemplo n.º 54
0
l = abs(x1) - width
w = abs(y1) - height

if l == 0:
    l = width // 2
elif w == 0:
    w = height // 2

l = abs(l)
w = abs(w)
turtle.showturtle()
turtle.penup()
turtle.goto(x1,y1)
turtle.forward(l)
turtle.pendown()
turtle.setheading(-90)
turtle.forward(w)
turtle.setheading(180)
turtle.forward(2 * l)
turtle.setheading(90)
turtle.forward(2 * w)
turtle.setheading(0)
turtle.forward(2 * l)
turtle.setheading(-90)
turtle.forward(w)
turtle.done()




Exemplo n.º 55
0
 def orient(self, angle):
     turtle.setheading(angle)
Exemplo n.º 56
0
def turn_left():  # 왼쪽으로 방향을 바꿉니다.
    t.setheading(180)
Exemplo n.º 57
0
#Turtle Graphics: Repeating Squares

#turtle graphics program that uses nested loops to draw 100 squares
import turtle

NUM_SQUARES = 100  #number of squares to draw
FORWARD = 5  #distance turtle travels

#draw 100 squares, increasing each new one by 2
for x in range(NUM_SQUARES):
    turtle.setheading(90)
    turtle.forward(FORWARD)
    turtle.setheading(180)
    turtle.forward(FORWARD)
    turtle.setheading(270)
    turtle.forward(FORWARD)
    turtle.setheading(360)
    turtle.forward(FORWARD)
    FORWARD *= 2
Exemplo n.º 58
0
turtle.fd(45)
turtle.right(165)
turtle.fd(20)
turtle.left(155)
turtle.circle(150, 80)
turtle.left(50)
turtle.circle(150, 90)
turtle.end_fill()  # 结束填充

# 花瓣1
turtle.left(150)
turtle.circle(-90, 70)
turtle.left(20)
turtle.circle(75, 105)
turtle.setheading(
    60
)  # urtle.setheading(angle) 或 turtle.seth(angle):改变行进方向 angle:行进方向的绝对角度,可以为负值
turtle.circle(80, 98)
turtle.circle(-90, 40)

# 花瓣2
turtle.left(180)
turtle.circle(90, 40)
turtle.circle(-80, 98)
turtle.setheading(-83)

# 叶子1
turtle.fd(30)
turtle.left(90)
turtle.fd(25)
turtle.left(45)
Exemplo n.º 59
0
    t.speed(turtleSpeeds[4])

    # initial pen position
    t.penup()  # don't draw while positioning
    t.setpos(penX, penY)  # set pen position


setup(windowTitle, windowWidth, windowHeight, windowWidth / 2,
      windowHeight * 0.82, bgColor)

# set up shape
t.color(lineColor)  # set pen color
t.fillcolor(fillColor)
t.width(4)  # set pen width
starPoints = 5
pointAngle = (360 / starPoints) * 2
lineLgth = 400

t.pendown()
t.begin_fill()

t.setheading(90)  # point straight up
t.right(90 + pointAngle / 2)
for i in range(1, starPoints + 1):
    t.forward(lineLgth)
    t.right(pointAngle)

t.end_fill()

t.exitonclick()  # keep window open until mouse click
Exemplo n.º 60
0
def turn_right():  # 오른쪽으로 방향을 바꿉니다.
    t.setheading(0)