Ejemplo n.º 1
0
def drawLine():
	turtle.penup()
	turtle.goto(-50, 300)
	turtle.pendown()
	turtle.write("Base Line", font=("Arial", 14, "normal"))
	turtle.color("red")
	turtle.forward(500)
Ejemplo 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()
Ejemplo n.º 3
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)
Ejemplo n.º 4
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
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
def koch(niveau=3, iter=0, taille=100, delta=0):
    """
    Tracé du flocon de Koch de niveau 'niveau', de taille 'taille'
    (px).

    Cette fonction récursive permet d'initialiser le flocon (iter=0,
    par défaut), de tracer les branches fractales (0<iter<=niveau) ou
    bien juste de tracer un segment (iter>niveau).
    """

    if iter == 0:                         # Dessine le triangle de niveau 0
        T.title("Flocon de Koch - niveau {}".format(niveau))
        koch(iter=1, niveau=niveau, taille=taille, delta=delta)
        T.right(120)
        koch(iter=1, niveau=niveau, taille=taille, delta=delta)
        T.right(120)
        koch(iter=1, niveau=niveau, taille=taille, delta=delta)
    elif iter <= niveau:                  # Trace une section _/\_ du flocon
        koch(iter=iter + 1, niveau=niveau, taille=taille, delta=delta)
        T.left(60 + delta)
        koch(iter=iter + 1, niveau=niveau, taille=taille, delta=delta)
        T.right(120 + 2 * delta)
        koch(iter=iter + 1, niveau=niveau, taille=taille, delta=delta)
        T.left(60 + delta)
        koch(iter=iter + 1, niveau=niveau, taille=taille, delta=delta)
    else:                               # Trace le segment de dernier niveau
        T.forward(taille / 3 ** (niveau + 1))
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
def theStem(stemLength=100):
	turtle.home()
	turtle.forward(25)
	turtle.left(90)
	turtle.pensize(4)
	turtle.color("green")
	turtle.forward(stemLength)
Ejemplo n.º 9
0
def entrance(pointOne):
    turtle.goto(pointOne[0], pointOne[1] + 36)
    turtle.setheading(270)
    turtle.pendown()
    turtle.forward(15)
    turtle.penup()
    drawArrows()
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo 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
Ejemplo n.º 13
0
def at(x, y):
    turtle.penup()
    turtle.home()
    turtle.forward(x)
    turtle.left(90)
    turtle.forward(y)
    turtle.pendown()
Ejemplo n.º 14
0
def draw_regular_hexagon(l):
    i=0
    while(i<6):
        turtle.forward(l)
        turtle.left(60)
        i=i+1
    turtle.done()
Ejemplo n.º 15
0
 def draw(self):
     for i in range(0,2):
         turtle.forward(self.length)
         turtle.left(90)
         turtle.forward(self.width)
         turtle.left(90)
     turtle.done()
Ejemplo n.º 16
0
def shape(length,sides):
	if sides < 3:
		sides =3
	angle = 360/sides
	for i in range(sides):
		t.forward(length)
		t.right(angle)
Ejemplo n.º 17
0
def draw_triangle(l):
    i=0
    while(i<3):
        turtle.forward(l)
        turtle.left(120)
        i=i+1
    turtle.done()
Ejemplo n.º 18
0
def newrow(turtle,length):
	turtle.right(90)
	turtle.forward(100)
	turtle.right(90)
	turtle.forward(length*100)
	turtle.right(180)
	randcolor(turtle)
Ejemplo n.º 19
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()
def hexagon(sidelen,turtle):
   # turtle.begin_fill()
    for x in range(0, 6):
        #move forward sidelen
        turtle.forward(sidelen)
        #rotate 90 degrees to the left
        turtle.left(60)
Ejemplo n.º 21
0
def koch(t, order, size):
    if order == 0:
        t.forward(size)
    else:
        for angle in [60, -120, 60, 0]:
            koch(t, order - 1, size / 3)
            t.left(angle)
Ejemplo n.º 22
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 Minkovskiy(l, n):
	if n == 0:
		turtle.forward(l)
	else:
		for angle in [90, -90, -90, 0, 90, 90, -90, 0]:
			Minkovskiy(l/4, n-1)
			turtle.left(angle)
