Exemplo n.º 1
0
def vlocka(velikost=100, pstran=6, rev=False):
    for _ in range(pstran):
        troj(velikost / 3, 3)
        if rev:
            t.left( 360 / pstran )
        else:
            t.right( 360 / pstran )
Exemplo n.º 2
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.º 3
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.º 4
0
def alpha_beta_helper():
	global state, root, alpha_time
	initialize()
	print("PLEASE WAIT!!!")
	root = TreeNode(-1000)
	time1 = time.time()
	alpha_beta(root, 1, state)
	init_screen()
	drawLine()
	drawGrid()
	drawColumns()
	drawRows()
	caliberate()
	col = root.ans
	row = -1
	turtle.onscreenclick(goto)
	for i in range(4):
		if state[i][col] == 0:
			row = i
			break
	state[row][col] = 1
	drawDot(row, col, 1)
	var = (int)(input("Enter 1 to continue playing or 0 to stop."))
	time2 = time.time()
	alpha_time = time2-time1
	if(var == 1):
		turtle.clear()
		turtle.goto(0, 0)
		turtle.penup()
		turtle.right(270)
		alpha_beta_helper()
	else:
		write_analysis(3)
Exemplo n.º 5
0
def hang():
	turtle.speed(0)
	if stage[0]==0:
		go_to(-300,0,0)
		turtle.forward(600)
		go_to(-100,0, 90)
		turtle.forward(200)
		turtle.right(90)
		turtle.forward(100)
		turtle.right(90)
		turtle.forward(25)
	elif stage[0]==1:
		go_to(0, 150, 0)
		turtle.circle(12.5)
	elif stage[0]==2:
		go_to(0,150, -90)
		turtle.forward(50)
	elif stage[0]==3:
		go_to(0,140, -45)
		turtle.forward(25)
		go_to(0,140, -135)
		turtle.forward(25)
	elif stage[0]==4:
		go_to(0,100, -45)
		turtle.forward(25)
		go_to(0,100, -135)
		turtle.forward(25)
	stage[0]+=1
	return 0
Exemplo n.º 6
0
def star(points, length):  # Defines a function polygon with respect to the number of points on the star and its length.

    for i in range(points):  # For loop used to draw the star using the users input for length.
        turtle.right(180 / points)
        turtle.forward(length)
        turtle.left((90 / points) + 90)
        turtle.forward(length)
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 draw_fractal2(turtle, size):
	for i in range(1,5):
		for i in range(1,3):
			draw_fractal(turtle, size)
			turtle.forward(size * 3)
		turtle.forward(size * 3)
		turtle.right(90)
Exemplo n.º 9
0
def draw_fractal4(turtle, size):
	for i in range(1,5):
		for i in range(1,3):
			draw_fractal3(turtle, size)
			turtle.forward(size * 27)
		turtle.forward(size * 27)
		turtle.right(90)
Exemplo n.º 10
0
def cross( x, y, scale, fill, color ):
	'''draws a cross given location, scale, and color'''
	goto( x, y )
	
	if fill == "True":
		'''if the scale is 1, and fill == True
			then this function will draw a cross 
			with its left point at (x,y) and
			will have lengths of 50 and widths of 15
			and filled with the color given'''
		t.begin_fill()
		t.color(color)
		for i in range(4):
			t.forward(50*scale)
			t.right(90)
			t.forward(50*scale)
			t.left(90)
			t.forward(15*scale)
			t.left(90)
		t.end_fill()
	else: 
		'''if the scale is 1, and fill == False
			then this function will draw a cross 
			with its left point at (x,y) and
			will have lengths of 50 and widths of 15
			and with no color fill'''
		for i in range(4):
			t.forward(50*scale)
			t.right(90)
			t.forward(50*scale)
			t.left(90)
			t.forward(15*scale)
			t.left(90)
Exemplo n.º 11
0
def draw_star(size, color):

    turtle.pendown()
    turtle.begin_fill()
    turtle.color(1,1,1)
    turtle.forward(2.5) 
    turtle.left(size)
    turtle.forward(2.5)
    turtle.right(144)
    turtle.forward(2.5)
    turtle.left(size)
    turtle.forward(2.5)
    turtle.right(144)
    turtle.forward(2.5)
    turtle.left(size)
    turtle.forward(2.5)
    turtle.right(144)
    turtle.forward(2.5)
    turtle.left(size)
    turtle.forward(2.5)
    turtle.right(144)
    turtle.forward(2.5)
    turtle.left(size)
    turtle.forward(2.5)
    turtle.right(144)
    turtle.end_fill()
    turtle.penup()
Exemplo n.º 12
0
def treeType(type):
    """
    This function draws a tree randomly
    :param type: type is any integer between 1-3
    :pre: pos (0,0), heading (east), up
    :post: pos (100,0), heading (east), up
    :return: wood used to make the tree
    """
    global maxheight
    randvalue = 0
    if type == 1:
        randvalue = random.randint(50, 200)
        makeTrunk(randvalue)
        makePolygon(3, 50)
    if type == 2:
        randvalue = random.randint(50, 150)
        makeTrunk(randvalue)
        makePolygon(4, 50)
    if type == 3:
        randvalue = random.randint(50, 150)
        makeTrunk(randvalue)
        makePolygon(0, 25)

    t.right(90)
    t.forward(randvalue)
    t.left(90)
    t.forward(100)
    if randvalue + 50 > maxheight:
        maxheight = randvalue + 50
    return randvalue
