def koch(size, n):
    if n == 0:
        turtle.fd(size)
    else:
        for angle in [0, 60, -120, 60]:
            turtle.left(angle)
            koch(size/3, n-1)
Beispiel #2
0
def set(): #set of parameters
    turtle.hideturtle()
    turtle.tracer(1e3,1)
    turtle.left(95)
    turtle.penup()
    turtle.goto(0,-turtle.window_height()/2)
    turtle.pendown()
Beispiel #3
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)
Beispiel #4
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 )
Beispiel #5
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()
Beispiel #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))
def polygon(side = 50, angle = None, xstart = None, ystart = None, numberSides = 3, color = 'black', fill = False):
    turtle.pensize(3)
    turtle.speed('fastest')
    turtle.hideturtle()
    if angle != None:
        turtle.left(angle)
    
    turtle.penup()
    if fill == True:
        if xstart != None or ystart != None:
            turtle.goto(xstart, ystart)
        else:
            turtle.goto(0, 0)
        turtle.color(color)
        turtle.pendown()
        turtle.begin_fill()
        turtle.circle(side, 360, numberSides)
        turtle.end_fill()
        turtle.penup()
        
    else:
        turtle.goto(xstart, ystart)
        turtle.color(color)
        turtle.pendown()
        turtle.circle(side, 360, numberSides)
        turtle.penup()
    
    return
Beispiel #8
0
def forGlory(sideLength=50):
	turtle.left(150)
	turtle.penup()
	turtle.setpos(-25,75)
	turtle.color("blue")
	turtle.pendown()
	hexagon(sideLength)
Beispiel #9
0
def theStem(stemLength=100):
	turtle.home()
	turtle.forward(25)
	turtle.left(90)
	turtle.pensize(4)
	turtle.color("green")
	turtle.forward(stemLength)
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)
Beispiel #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()
Beispiel #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
Beispiel #13
0
def at(x, y):
    turtle.penup()
    turtle.home()
    turtle.forward(x)
    turtle.left(90)
    turtle.forward(y)
    turtle.pendown()
Beispiel #14
0
def draw_regular_hexagon(l):
    i=0
    while(i<6):
        turtle.forward(l)
        turtle.left(60)
        i=i+1
    turtle.done()
Beispiel #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()
Beispiel #16
0
def demo():
    turtle.forward(100)
    turtle.left(120)
    turtle.forward(80)
    turtle.right(90)
    turtle.forward(80)
    turtle.exitonclick()
Beispiel #17
0
def draw_triangle(l):
    i=0
    while(i<3):
        turtle.forward(l)
        turtle.left(120)
        i=i+1
    turtle.done()
Beispiel #18
0
def make_smiley(size, mood):
    turtle.penup()
    turtle.right(90)
    turtle.forward(size)
    turtle.left(90)
    turtle.pendown()
    turtle.circle(size)
    turtle.penup()
    turtle.forward(-size/3)
    turtle.left(90)
    turtle.forward(size)
    turtle.pendown()
    turtle.forward(size/2)
    turtle.penup()
    turtle.right(90)
    turtle.forward(size/1.5)
    turtle.right(90)
    turtle.pendown()
    turtle.forward(size/2)
    turtle.penup()
    turtle.forward(size/2)
    turtle.right(90)
    turtle.pendown()
    if mood=="happy":
        turtle.right(90)
        turtle.circle(size/3, -180)
    elif mood=="meh":
        turtle.forward(size/1.5)
    elif mood=="sad":
        turtle.right(90)
        turtle.circle(size/3, 180)
    else:
        print("what mood are we in today?")