Ejemplo n.º 24
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
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
Ejemplo n.º 26
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)
Ejemplo n.º 27
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)
Ejemplo n.º 28
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)
Ejemplo n.º 29
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")
Ejemplo n.º 30
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')
Ejemplo n.º 31
0
def star(sidelength):
    for i in range(5):
        turtle.forward(sidelength)
        turtle.right(144)
Ejemplo n.º 32
0
import turtle as t
t.speed("fastest")
t.pensize(2)
t.colormode(255)
coloes = ["blue", "green", "red", "gray"]
i = 1
for r in range(255):
    for g in range(255):
        for b in range(255):
            t.color(r, g, b)
            t.forward(4 * i / 100)
            i = 1 + i
            t.left(91)
t.done()

#     # t.pencolor(coloes[i%4])
#     t.pencolor(i,i,i)
#     t.forward(4*i)
#     t.left(91)
# t.done()
Ejemplo n.º 33
0
from turtle import forward, left, exitonclick

for i in range(3):
    forward(100)
    left(120)
Ejemplo n.º 34
0
def pround(n):#полуокружность
	for i in range(n):
		turtle.forward(3)
		turtle.right(180/n)
Ejemplo n.º 35
0
def cir(n):#окружность
	for i in range(1, n+1, 1):
		turtle.forward(3)
		turtle.left(360/n)
Ejemplo n.º 36
0
turtle.begin_fill()
turtle.color('blue')
cir(20)
turtle.end_fill()

turtle.penup()
turtle.goto(50, 50)
turtle.pendown()
turtle.begin_fill()
turtle.color('blue')
cir(20)
turtle.end_fill()

turtle.penup()
turtle.goto(0, 40)
turtle.pendown()
turtle.begin_fill()
turtle.color('black')
turtle.left(180)
turtle.width(8)
turtle.forward(30)
turtle.end_fill()

turtle.penup()
turtle.goto(50, 5)
turtle.pendown()
turtle.color('red')
turtle.width(8)
pround(50)

Ejemplo n.º 37
0
import turtle

turtle.penup()
turtle.goto(0, 50)
turtle.pendown()

turtle.right(60)
turtle.forward(100)
turtle.right(120)
turtle.forward(100)
turtle.right(120)
turtle.forward(200)

turtle.left(120)
turtle.forward(100)
turtle.left(120)
turtle.forward(100)

turtle.done()
Ejemplo n.º 38
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)
Ejemplo n.º 39
0
def right(distance):
    time.sleep(0.100)
    if (distance > threshold):
        turtle.forward(distance)
        left(distance * ratio)
        turtle.forward(distance)
        left(distance * ratio)
        turtle.forward(distance)
        left(distance * ratio)
    else:
        turtle.forward(distance - distance * ratio * ratio)
        turtle.left(90)
        turtle.forward(distance - distance * ratio * ratio)
        turtle.left(90)
        turtle.forward(distance - distance * ratio * ratio)
        turtle.left(90)
Ejemplo n.º 40
0
import turtle as t  # turtle이라는 외부 툴을 가져와서 사용, 약어 t로 사용
t.shape('turtle')  # 펜의 모양
t.color('pink')  # 펜의 컬러
for i in range(4):  # 앞으로 100, 오른쪽으로 90도 꺽는 것을 4번 반복
    t.forward(100)
    t.right(90)

t2 = t.Pen()  # 펜 기능을 t2에 부여
t2.shape('turtle')
t2.color('red')
t2.penup()  # 펜을 듬
t2.goto(-200, 100)  # 펜을 해당 좌표로 이동
t2.pendown()
t2.begin_fill()
t2.fillcolor('orange')
t2.circle(25)  # 반지름 기준으로 원을 그림
t2.end_fill()

t3 = t.Pen()
t3.shape('turtle')
t3.shapesize(5)
t3.color('blue')
t3.penup()
t3.goto(100, 100)
t3.pendown()
for i in range(5):
    t3.fd(100)
    t3.right(72)