Exemplo n.º 13
0
def star( x, y, scale, fill, color ):
	'''draws a star given location, scale, and color'''
	goto( x, y )
	
	if fill == "True":
		'''if the scale is 1, and fill == True
			then this function will draw a star 
			with its left point at (x,y) and
			will have star ray lengths of 50
			and filled with the color given'''
		t.begin_fill()
		t.color(color)
		for i in range(10):
			t.forward(50*scale)
			t.right(108)
			t.forward(50*scale)
			t.left(144)
		t.end_fill()
	else: 
		'''if the scale is 1, and fill == False
			then this function will draw a star 
			with its left point at (x,y) and
			will have star ray lengths of 50
			and with no color fill'''
		t.begin_fill()
		for i in range(10):
			t.forward(50*scale)
			t.right(108)
			t.forward(50*scale)
			t.left(144)
Exemplo n.º 14
0
def shape(length,sides):
	if sides < 3:
		sides =3
	angle = 360/sides
	for i in range(sides):
		t.forward(length)
		t.right(angle)
Exemplo n.º 15
0
def demo():
    turtle.forward(100)
    turtle.left(120)
    turtle.forward(80)
    turtle.right(90)
    turtle.forward(80)
    turtle.exitonclick()
Exemplo n.º 16
0
def draw_rectangle(length_float, width_float, color_str):
    """
    Asks for the length, width, and color of the rectangle and draws it
    using turtle
    
    Recieve:    The length, width and color of the triangle
    Return:     Nothing
    Algorithm:
        Use a for loop and draw a rectangle by going forward the specified
        length and making a 90 degree turn to the right and then going
        forward the width and turning 90 degrees to the right
        Then do the loop again
    """
    
    turtle.fillcolor(color_str)    
    turtle.pendown()
    turtle.begin_fill()
    
    for i in range(2):
        turtle.forward(length_float)
        turtle.right(90)
        turtle.forward(width_float)
        turtle.right(90)
        
    turtle.end_fill()
    turtle.penup()
Exemplo n.º 17
0
def plano2d():
  turtle.penup()

  for i in range(13):
    y = 264 - (44 *i)
    turtle.penup()
    turtle.setposition(-264,y)
    turtle.pendown()
    turtle.forward(528)
  
  turtle.right(90)

  for i in range(13):
    x = -264 + (44*i)
    turtle.penup()
    turtle.setposition(x,264)
    turtle.pendown()
    turtle.forward(528)
  
  turtle.penup()
  turtle.home()
  turtle.pendown()
  turtle.color("blue")         
  turtle.pensize(3)

  for i in range(4):
    grados = 90 * (i+1)
    turtle.home()
    turtle.left(grados)
    turtle.forward(264) 
Exemplo n.º 18
0
def dragon(level=1, remove_plus_minus=False, width=5):

    a = 'FX'

    rule = {
        'X': 'X+YF+',
        'Y': '-FX-Y',
        '-': '-',
        '+': '+',
        'F': 'F',
    }

    for _ in range(level):
        a = ''.join(rule[x] for x in a)

    print('len:', len(a))

    a = a.replace('X', '').replace('Y','')
    print('len without X, Y:', len(a))
    
    if remove_plus_minus:
        a = a.replace('+-', '').replace('-+', '')
        print('len without -+, +-:', len(a))
            
    for x in a:
        if x == 'F':
            turtle.forward(width)
        elif x == '+':        
            turtle.right(90)
            turtle.color('red')
        elif x == '-':
            turtle.left(90)
            turtle.color('green')

    print('OK')
Exemplo n.º 19
0
def leaf( x, y, scale, color ):
	'''draws a leaf given location and scale'''
	goto( x, y )
	turtle.begin_fill()
	turtle.color(color)
	turtle.right(30)
	turtle.forward(8.33*scale)
	turtle.left(120)
	turtle.forward(3.33*scale)
	turtle.right(105)
	turtle.forward(15*scale)
	turtle.left(110)
	turtle.forward(5*scale)
	turtle.right(95)
	turtle.forward(15*scale)
	turtle.left(150)
	turtle.forward(15*scale)
	turtle.right(95)
	turtle.forward(5*scale)
	turtle.left(110)
	turtle.forward(15*scale)
	turtle.right(105)
	turtle.forward(3.33*scale)
	turtle.left(120)
	turtle.forward(8.33*scale)
	turtle.left(60)
	turtle.forward(10*scale)
	turtle.left(30)
	turtle.forward(10*scale)
	turtle.left(180)
	turtle.forward(10*scale)
	turtle.left(75)
	turtle.end_fill()
	turtle.forward(8.33*scale)
Exemplo n.º 20
0
def circle(r, n, angle):
	turtle.seth(angle)
	a = 2*r*sin(pi/n)
	phi = 180*(1-2/n)
	for i in range(int(n/2)+1):
		turtle.forward(a)
		turtle.right(180-phi)