Beispiel #19
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) 
Beispiel #20
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)
Beispiel #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)
Beispiel #22
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')
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)
Beispiel #24
0
def drawHouse(wallSize):

    """
    This is the function for drawing house which takes
    wall size as a input.
    :pre: (relative) pos (0,0), heading (east), right
    :post: (relative) pos (wallSize,0), heading (north), up
    :return: total wood required to built the house.
    """
    turtle.down()
    turtle.forward(wallSize)
    turtle.left(90)
    turtle.forward(wallSize)
    maxX = turtle.xcor()
    turtle.left(45)
    turtle.forward(wallSize / math.sqrt(2))
    maxY = turtle.ycor()
    turtle.left(90)
    turtle.forward(wallSize / math.sqrt(2))
    turtle.left(45)
    turtle.forward(wallSize)
    turtle.left(90)
    turtle.forward(wallSize)
    turtle.up()
    return 2 * (wallSize + wallSize / math.sqrt(2))
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 drawY(length):
    """
    Draw English character 'Y'
    :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.right(45)
    turtle.forward(math.sqrt((2 * math.pow((length / 2), 2))))
    # moving at 45 degree angle for length sqrt(((math.pow((length/2)+(math.pow((length/2)),2)))
    # calculated using pythagorean theorem.
    turtle.right(45)
    turtle.forward(length / 2)
    turtle.right(180)
    turtle.forward(length / 2)
    turtle.right(45)
    turtle.forward(math.sqrt((2 * math.pow((length / 2), 2))))
    turtle.right(45)
    turtle.up()
    turtle.right(90)
    turtle.forward(length)
    turtle.left(90)
    turtle.up()
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()
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)
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
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)
Beispiel #31
0
def Draw_all(num_set, num_ind):
    '''combine with the draw functions above but consider that each raw should only have 2 sets'''
    t.setup(width=0.5, height=1.0)
    t.penup()
    t.goto(-200, 300)
    t.speed(300)
    t.left(90)
    row = num_set // 2
    row_remain = num_set % 2
    t.pensize(2)
    t.pencolor('blue')
    for i in range(row):
        Draw_set()
        t.left(180 - 36.843)
        t.penup()
        t.forward(40)
        t.left(90)
        t.forward(60)
        t.left(90)
        Draw_set()
        t.left(180 - 36.843)
        t.penup()
        t.forward(100)
        t.right(90)
        t.forward(48)
        t.right(90)
    if row_remain != 0:
        Draw_set()
        t.left(180 - 36.843)
        t.penup()
        t.forward(40)
        t.left(90)
        t.forward(60)
        t.left(90)
    Draw_ind(num_ind)
    t.done()
    '''
Beispiel #32
0
import turtle

count = '0'
while count != '4':
    count = input('2+2 is ')

#Challenge Sketch Program

print('Sketch Program')
colour = ''
lnLen = 1
angle = 0

while lnLen != 0:
    lnLen = int(input('What is the line length you prefer \n'))
    angle = int(input('What is the angle you prefer \n'))
    colour = input('What is the pen colour you prefer \n')
    turtle.color(colour)
    turtle.forward(lnLen)
    turtle.left(angle)
import turtle

turtle.shape('turtle')
i = 0
n = 10
while i < n:
    turtle.forward(100)
    turtle.stamp()
    turtle.backward(100)
    turtle.left(360 / n)
    i += 1
import turtle
turtle.width(10)  # 笔的宽度
turtle.showturtle()  # 显示箭头
turtle.write("锡权")
turtle.forward(300)  # 前进300像素
turtle.color('red')  # 画笔颜色改为red
turtle.left(90)  # 夹头左转90度
turtle.forward(300)
turtle.goto(0, 50)  # 去坐标(0,50)
turtle.goto(0, 0)
turtle.penup()  # 抬笔,这样路径没有画线
turtle.goto(0, 300)
turtle.goto(0, 0)
turtle.pendown()  # 下笔,路径有画线
turtle.goto(50, 50)

turtle.circle(100)  # 画圆
Beispiel #35
0
#----------------------------------------------
#       Problem 060
#       Author: Omar Rahman
#       Date: 1/1/2019
#----------------------------------------------

#--------------
# Triangle
#--------------
import turtle

turtle.shape("turtle")

Screen = turtle.Screen()
Screen.bgcolor("yellow")

turtle.pensize(3)

turtle.color("green", "red")
turtle.begin_fill()

#----------------------
for i in range(0, 3):
    turtle.forward(100)
    turtle.left(120)
#----------------------

turtle.end_fill()
turtle.exitonclick()
Beispiel #36
0
def move_pen_position(x, y):
    turtle.hideturtle()  # 隐藏画笔(先)
    turtle.up()  # 提笔
    turtle.goto(x, y)  # 移动画笔到指定起始坐标(窗口中心为0,0)
    turtle.down()  # 下笔
    turtle.showturtle()  # 显示画笔


# 初始化
turtle.setup(width=800, height=500)  # 窗口(画布)大小
turtle.color('red', 'pink')  # 画笔颜色
turtle.pensize(3)  # 画笔粗细
turtle.speed(1)  # 描绘速度
# 初始化画笔起始坐标
move_pen_position(x=0, y=-180)  # 移动画笔位置
turtle.left(140)  # 向左旋转140度

turtle.begin_fill()  # 标记背景填充位置

# 画心形直线( 左下方 )
turtle.forward(224)  # 向前移动画笔,长度为224
# 画爱心圆弧
hart_arc()  # 左侧圆弧
turtle.left(120)  # 调整画笔角度
hart_arc()  # 右侧圆弧
# 画心形直线( 右下方 )
turtle.forward(224)
turtle.end_fill()  # 标记背景填充结束位置

# 点击窗口关闭程序
window = turtle.Screen()
Beispiel #37
0
    count += 1

    data1 = count
    data5 = count

    r = random.random()
    g = random.random()
    b = random.random()
    data2 = r
    data3 = g
    data4 = b
    turtle.pencolor((r, g, b))

    angle = random.randrange(0, 360)
    dist = random.randrange(1, 100)
    turtle.left(angle)  ##이동
    turtle.forward(dist)
    curX = int(turtle.xcor())  ##현재 거북이 위치 구함
    curY = int(turtle.ycor())

    data6 = curX
    data7 = curY

    sql = "INSERT INTO ttable VALUES('data1','data2' , 'data3' , 'data4', 'data5' , 'data6', 'data7')"
    cur.execute(sql)
    print("%5s %5s %5s %5s %5s %5s %5s" %
          (data1, data2, data3, data4, data5, data6, data7))
    strdata1.append("선분 ID")
    strdata2.append("색상 R")
    strdata3.append(data3)
    strdata4.append(data4)
Beispiel #38
0
import turtle

# Нарисуйте паука с n лапами. Пример n = 12:

turtle.shape('turtle')
turtle.speed(0)

legs = 12
legLen = 100
angle = 360 / legs

for leg in range(1, legs + 1):
    turtle.forward(legLen)
    turtle.stamp()
    turtle.left(180)
    turtle.forward(legLen)
    turtle.left(180 + angle)

turtle.done()
turtle.forward(clusterlength + offset)
a, b = turtle.xcor(), turtle.ycor()
print(a, b)
turtle.right(90)
turtle.pendown()
a = 0
for n in orfs:
    turtle.pen(fillcolor=n[3], pencolor="black", pensize=4)
    turtle.begin_fill()
    if n[1] < n[2]:
        turtle.setheading(90)
        turtle.forward(50)
        turtle.right(90)
        turtle.forward(
            (float(n[2]) - float(n[1]) - math.tan(math.radians(30)) * 100))
        turtle.left(90)
        turtle.forward(50)
        turtle.right(150)
        turtle.forward(115.47)
        x, y = turtle.xcor(), turtle.ycor()
        turtle.right(60)
        turtle.forward(115.47)
        turtle.right(150)
        turtle.forward(50)
        turtle.left(90)
        turtle.forward(
            (float(n[2]) - float(n[1]) - math.tan(math.radians(30)) * 100))
        turtle.right(90)
        turtle.forward(50)
        k, l = turtle.xcor(), turtle.ycor()
        turtle.end_fill()
Beispiel #40
0
def draw_M():
    turtle.delay(0)
    turtle.bgcolor("gold")
    turtle.hideturtle()
    turtle.color("maroon")
    turtle.penup()
    turtle.setpos(-200, -100)
    turtle.pendown()
    turtle.begin_fill()
    turtle.forward(120)
    turtle.left(90)
    turtle.forward(64)
    turtle.left(90)
    turtle.forward(20)
    turtle.right(120)
    turtle.forward(80)
    turtle.right(120)
    turtle.forward(28)
    turtle.right(120)
    turtle.forward(14)
    turtle.left(90)
    turtle.forward(64)
    turtle.left(90)
    turtle.forward(128)
    turtle.left(90)
    turtle.forward(64)
    turtle.left(90)
    turtle.forward(14)
    turtle.right(120)
    turtle.forward(28)
    turtle.right(120)
    turtle.forward(80)
    turtle.right(120)
    turtle.forward(20)
    turtle.left(90)
    turtle.forward(64)
    turtle.left(90)
    turtle.forward(120)
    turtle.left(90)
    turtle.forward(64)
    turtle.left(90)
    turtle.forward(28)
    turtle.right(60)
    turtle.forward(140)
    turtle.right(120)
    turtle.forward(20)
    turtle.left(90)
    turtle.forward(64)
    turtle.left(90)
    turtle.forward(120)
    turtle.left(90)
    turtle.forward(64)
    turtle.left(90)
    turtle.forward(20)
    turtle.right(120)
    turtle.forward(52)
    turtle.right(120)
    turtle.forward(52)
    turtle.right(120)
    turtle.forward(20)
    turtle.left(90)
    turtle.forward(64)
    turtle.left(90)
    turtle.forward(120)
    turtle.left(90)
    turtle.forward(64)
    turtle.left(90)
    turtle.forward(20)
    turtle.right(120)
    turtle.forward(140)
    turtle.right(60)
    turtle.forward(28)
    turtle.left(90)
    turtle.forward(64)
    turtle.end_fill()
import turtle

# Draw chess board borders
turtle.pensize(3)  # Set pen thickness to 3 pixels
turtle.penup()  # Pull the pen up
turtle.goto(-120, -120)
turtle.pendown()  # Pull the pen down
turtle.color("red")

for i in range(4):
    turtle.forward(240)  # Draw a line
    turtle.left(90)  # Turn left 90 degrees

# Draw chess board inside
turtle.color("black")
for j in range(-120, 90, 60):
    for i in range(-120, 120, 60):
        turtle.penup()
        turtle.goto(i, j)
        turtle.pendown()

        # Draw a small rectangle
        turtle.begin_fill()
        for k in range(4):
            turtle.forward(30)  # Draw a line
            turtle.left(90)  # Turn left 90 degrees
        turtle.end_fill()

for j in range(-90, 120, 60):
    for i in range(-90, 120, 60):
        turtle.penup()
import turtle


def DrawSquare():
    turtle.speed(10)
    turtle.forward(80)
    turtle.right(90)
    turtle.forward(80)
    turtle.right(90)
    turtle.forward(80)
    turtle.right(90)
    turtle.forward(80)
    turtle.right(90)


turtle.left(90)
DrawSquare()

for i in range(50):
    turtle.right(7)
    DrawSquare()

turtle.done()
Beispiel #43
0
import turtle as t

t.penup()
t.goto(0, 0)
t.pendown()
t.forward(100)

t.right(120)
t.forward(200)

t.left(120)
t.forward(100)

t.left(120)
t.forward(200)

t.right(180)
t.forward(100)

input()
#Creating an abstract design using the Turtle feature

from turtle import forward, left, circle, done

circle(50)
forward(100)
circle(50)
left(90)
forward(100)
circle(50)
left(90)
forward(100)
left(90)
forward(100)
circle(50)
done()
Beispiel #45
0
# CTI-110
# Kayla Ward
# 26 Sept 2018
# P4T1b
#

import turtle
turtle.shape("turtle")
turtle.color("blue")
turtle.pensize(width=3)
turtle.left(90)
turtle.forward(100)
turtle.backward(50)
turtle.right(45)
turtle.forward(70)
turtle.backward(70)
turtle.right(90)
turtle.forward(70)
turtle.penup()
turtle.left(45)
turtle.forward(150)
turtle.pendown()
turtle.right(65)
turtle.forward(100)
turtle.left(130)
turtle.forward(70)
turtle.right(130)
turtle.forward(70)
turtle.left(130)
turtle.forward(100)
turtle.hideturtle()
def draw_square(side_length):
    for i in range(4):
        turtle.forward(side_length)
        turtle.left(90)
Beispiel #47
0
import turtle

turtle.shape('turtle')

fig1_angles = 12
for i in range(fig1_angles):
    turtle.forward(50)
    turtle.right(180)
    turtle.forward(50)
    turtle.right(180)
    turtle.left(360 / fig1_angles)

turtle.hideturtle()
Beispiel #48
0
import turtle as t

t.speed(1000)
t.shape('turtle')
def halfcircle(n):
    for i in range(90):
        t.forward(n)
        t.right(2)
t.left(90)
for i in range(10):
    halfcircle(2)
    halfcircle(0.5)


Beispiel #49
0
def card_suit_position():
    """card_suit_position sets up the suits position"""
    turtle.up()
    turtle.forward(110)
    turtle.left(90)
    turtle.forward(25)
    turtle.right(90)
    turtle.down()
    draw_card_suit_diamond()
    turtle.up()
    turtle.right(45)
    turtle.forward(15)
    turtle.left(90)
    turtle.forward(175)
    turtle.left(90)
    turtle.forward(110)
    turtle.left(90)
    turtle.forward(8)
    turtle.left(90)
    draw_card_suit_diamond()
    turtle.up()
    turtle.left(45)
    turtle.forward(8)
    turtle.left(90)
    turtle.forward(15)
    turtle.left(90)
    turtle.forward(105)
    turtle.left(90)
    turtle.forward(62.5)
    turtle.left(90)
    turtle.forward(15)
    turtle.right(90)
    turtle.down()
    draw_card_big_suit_diamond()
    turtle.up()
    turtle.left(45)
    turtle.write( "A", align="center", font=("Arial", 20, "bold"))
    turtle.home()
Beispiel #50
0
def n_angle(n):
    for _ in range(n):
        turtle.forward(80)
        turtle.left(360 / n)
    turtle.done()
Beispiel #51
0
# Drawing a flower
# 1. Draw the stem
# 2. Draw the petals
# 3. Draw the center of the flower
# 4. Profit

# Import turtle module
import turtle as t

# 1. Draw the stem
t.left(90)
t.forward(100)

# 2. Draw the petals
for angles in range(0, 360, 45):
    t.left(angles)
    t.circle(25)

# 3. Draw the center of the flower

t.exitonclick()
Beispiel #52
0
def card_suit_position_two():
    """card_suit_position_two sets up the suit of the second card on right"""
    turtle.forward(30)
    draw_card_border()
    turtle.up()
    turtle.forward(110)
    turtle.left(90)
    turtle.forward(25)
    turtle.right(90)
    turtle.down()
    draw_card_suit_club()
    turtle.up()
    turtle.forward(15)
    turtle.left(90)
    turtle.forward(175)
    turtle.left(90)
    turtle.forward(110)
    turtle.left(90)
    turtle.forward(20)
    turtle.left(90)
    turtle.down()
    draw_card_suit_club() 
    turtle.up()
    turtle.left(90)
    turtle.forward(20)
    turtle.left(90)
    turtle.forward(15)
    turtle.left(90)
    turtle.forward(125)
    turtle.left(90)
    turtle.forward(62.5)
    turtle.left(90)
    turtle.forward(15)
    turtle.right(90)
    turtle.down()
    draw_card_bigger_suit_club()
    turtle.up()
    turtle.left(90)
    turtle.forward(30)
    turtle.down()
    turtle.write( "7", align="center", font=("Arial", 20, "bold"))
import turtle as t

t.color("red", "yellow")
t.speed(5)

t.begin_fill()
for _ in range(5):
    t.forward(200)
    t.left(216)
t.end_fill()

t.done()
import turtle
num_pts =6
for i in range(num_pts):
    turtle.left(360/num_pts)
    turtle.forward(100)
    turtle.circle()
turtle.mainloop()
Beispiel #55
0
import turtle
turtle.shape('turtle')
turtle.speed(10)
k = 1
for i in range(10):
    for j in range(360):
        turtle.left(1)
        turtle.forward(k)
    for j in range(360):
        turtle.right(1)
        turtle.forward(k)
    k += 1
import  turtle
import random
turtle.speed(0)
#for i in range(6):#will give 6 sided rangoli
a='green','red'
turtle.color('blue','blue')
for i in range(64):
    if i%32<>0:
        b=random.choice(a)
        turtle.color(b,b)
    turtle.circle(150)
    turtle.left(45.0/4)

#turtle.forward(150)#these 2 line s in main loop only
#turtle.left(60)

a=raw_input()
turtle.right(-90)
turtle.forward(100)

turtle.penup()
turtle.goto(nowpos)
turtle.pendown()

turtle.right(40)
turtle.forward(50)
turtle.right(-40)
turtle.right(90)
turtle.forward(200)
turtle.right(-90)

nowpos = turtle.pos()
turtle.left(140)
turtle.fd(50)
turtle.penup()
turtle.goto(nowpos)
turtle.pendown()
turtle.left(-140)

turtle.left(180)
turtle.forward(100)
turtle.right(90)
turtle.fd(200)
turtle.right(90)
turtle.forward(100)

turtle.penup()
turtle.right(180)
Beispiel #58
0
def print_circle(n):
    """ n - degree of rotation
    """
    for _ in range(n):
        turtle.forward(5)
        turtle.left(360 / n)
Beispiel #59
0
"""__author:吴佩隆"""
import turtle

turtle.setup(400,600)
turtle.width(2)
turtle.speed(2)

turtle.up()
turtle.goto(0,-260)

turtle.left(150)
turtle.down()
for x in range(30):
    turtle.forward(1)
    turtle.right(2)

turtle.forward(20)

turtle.right(10)

for x in range(100):
    turtle.forward(3)
    turtle.left(0.3)

for x in range(130):
    turtle.forward(3)
    turtle.right(1.5)

turtle.up()
turtle.goto(160,150)
turtle.down()
Beispiel #60
0
@author: boris
"""

import turtle
from turtle import Turtle, Screen
import math

_forw = int(input("radius?: "))
_left = int(input("left?: "))
turtle.color('red', 'yellow')
turtle.begin_fill()

while True:
    turtle.forward(200)
    turtle.up(100)
    turtle.left(170)

    if abs(turtle.pos()) < 1:
        break

turtle.circle(_forw)
turtle.end_fill
turtle.done()

# def _draw_circle_right(radius, x, y):
#     turtle.up()
#     turtle.goto(x,y+radius) # go to (0, radius)
#     turtle.begin_fill() # start fill
#     turtle.down() # pen down
#     turtle.color('blue')
#     times_y_crossed = 0