t4 = t.Pen()
t4.shape('turtle')
Ejemplo n.º 41
0
def InitTail():
    # 尾巴
    t.begin_fill()
    t.fillcolor("yellow")
    t.pu()  # 提笔
    t.goto(64, -140)  # 笔头初始位置
    t.pd()  # 下笔
    t.setheading(10)  # 画笔角度
    t.forward(20)
    t.setheading(90)  # 画笔角度
    t.forward(20)
    t.setheading(10)  # 画笔角度
    t.forward(10)
    t.setheading(80)  # 画笔角度
    t.forward(100)
    t.setheading(35)  # 画笔角度
    t.forward(80)
    t.setheading(260)  # 画笔角度
    t.forward(100)
    t.setheading(205)  # 画笔角度
    t.forward(40)
    t.setheading(260)  # 画笔角度
    t.forward(37)
    t.setheading(205)  # 画笔角度
    t.forward(20)
    t.setheading(260)  # 画笔角度
    t.forward(25)
    t.setheading(175)  # 画笔角度
    t.forward(30)
    t.setheading(100)  # 画笔角度
    t.forward(13)
    t.end_fill()
import turtle
turtle.fillcolor('white')
turtle.begin_fill()
turtle.showturtle()
turtle.speed(50)
turtle.right(45)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(100)
turtle.end_fill()
turtle.done()
Ejemplo n.º 43
0
def drawLine(angle, length):
    turtle.left(angle)
    turtle.forward(length)
Ejemplo n.º 44
0
        turtle.forward(distance - distance * ratio * ratio)
        turtle.right(90)
        turtle.forward(distance - distance * ratio * ratio)
        turtle.right(90)
        turtle.forward(distance - distance * ratio * ratio)
        turtle.right(90)


def right(distance):
    time.sleep(0.100)
    if (distance > threshold):
        turtle.forward(distance)
        left(distance * ratio)
        turtle.forward(distance)
        left(distance * ratio)
        turtle.forward(distance)
        left(distance * ratio)
    else:
        turtle.forward(distance - distance * ratio * ratio)
        turtle.left(90)
        turtle.forward(distance - distance * ratio * ratio)
        turtle.left(90)
        turtle.forward(distance - distance * ratio * ratio)
        turtle.left(90)


for i in range(4):
    right(startDistance)
    turtle.forward(startDistance / ratio)
turtle.done()
Ejemplo n.º 45
0
def drawSKFlag():
    #draw the outline of the flag
    for n in range(2):
        turtle.forward(250)
        turtle.left(90)
        turtle.forward(130)
        turtle.left(90)
    turtle.penup()
    #adjust the position of turtle to where the blue circle starts
    turtle.forward(165)
    turtle.left(90)
    turtle.forward(65)
    turtle.pendown()
    #draw the blue circle
    turtle.color("darkblue")
    turtle.fillcolor("darkblue")
    turtle.begin_fill()
    turtle.circle(40, 360)
    turtle.end_fill()
    #draw the red part of the circle
    turtle.color("maroon")
    turtle.fillcolor("maroon")
    turtle.begin_fill()
    turtle.circle(20, 180)
    turtle.circle(-20, 180)
    turtle.circle(-40, 180)
    turtle.end_fill()
    #adjust to where upper left stripes are
    turtle.color("black")
    turtle.penup()
    turtle.left(180)
    turtle.forward(40)
    turtle.right(90)
    turtle.forward(20)
    turtle.right(45)
    turtle.color("black")
    #draw the upper left group of stripes
    Line2()
    Line1()
    Line2()
    #adjust to where lower left stripes are
    gotoNext(18)
    #draw the lower left group of stripes
    Line2()
    Line2()
    Line2()
    #adjust to where lower right stripes are
    gotoNext(95)
    #draw the lower right group of stripes
    Line1()
    Line2()
    Line1()
    #adjust to where upper left stripes are
    gotoNext(18)
    #draw the upper right group of stripes
    Line1()
    Line1()
    Line1()