Exemplo n.º 21
0
def draw_vertrect(length,width,color):
    turtle.pendown()
    turtle.color(color)
    turtle.begin_fill()
    #uses color to determine length of cross
    if(color=="blue" or color == "red" or color == "light coral" or color=="yellow"):
        length*=.4375
    elif(color == "snow"or color=="navy" ):
        length*=.42857
    else:
        length*=.375
    print("the length of the first " , length, " and the width is ", width)
    #loops to draw vertical rectangle
    for x in range(5):
        if(x%5==0):
            #draws first half of left vertical line
            turtle.forward((length))
            print("drawing length")
        #draws from top of vertical to bottom of flag
        elif(x%2==0):
            turtle.forward(length*2+width)
            print("drawing long side")
        #draws small side of vertical rectangle
        elif(x!=5):
            turtle.forward(width)
        turtle.right(90)
    turtle.end_fill()
def draw_square_and_circle():
    window = turtle.Screen()
    window.bgcolor("red")
    
    count = 0
    while count < 4:
        turtle.position()
        turtle.forward(100)
        turtle.right(90)
        count = count + 1
    
    angie = turtle.Turtle()
    angie.shape("arrow")
    angie.color("blue")
    angie.circle(100)
    
    todd = turtle.Turtle()
    todd.shape("arrow")
    todd.color("green")
    
    todd_count = 0
    whilte todd_count < 3:
        todd.forward(300)
        todd.left(120)
        todd_count = todd_count + 1
Exemplo n.º 23
0
def draw_tree(depth, height, branches, leafs, angle):
    """
    Draws the tree using recursion
    :pre: pos(0,0), heading east, up
    :post: pos(0,0), heading east, up
    :param depth: number of layers of sub branches (recursion depth)
    :param height: height of tree
    :param branches: number of branches
    :param leafs: number of leafs
    :param angle: angle between branches
    :return: None
    """
    if depth == 0:
        leafs = random.randint(0, leafs)
        draw_leaf(leafs)
        t.down()
        pass

    else:
        t.color('brown')
        t.forward(height)
        for i in range(1, branches+1):
            t.left(90 - i * angle)
            #random branches
            branches = random.randint(branches-1,branches+5)
            draw_tree(depth - 1, height * HEIGHT_FACTOR, branches, leafs, angle)
            t.right(90 - i * angle)
            #random angle
            angle = random.randint(angle-1, angle+1)
            if depth == 1:
                break
        t.color('brown')
        t.backward(height)
Exemplo n.º 24
0
def drawMyTree(trunk):
    """
    Draws the tree of type MyTree
    :pre: (relative) pos (0,0), heading (north), up
    :post: (relative) pos (0,0), heading (north), up
    :return: height of tree
    """
    drawTrunk(trunk)
    turtle.right(60)
    turtle.forward(30)
    turtle.left(60)
    turtle.forward(60)
    turtle.left(60)
    turtle.forward(30)
    turtle.left(60)
    turtle.forward(30)
    turtle.left(60)
    turtle.forward(60)
    turtle.left(60)
    turtle.forward(30)
    turtle.right(60)
    turtle.forward(trunk)
    turtle.left(90)
    height = trunk + (30 * (3 ** 0.5) + 60)
    return height
Exemplo n.º 25
0
def robber_move(turtle):
    fifty_fifty = random.randrange(0, 2)
    if fifty_fifty == 0:
        turtle.right(90)
    else:
        turtle.left(90)
    turtle.forward(10)
def drawS(length):
    """
    Draw English character 'S'
    :pre: (relative) pos (X,Y), heading (east), up
    :post: (relative) pos (X+length,Y), heading (east), up
    :return: None
    """
    turtle.up()
    turtle.left(90)
    turtle.forward(length)
    turtle.right(90)
    turtle.down()
    turtle.forward(length)
    turtle.right(180)
    turtle.forward(length)
    turtle.left(90)
    turtle.forward(length / 2)
    turtle.left(90)
    turtle.forward(length)
    turtle.right(90)
    turtle.forward(length / 2)
    turtle.right(90)
    turtle.forward(length)
    turtle.right(180)
    turtle.forward(length)
    turtle.up()
Exemplo n.º 27
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.º 28
0
def draw_leaf(no_of_leafs):
    """
    Draws leafs at the end of branch. Min 0 and max = no_of_leafs
    :pre: pos(0,0), heading east, up
    :post: pos(0,0), heading east, up
    :param no_of_leafs: maximum number of leads drawn
    :return: None
    """
    for i in range(no_of_leafs):
        # draws random poylgon from triangle to hexagon
        sides = random.randint(3, 6)
        color = random.choice(COLORS)
        size = 10
        angle = 360/sides
        t.left(90 - i * angle)
        t.right(90)
        t.begin_fill()
        t.down()
        t.color(color)
        for _ in range(sides):
            t.forward(size)
            t.left(angle)
        t.left(90)
        t.up()
        t.end_fill()
        t.right(90 - i * angle)

    global LEAF_COUNTER
    LEAF_COUNTER += 1
Exemplo n.º 29
0
def y_tree(length = 200):
    """
    This function receives a length and draws a tree according to the length
    in an angle 60 between the branches always reducing the next length by
    0.6. The drawing ends when the length is smaller than 10
    :param length: The length of the branch to draw, default 200
    :return: None
    """
    ANGLE_BETWEEN_BRANCHES = 60
    LENGTH_REDUCTION = 0.6
    MIN_LENGTH = 10


    if length <= MIN_LENGTH:
        return
    else:
        turtle.forward(length)                  # draws the branch
        turtle.left(ANGLE_BETWEEN_BRANCHES / 2)
        y_tree(LENGTH_REDUCTION * length)       # draws the left branch

        turtle.right(ANGLE_BETWEEN_BRANCHES)
        y_tree(LENGTH_REDUCTION * length)       # draws the right branch

        turtle.left(ANGLE_BETWEEN_BRANCHES / 2)
        turtle.backward(length)                 # returns back to draw next
Exemplo n.º 30
0
def f(l, n):
	t.up()
	t.goto( - l / 2, l / 3 )
	t.down()
	for i in rang(3):
		vk(l, n)
		t.right(120)
Exemplo n.º 31
0
 def tortue_mini_spirale(self, debu1, debu2):
     turtle.shape("turtle")
     for pas in range(debu1, debu2, 2):
         turtle.forward(pas)
         turtle.right(pas)
Exemplo n.º 32
0
# Emma Stoverink
# September 7, 2018
# Problem: Draw four connected circles for the turtle when given a radius

import turtle

# Get radius from turtle
radius = int(input("Please enter a radius for the turtle:"))

# Draw the bottom two circles
turtle.circle(radius)
turtle.penup()
turtle.forward(radius * 2)
turtle.pendown()
turtle.circle(radius)
turtle.penup()
turtle.right(90)
turtle.forward(radius * 2)
turn.left(180)
turtle.pendown()
turtle.circle(radius)
Exemplo n.º 33
0
t.left(90)
t.forward(100)
t.left(90)
t.forward(100)
t.left(90)




t.up()
t.goto(20,20)
t.down()
t.color("green")

t.forward(100)
t.right(60)
t.forward(100)
t.right(60)
t.forward(100)
t.right(60)



t.up()
t.goto(100,100)
t.down()
t.color("green")
t.forward(100)
t.left(144)
t.forward(100)
t.left(144)
Exemplo n.º 34
0
def drawUSFlag():
    #adjust the direction of the turtle
    turtle.right(90)
    #initialize color filling of the stripes
    for n in range(6):
        turtle.fillcolor("maroon")
        turtle.begin_fill()
        #outline the stripes part
        for n in range(2):
            turtle.forward(10)
            turtle.right(90)
            turtle.forward(250)
            turtle.right(90)
        turtle.end_fill()
        turtle.forward(20)
    turtle.fillcolor("maroon")
    turtle.begin_fill()
    for n in range(2):
        turtle.forward(10)
        turtle.right(90)
        turtle.forward(250)
        turtle.right(90)
    turtle.end_fill()
    #go to the initial place of the blue part
    turtle.forward(10)
    turtle.right(90)
    turtle.forward(250)
    turtle.right(90)
    turtle.forward(130)
    #initialize the color filling of the blue part
    turtle.fillcolor("blue")
    turtle.begin_fill()
    #outline the blue part
    for n in range(2):
        turtle.right(90)
        turtle.forward(110)
        turtle.right(90)
        turtle.forward(70)
    turtle.end_fill()
    #adjust the direction and positon of pen to draw stars
    turtle.right(90)
    turtle.penup()
    turtle.forward(5)
    turtle.right(90)
    turtle.forward(10)
    turtle.left(90)
    turtle.pendown()
    #draw stars
    turtle.color("white")
    turtle.fillcolor("white")
    for n in range(2):
        #draw the first line of the stars
        for n in range(5):
            turtle.begin_fill()
            drawStar(10)
            turtle.end_fill()
            turtle.penup()
            turtle.left(108)
            turtle.forward(18)
            turtle.pendown()
        turtle.begin_fill()
        drawStar(10)
        turtle.end_fill()
        turtle.penup()
        turtle.left(18)
        turtle.forward(15)
        turtle.right(90)
        turtle.forward(80)
        turtle.left(180)
        turtle.pendown()
        #draw the second line of the stars
        for n in range(5):
            turtle.begin_fill()
            drawStar(10)
            turtle.end_fill()
            turtle.penup()
            turtle.left(108)
            turtle.forward(18)
            turtle.pendown()
        turtle.penup()
        turtle.right(90)
        turtle.forward(15)
        turtle.right(90)
        turtle.forward(100)
        turtle.left(180)
        turtle.pendown()
    #move the pen to where the last line of stars start
    for n in range(5):
        turtle.begin_fill()
        drawStar(10)
        turtle.end_fill()
        turtle.penup()
        turtle.left(108)
        turtle.forward(18)
        turtle.pendown()
    #draw the last line of stars
    turtle.fillcolor("white")
    turtle.begin_fill()
    drawStar(10)
    turtle.end_fill()