Ejemplo n.º 46
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()
Ejemplo n.º 47
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()
Ejemplo n.º 48
0
def drawQatarFlag():
    #draw a rectangular
    for i in range(2):
        turtle.forward(250)
        turtle.left(90)
        turtle.forward(130)
        turtle.left(90)
    #draw the colored part and fill maroon
    turtle.forward(50)
    turtle.fillcolor("maroon")
    turtle.begin_fill()
    turtle.left(math.atan(65 / (9 * 20)) / math.pi * 180)
    turtle.forward((20**2 + (65 / 9)**2)**0.5)
    #outline the colred part
    for n in range(8):
        turtle.left(180 - 2 * math.atan(65 / (9 * 20)) / math.pi * 180)
        turtle.forward((20**2 + (65 / 9)**2)**0.5)
        turtle.right(180 - 2 * math.atan(65 / (9 * 20)) / math.pi * 180)
        turtle.forward((20**2 + (65 / 9)**2)**0.5)
    turtle.left(180 - 2 * math.atan(65 / (9 * 20)) / math.pi * 180)
    turtle.forward((20**2 + (65 / 9)**2)**0.5)
    turtle.right(180 - math.atan(65 / (9 * 20)) / math.pi * 180)
    turtle.forward(200)
    turtle.right(90)
    turtle.forward(130)
    turtle.right(90)
    turtle.forward(200)
    turtle.end_fill()
    turtle.hideturtle()
Ejemplo n.º 49
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()
Ejemplo n.º 50
0
def Line2():
    #draw the first part of the stripe
    turtle.fillcolor("black")
    turtle.begin_fill()
    for n in range(2):
        turtle.forward(18)
        turtle.left(90)
        turtle.forward(5)
        turtle.left(90)
    turtle.end_fill()
    #adjust turtle to where the second part of the stripe begins
    turtle.penup()
    turtle.forward(22)
    turtle.pendown()
    #draw the second part of the stripe
    turtle.begin_fill()
    for n in range(2):
        turtle.forward(18)
        turtle.left(90)
        turtle.forward(5)
        turtle.left(90)
    turtle.end_fill()
    #move to the position next strike might be
    turtle.penup()
    turtle.left(180)
    turtle.forward(22)
    turtle.right(90)
    turtle.forward(8)
    turtle.right(90)
    turtle.pendown()
Ejemplo n.º 51
0
 def tortue_carre(self, var1, var2):
     for i in range(var1, var2):
         turtle.forward(50)
         turtle.left(90)
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)
    y = random.randint(-400, 400)
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()
    for j in range(10):
        for i in range(0, 2, 1):
            red = random.randint(230, 255)
            green = random.randint(150, 200)
            blue = random.randint(10, 60)
            turtle.pencolor(red, green, blue)

            turtle.forward(size)
            turtle.left(60)
            turtle.forward(size)
            turtle.left(120)
        turtle.left(36)

turtle.hideturtle()
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()
Ejemplo n.º 54
0
def ugras_kovetezore(hossz):
    t.up()
    t.forward(hossz)
Ejemplo n.º 55
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()
Ejemplo n.º 56
0
 def tortue_mini_spirale(self, debu1, debu2):
     turtle.shape("turtle")
     for pas in range(debu1, debu2, 2):
         turtle.forward(pas)
         turtle.right(pas)
Ejemplo n.º 57
0
def LittleHeart():
    for i in range (200):
        turtle.right(1)
        turtle.forward(2)
Ejemplo n.º 58
0
for i in range(10):
    print("I want to be a great programmer.")

for i in range(5):
    print(i)

import turtle

turtle.shape("turtle")
turtle.speed(1)
for i in range(4):
    turtle.forward(100)
    turtle.left(90)
turtle.exitonclick()

result = 0
for i in range(50):
    result = result + 1
print(result)

result = 0
for _ in range(50):
    result = result + 1
print(result)

result = 0
num = 1
for _ in range(50):
    result = result + num
    num = num + 1
print(result)
Ejemplo n.º 59
0
turtle.pensize(3)
# 速度
turtle.speed(1)
# 提笔
turtle.up()
# 隐藏笔
turtle.hideturtle()
# 去到的坐标,窗口中心为0,0
turtle.goto(0,-180)
turtle.showturtle()
# 画上线
turtle.down()
turtle.speed(1)
turtle.begin_fill()
turtle.left(140)
turtle.forward(224)
#调用画爱心左边的顶部
LittleHeart()
#调用画爱右边的顶部
turtle.left(120)
LittleHeart()
# 画下线
turtle.forward(224)
turtle.end_fill()
turtle.pensize(5)
turtle.up()
turtle.hideturtle()
# 在心中写字 一次
turtle.goto(0,0)
turtle.showturtle()
turtle.color('#CD5C5C','pink')
Ejemplo n.º 60
0
def tscheme_forward(n):
    """Move the turtle forward a distance N units on the current heading."""
    _check_nums(n)
    _tscheme_prep()
    turtle.forward(n)