Exemplo n.º 35
0
def drawPAKFlag():
    #draw the outline of the flag
    for n in range(2):
        turtle.right(90)
        turtle.forward(130)
        turtle.right(90)
        turtle.forward(250)
    #draw and fill the green part of the flag
    turtle.fillcolor("green")
    turtle.begin_fill()
    for n in range(2):
        turtle.right(90)
        turtle.forward(130)
        turtle.right(90)
        turtle.forward(188)
    turtle.end_fill()
    #adjust the position of turtle to where the star starts
    turtle.penup()
    turtle.right(90)
    turtle.forward(50)
    turtle.right(90)
    turtle.forward(50)
    turtle.pendown()
    #draw the star
    turtle.color("white")
    turtle.fillcolor("white")
    turtle.begin_fill()
    drawStar(25)
    turtle.end_fill()
    #adjust the position of turtle to where the crescent starts
    turtle.penup()
    turtle.left(36 * 3)
    turtle.forward(40)
    turtle.left(90)
    turtle.forward(40)
    #draw the crescent
    turtle.pendown()
    turtle.left(90)
    drawCrescent(30, "white")
    turtle.hideturtle()
#draw the sun
turtle.speed(0)
turtle.pencolor("red")

size_of_sun = 10
sun_x = 0
sun_y = 300

for j in range(12):
    turtle.penup()
    turtle.goto(sun_x, sun_y)
    turtle.pendown()
    for i in range(3):
        turtle.circle(size_of_sun, 180)
        turtle.right(180)
    turtle.right(30)

# end of drawing the sun

turtle.colormode(255)

red = random.randint(0, 255)
green = random.randint(0, 255)
blue = random.randint(0, 255)
turtle.pencolor(red, green, blue)

size = 10

for k in range(10):
    x = random.randint(-400, 400)
Exemplo n.º 37
0
from turtle import left, right, forward, shape, clear, exitonclick, penup, pendown

shape("turtle")

penup()
left(180)
forward(500)
left(180)
pendown()

for i in range(10):

    left(90)
    forward(100)
    right(90)
    forward(100)
    left(135)
    forward((5000)**(1 / 2))
    left(90)
    forward((5000)**(1 / 2))
    left(90)
    forward(20000**(1 / 2))
    left(135)
    forward(100)
    left(135)
    forward(20000**(1 / 2))
    left(135)
    forward(150)

exitonclick()
Exemplo n.º 38
0
show_process = False
iterations = 1000


import turtle
if not show_process:
    turtle.tracer(0)


turtle.setup(width=600, height=500)
turtle.reset()
turtle.hideturtle()
turtle.bgcolor('black')

colors = [(1.00, 0.00, 0.00),(1.00, 0.03, 0.00),(1.00, 0.05, 0.00),(1.00, 0.07, 0.00),(1.00, 0.10, 0.00),(1.00, 0.12, 0.00),(1.00, 0.15, 0.00),(1.00, 0.17, 0.00),(1.00, 0.20, 0.00),(1.00, 0.23, 0.00),(1.00, 0.25, 0.00),(1.00, 0.28, 0.00),(1.00, 0.30, 0.00),(1.00, 0.33, 0.00),(1.00, 0.35, 0.00),(1.00, 0.38, 0.00),(1.00, 0.40, 0.00),(1.00, 0.42, 0.00),(1.00, 0.45, 0.00),(1.00, 0.47, 0.00),
(1.00, 0.50, 0.00),(1.00, 0.53, 0.00),(1.00, 0.55, 0.00),(1.00, 0.57, 0.00),(1.00, 0.60, 0.00),(1.00, 0.62, 0.00),(1.00, 0.65, 0.00),(1.00, 0.68, 0.00),(1.00, 0.70, 0.00),(1.00, 0.72, 0.00),(1.00, 0.75, 0.00),(1.00, 0.78, 0.00),(1.00, 0.80, 0.00),(1.00, 0.82, 0.00),(1.00, 0.85, 0.00),(1.00, 0.88, 0.00),(1.00, 0.90, 0.00),(1.00, 0.93, 0.00),(1.00, 0.95, 0.00),(1.00, 0.97, 0.00),
(1.00, 1.00, 0.00),(0.95, 1.00, 0.00),(0.90, 1.00, 0.00),(0.85, 1.00, 0.00),(0.80, 1.00, 0.00),(0.75, 1.00, 0.00),(0.70, 1.00, 0.00),(0.65, 1.00, 0.00),(0.60, 1.00, 0.00),(0.55, 1.00, 0.00),(0.50, 1.00, 0.00),(0.45, 1.00, 0.00),(0.40, 1.00, 0.00),(0.35, 1.00, 0.00),(0.30, 1.00, 0.00),(0.25, 1.00, 0.00),(0.20, 1.00, 0.00),(0.15, 1.00, 0.00),(0.10, 1.00, 0.00),(0.05, 1.00, 0.00),
(0.00, 1.00, 0.00),(0.00, 0.95, 0.05),(0.00, 0.90, 0.10),(0.00, 0.85, 0.15),(0.00, 0.80, 0.20),(0.00, 0.75, 0.25),(0.00, 0.70, 0.30),(0.00, 0.65, 0.35),(0.00, 0.60, 0.40),(0.00, 0.55, 0.45),(0.00, 0.50, 0.50),(0.00, 0.45, 0.55),(0.00, 0.40, 0.60),(0.00, 0.35, 0.65),(0.00, 0.30, 0.70),(0.00, 0.25, 0.75),(0.00, 0.20, 0.80),(0.00, 0.15, 0.85),(0.00, 0.10, 0.90),(0.00, 0.05, 0.95),
(0.00, 0.00, 1.00),(0.05, 0.00, 1.00),(0.10, 0.00, 1.00),(0.15, 0.00, 1.00),(0.20, 0.00, 1.00),(0.25, 0.00, 1.00),(0.30, 0.00, 1.00),(0.35, 0.00, 1.00),(0.40, 0.00, 1.00),(0.45, 0.00, 1.00),(0.50, 0.00, 1.00),(0.55, 0.00, 1.00),(0.60, 0.00, 1.00),(0.65, 0.00, 1.00),(0.70, 0.00, 1.00),(0.75, 0.00, 1.00),(0.80, 0.00, 1.00),(0.85, 0.00, 1.00),(0.90, 0.00, 1.00),(0.95, 0.00, 1.00)]

c = 0
for i in range(iterations):
    turtle.color(colors[int(c)])
    c += 0.1
    turtle.forward(i)
    turtle.right(98)


turtle.update()
turtle.exitonclick()
Exemplo n.º 39
0
def LittleHeart():
    for i in range (200):
        turtle.right(1)
        turtle.forward(2)
def drawPieChart(central_angles, angle_of_rest, probability_of_rest):
    # reset turtle to redraw the piechart if the user enters a new value for N.
    turtle.reset()

    # set color mode to accept rgb values
    window.colormode(255)
    turtle.fillcolor('gray')
    turtle.speed(10)

    # draw base circle and fill it with color
    turtle.begin_fill()
    turtle.circle(120)
    turtle.end_fill()
    turtle.up()

    angle_counter = 0
    prev_angle = 0

    # draw arc sectors for each probability in the circle
    for index, (letter, angle, probability) in enumerate(central_angles):
        if index == 0:
            # turn radians to degrees
            angle_counter += angle * (360 / math.pi)
        turtle.fillcolor((random.randrange(0, 255), random.randrange(0, 255),
                          random.randrange(0, 255)))
        turtle.begin_fill()
        turtle.goto(x=0, y=120)
        turtle.setheading(angle_counter)
        angle_counter += angle * (360 / math.pi)
        turtle.forward(120)
        turtle.right(270)
        turtle.circle(120, angle * (360 / math.pi))
        turtle.setheading(angle_counter)
        turtle.forward(50)
        turtle.write('{}, {}'.format(letter, round(probability, 3)),
                     font=("Arial", 10, "normal"))
        turtle.backward(50)
        turtle.setheading(angle * (360 / math.pi) + prev_angle)
        turtle.goto(x=0, y=120)
        turtle.end_fill()
        prev_angle += angle_counter

        # draw the arc for the remaining probabilites.
        if index == len(central_angles) - 1:
            turtle.fillcolor('gray')
            turtle.begin_fill()
            turtle.goto(x=0, y=120)
            turtle.setheading(angle_counter)
            turtle.forward(120)
            turtle.right(270)
            turtle.circle(120, angle_of_rest * (180 / math.pi))
            angle_counter += angle_of_rest * (180 / math.pi)
            turtle.setheading(angle_counter)
            turtle.forward(50)
            turtle.write('All other letters, {}'.format(
                round(probability_of_rest, 3)),
                         font=("Arial", 10, "normal"))
            turtle.backward(50)
            turtle.setheading(angle_of_rest * (180 / math.pi) + prev_angle)
            turtle.goto(x=0, y=120)
            turtle.end_fill()
Exemplo n.º 41
0
while 1==1:
	import turtle
	import random
	a = random.randint(1,4)
	if a == 1:
		turtle = turtle.left(90)
	elif a == 2:
		turtle = turtle.right(90)
	else:
		turtle.forward(5)
Exemplo n.º 42
0
def tscheme_right(n):
    """Rotate the turtle's heading N degrees clockwise."""
    _check_nums(n)
    _tscheme_prep()
    turtle.right(n)
Exemplo n.º 43
0
def coolpattern():
    for i in range(12):
        hexagonRight()
        t.right(30)
    return
    turtle.forward(30 * 3)
    turtle.left(60)
    draw_whole_cube_face(18)  #draw 'top' face
    print(colors_used)


def tilt_da_colors(start, end, increment, fake_conter):
    conter = fake_conter
    for m in range(start, end, increment):
        colors_used[m] = colors_used[conter]
        colors_used[conter] = COLORS[randint(0, 5)]
        conter = conter - 1


#drawing 2nd phase of cube
turtle.right(90)  #untilt the cube
#ORIGNAL CUBE, perfectly striped faces
drawing_cube()

turtle.up()
turtle.goto(150, -150)
turtle.down()
turtle.left(120)

tilt_da_colors(17, 10, -3, 26)

drawing_cube()

turtle.up()
turtle.goto(-150, -150)
turtle.down()
Exemplo n.º 45
0
 def draw_distributed_load(self, sxcoor, sycoor, excoor, eycoor, py1, py2,
                           orientation):
     loadarrow = 50.
     #
     # Draw the line at the base, turn to the starting position
     turtle.penup()
     turtle.setposition(sxcoor, sycoor)
     turtle.setheading(orientation)
     turtle.backward(10)
     # Note original coordinates
     xso = turtle.xcor()
     yso = turtle.ycor()
     turtle.setposition(excoor, eycoor)
     turtle.backward(10)
     xfo = turtle.xcor()
     yfo = turtle.ycor()
     turtle.pendown()
     turtle.setposition(xso, yso)
     # Get local coordinate along member axis, decide if horiz. or vertic.
     if sxcoor == excoor:  # Vertical member
         xs = yso
         xf = yfo
         ys = xso
         yf = xfo
         alignment = 'v'
     elif sycoor == eycoor:  # Horizontal member
         xs = xso
         xf = xfo
         ys = yso
         yf = yfo
         alignment = 'h'
     xdiff = xf - xs
     narrow = 11.
     x = 0.
     step = xdiff / narrow
     #
     # Make distinctions between different load cases
     #
     # Uniform loading
     if py1 == py2:
         loadtext = ''.join([str(py1), ' kN/m'])
         turtle.backward(loadarrow)
         turtle.forward(loadarrow)
         self.draw_arrow(arrowsize=5)
         turtle.backward(loadarrow)
         while x < xdiff:
             turtle.left(90)
             turtle.forward(step)
             turtle.right(90)
             turtle.forward(loadarrow)
             self.draw_arrow(arrowsize=5)
             turtle.backward(loadarrow)
             x = x + step
         turtle.penup()
         # go to midpoint of the load to write the label
         if alignment == 'h':
             turtle.setx(turtle.xcor() - xdiff / 2)
             turtle.write(loadtext,
                          align='center',
                          font=("Times New Roman", 18, ""))
         elif alignment == 'v':
             turtle.sety(turtle.ycor() - xdiff / 2)
             turtle.write(loadtext,
                          align='right',
                          font=("Times New Roman", 18, ""))
     # Triangle starting from 0 ending at Py2
     if (py1 == 0) or (py2 == 0):
         if py1 == 0:
             sgn = 1.
             loadtext = ''.join([str(py2), ' kN/m'])
             phase = 0.
             yp1 = 0.
             yp2 = loadarrow * 2
             slope = np.arctan(yp2 / xdiff)
             slopedeg = slope * 180 / np.pi
             x = xs + step
             y = ys + np.tan(slope) * step
             xs = xs
             yco = 0
         elif py2 == 0:
             sgn = -1.
             loadtext = ''.join([str(py1), ' kN/m'])
             turtle.penup()
             turtle.setposition(xfo, yfo)
             turtle.pendown()
             yp1 = loadarrow * 2
             yp2 = 0.
             slope = np.arctan(yp1 / xdiff)
             slopedeg = slope * 180 / np.pi
             phase = (180 - 2 * slopedeg)
             x = xf - step
             y = yf + np.tan(slope) * step
             xs = xf  # Drawing from left to right
             yco = 0
         while abs(x - xs) <= xdiff:
             turtle.left(90 + slopedeg + phase)
             dy = step * np.tan(slope)
             yco += dy
             dist = np.sqrt(dy**2 + step**2)
             turtle.forward(dist)
             turtle.right(90 + slopedeg + phase)
             turtle.forward(yco)
             self.draw_arrow(arrowsize=5)
             turtle.backward(yco)
             x = x + step * sgn
         turtle.write(loadtext,
                      align='center',
                      font=("Times New Roman", 18, ""))
     return
Exemplo n.º 46
0
def circle(r, angle):
    for i in range(angle):
        turtle.right(1)
        turtle.forward(r*2*math.pi/360)
Exemplo n.º 47
0
import turtle
import math

R = 50  #THE RADIUS OF THE TRIANGLE
delta_R = 30  #THE INCREMENT IF THE RADIUS
x = 10  #THE NUMBER OF THE POLYGONS
pi = 3.1415


def polygon(n):
    for i in range(n):
        l = 2 * R * (math.cos(pi * (n - 2) / (2 * n)))
        turtle.forward(l)
        turtle.left(360 / n)


for j in range(x):
    n = j + 3
    turtle.left(90 * (n + 2) / n)
    polygon(n)
    turtle.right(90 * (n + 2) / n)
    turtle.penup()
    turtle.forward(delta_R)
    turtle.pendown()
    R += delta_R
Exemplo n.º 48
0
spiral()

origin()
t.penup()
t.left(70)
t.forward(150)
t.pendown()

#parametered drawing
side = input("choose value between 1 to 50")
degree = input("choose value from 1-360")
shape(side, degree)

origin()
t.penup()
t.right(90)
t.forward(300)
t.pendown()

#second parametered drawing
side2 = input("choose value from 20-100")
shape2(side2)

origin()
t.penup()
t.right(30)
t.forward(400)
t.pendown()

#clock of colors - by shawn noruzi
atobe()
Exemplo n.º 49
0
import turtle

turtle.bgcolor("red")
turtle.fillcolor("yellow")
turtle.color('yellow')
turtle.speed(10)
#主星
turtle.begin_fill()
turtle.up()
turtle.goto(-600,220) 
turtle.down()
for i in range (5):    
    turtle.forward(150)
    turtle.right(144)
turtle.end_fill()

#第1颗副星
turtle.begin_fill()
turtle.up()
turtle.goto(-400,295)
turtle.down()
for i in range (5):    
    turtle.forward(50)
    turtle.left(144)

turtle.end_fill()


#第2颗副星
turtle.begin_fill()
turtle.up()
Exemplo n.º 50
0
#   在屏幕中画出四个正六边形
#++++++++++++++++++++++++++++++++++++++++++++++++

import turtle

side = eval(input("输入六边形边长:"))

pos = side * 3**0.5 / 2
turtle.penup()
turtle.goto(-pos, 0)
turtle.pendown()
turtle.left(30)
for i in range(6):
    turtle.forward(side)
    turtle.left(60)
turtle.right(60)
for i in range(6):
    turtle.forward(side)
    turtle.right(60)

turtle.penup()
turtle.goto(pos, 0)
turtle.pendown()
turtle.left(60)
for i in range(6):
    turtle.forward(side)
    turtle.left(60)
turtle.right(60)
for i in range(6):
    turtle.forward(side)
    turtle.right(60)
import turtle as t

size = 300
points = 11
angle = 180 - (180 / points)

t.color('red')
t.begin_fill()
for i in range(points):
    t.forward(size)
    t.right(angle)

t.end_fill()
Exemplo n.º 52
0
'''
import turtle as t
t.right(30)
t.fd(200)
t.right(-60)
t.fd(200)
t.right(-120)
t.fd(200)
t.right(-60)
t.fd(200)
t.done()
'''
import turtle as t
t.right(-30)
for i in range(2):
    t.fd(200)
    t.right(60 * (i + 1))
for i in range(2):
    t.fd(200)
    t.right(60 * (i + 1))
t.done()
def drawLine(draw):#绘制单段数码管
    turtle.pendown() if draw else turtle.penup()
    turtle.fd(40)
    turtle.right(90)
Exemplo n.º 54
0
#######################################################
# Name:       Justin Pawlarczyk
# Class:      CIS-1400
# Assignment: Practice 05b
# File:       Practice_05b.py
# Purpose:    Draw increasing square pattern
#######################################################

print('\n**  Justin Pawlarczyk  **\n')  # Display author's name

import turtle  # Turtle is used for this program

# starting length of square is 50 pixels
length = 50
turtle.speed(0)
# square is incresed by 5 pixels and turned 10 degrees for each drawn square
for squares_counted in range(0, 37):
    length += 5
    for squares_counted in range(
            0, 4):  # Starting length of each side turned 90 degrees
        turtle.forward(length)
        turtle.right(90)
    turtle.right(10)  # Turn turtle right 10 degrees
Exemplo n.º 55
0
def drawwjx(x):
    turtle.begin_fill()
    for i in range(5):
        turtle.forward(x)
        turtle.right(144)
    turtle.end_fill()
Exemplo n.º 56
0
f.close()
'''

#行进距离  转向判断  转向角度
import turtle

turtle.clear()
turtle.title("自动绘制轨迹")
turtle.setup(800, 600, 0, 0)
turtle.pencolor("red")
turtle.pensize(5)

#加载文件
datals = []
f = open("data.txt", "r", encoding="UTF-8")
for line in f:
    line = line.replace("\n", "")
    datals.append(list(map(eval, line.split(","))))  #将字符串数据变成数字

#解析文件,绘制图形
for i in range(len(datals)):
    turtle.pencolor(datals[i][3], datals[i][4], datals[i][5])
    turtle.fd(datals[i][0])
    if datals[i][1]:
        turtle.right(datals[i][2])
    else:
        turtle.left(datals[i][2])

turtle.hideturtle()
turtle.done()
Exemplo n.º 57
0
# squarespirall.py -- Draws a square spirall

import turtle
# t = turtle.pen()
for x in range(300):
    turtle.forward(x)
    turtle.right(225)
Exemplo n.º 58
0
import turtle as t
t.setup(1000,800)
t.pu()
t.fd(-400)
t.goto(-400,300)
t.pd()
t.pensize(5)
t.pencolor("red")
#正方形
for i in range(4):
    t.pencolor("blue")
    t.fd(80)
    t.right(90)
t.pu()
t.goto(-250,300)
t.pd()
#六边形
for i in range(6):
    t.fd(80)
    t.right(60)
t.pu()
t.goto(-300,-100)
t.pd()
#九角心
t.fillcolor("red")
t.begin_fill()
for i in range(9):
    t.fd(150)
    t.left(80)
t.end_fill()
t.pu()
Exemplo n.º 59
0
from turtle import forward,right,left, backward,exitonclick,speed

# Kochova vločka
def koch(length,depth):
    # Pokud je depth==0 nakresli úsečku délky length
    if depth == 0:
        forward(length)
        return
    # Jinak 4x zavolej koch(length/3,depth-1)
    # a nakresli tím čáru se "zubem"
    koch(length/3,depth-1)
    left(60)
    koch(length/3,depth-1)
    right(120)
    koch(length/3,depth-1)
    left(60)
    koch(length/3,depth-1)

speed(10)
koch(400,5)
right(120)
koch(400,5)
right(120)
koch(400,5)
exitonclick()
Exemplo n.º 60
0
import turtle
s = input()
turtle.shape('turtle')
turtle.pendown()
while s != '0':
    if s == 'l': turtle.left(90)
    elif s == 'r': turtle.right(90)
    elif s == 'g': turtle.forward(50)
    s = input()