Пример #1
1
def main():
    turtle.setup(1300, 800, 0, 0)   # 启动图形窗口
    pythonsize = 10
    turtle.pensize(pythonsize)
    turtle.pencolor("blue")
    turtle.seth(-40)        # 启动时运动的方向(角度)
    drawSnake(40, 80, 5, pythonsize/2)
Пример #2
0
    def test_same_function_names_work(self):
        # draw some things using the english commands in tortuga
        tortuga.forward(50)
        tortuga.left(90)
        tortuga.forward(50)
        tortuga.right(45)
        tortuga.backward(50)
        tortuga.left(45)
        tortuga.pensize(5)
        for c in (english_colors):
            tortuga.color(c)
            tortuga.forward(10)

        # now draw the same things using turtle
        turtle.forward(50)
        turtle.left(90)
        turtle.forward(50)
        turtle.right(45)
        turtle.backward(50)
        turtle.left(45)
        turtle.pensize(5)
        for c in (english_colors):
            turtle.color(c)
            turtle.forward(10)

        # and make sure they both resulted in the same output
        self.assert_same()
Пример #3
0
    def test_equivalent_spanish_names_work(self):
        # draw some things using the english commands in tortuga
        tortuga.adelante(50)
        tortuga.izquierda(90)
        tortuga.adelante(50)
        tortuga.derecho(45)
        tortuga.atras(50)
        tortuga.izquierda(45)
        tortuga.tamano_lapiz(5)
        for c in (english_colors):
            tortuga.color(c)
            tortuga.adelante(10)
        for c in (spanish_colors):
            tortuga.color(c)
            tortuga.adelante(10)

        # now draw the same things using turtle
        turtle.forward(50)
        turtle.left(90)
        turtle.forward(50)
        turtle.right(45)
        turtle.backward(50)
        turtle.left(45)
        turtle.pensize(5)
        for c in (english_colors):
            turtle.color(c)
            turtle.forward(10)
        for c in (english_colors):
            turtle.color(c)
            turtle.forward(10)

        # and make sure they both resulted in the same output
        self.assert_same()
Пример #4
0
def main():
	turtle.setup(1300, 800, 0, 0)
	pythonsize = 30
	turtle.pensize(pythonsize)
	turtle.pencolor('blue')
	turtle.seth(-40)
	drawSnake(rad = 40, angle = 80, len = 5, neckrad = pythonsize/2 )
Пример #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)
Пример #6
0
def tree1(iters, xpos, ypos):
	'''Creates lsystem from filename and then creates an arrangement'''
	# creates object from lsystem
	l1 = ls.Lsystem('lsystemextension1.txt')
	
	#number of iterations
	# for growth effect in task 3, made iters a parameter
	num_iter1 = iters
	
	#creates buildstring function
	s1 = l1.buildString(num_iter1)
	
	#specific angle
	angle = 15
	
	#creates an object from TI class
	ti = it.TurtleInterpreter()
	
	# sets the colors of the tracer and calls the drawstring function
	# orients the trees with parameters xpos and ypos
	# My Tree 1 (mylsystem1.txt)
	turtle.pencolor('DarkOliveGreen')
	turtle.pensize(2)
	'''tree with stem color of olivedrab'''
	turtle.up()
	turtle.setposition(xpos,ypos)
	turtle.setheading(90)
	turtle.down()
	ti.drawString(s1,7,angle)
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
Пример #8
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)
Пример #9
0
    def drawLine(self,color,coord1,coord2): 
        """
        dessine une ligne entre deux coordonné sur la grille

        :param color: La couleur de la ligne
        :param coord1: La première coordonné en tuple (i,j,"joueur")
        :param coord2: La deuxième coordonné en tuple (i,j,"joueur")
        """
        if coord1[2] == coord2[2] and coord2[2] == "you":
            turtle.goto(38+coord1[1]*25,87-25*coord1[0])
        elif coord1[2] == coord2[2] and coord2[2] == "enemy":
            turtle.goto(-262+(25*coord1[1]),87-25*coord1[0])
        else:
            print('wrong player')
            return 0
        turtle.pensize(20)
        turtle.pencolor(color)
        if coord1[1] == coord2[1]: #Vertical
            turtle.pendown()
            turtle.setheading(270)
            turtle.fd((coord2[0]-coord1[0])*25)
        elif coord1[0] == coord2[0]: #horizontal
            turtle.pendown()
            turtle.setheading(0)
            turtle.fd((coord2[1]-coord1[1])*25)
        else:
            print('Ligne non Hori ou Vert')
            return 0
        turtle.penup()
        return 1
Пример #10
0
def main():
    turtle.setup(1300, 800, 0, 0)
    pythonsize = 30
    turtle.pensize(pythonsize)
    turtle.pencolor("blue")
    turtle.seth(-40)
    drawSnake(40, 80, 5, pythonsize / 2)
Пример #11
0
def theStem(stemLength=100):
	turtle.home()
	turtle.forward(25)
	turtle.left(90)
	turtle.pensize(4)
	turtle.color("green")
	turtle.forward(stemLength)
def rectangle(length = 50, width = 30, x = 0, y = 0, color = 'black', fill = False):
    turtle.pensize(3)
    turtle.speed('fastest')
    turtle.hideturtle()
    if fill == True:
        turtle.color(color)
        for i in range(width): 
            turtle.setposition(x, (y+i))
            turtle.pendown()
            turtle.setposition((x+length), (y+i))
            turtle.penup()
    else:
        turtle.penup()
        turtle.goto(x,y)
        turtle.color(color)
        turtle.pendown()
        turtle.forward(length)
        turtle.left(90)
        turtle.forward(width)
        turtle.left(90)
        turtle.forward(length)
        turtle.left(90)
        turtle.forward(width)
        turtle.left(90)
        turtle.penup()

    return
Пример #13
0
def drawLine(x1, y1, x2, y2, color = "black", size = 1):
    turtle.color(color)
    turtle.pensize(size)
    turtle.penup()
    turtle.goto(x1, y1)
    turtle.pendown()
    turtle.goto(x2, y2)
Пример #14
0
def main():  
    turtle.setup(1300,800,0,0)  
    pythonsize=1  
    turtle.pensize(pythonsize)  
    turtle.pencolor("black")  
    turtle.seth(-40)  
    drawSnack(40,80,5,pythonsize/2)  
Пример #15
0
def Eating(cells):
	for cell in cells:	
		for cell2 in cells:
			if cell!=cell2:
				min_d = cell.get_radius()+cell2.get_radius()
				d = ((cell.xcor()-cell2.xcor())**2+(cell.ycor()-cell2.ycor())**2)**0.5
				if d<min_d:
					if cell.get_radius()>cell2.get_radius():
						if cell2==user_cell:
							turtle.pensize(50)
							turtle.write("Game Over!")
							meet.mainloop()
						x=meet.get_random_x()
						y=meet.get_random_y()
						cell2.goto(x,y)
						r = cell.get_radius() + 0.2 * cell2.get_radius() 
						cell.set_radius(r)
					if cell2.get_radius()>cell.get_radius():
						if cell==user_cell:
							turtle.pensize(50)
							turtle.write("Game Over!")
							meet.mainloop()
						x=meet.get_random_x()
						y=meet.get_random_y()
						cell.goto(x,y)
						r = cell2.get_radius() + 0.2 * cell.get_radius()
						cell2.set_radius(r)
Пример #16
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) 
Пример #17
0
def circunferencia(simbolos,identificador,linea):
  p1= obtener_punto(2,identificador,simbolos)
  radio = obtener_radio(identificador,simbolos)
  x1 = obtener_x(p1,simbolos)
  y1 = obtener_y(p1,simbolos)
 
  escalar = obtener_escalar(identificador, simbolos,linea)
  relleno = obtener_color(obtener_relleno(identificador,simbolos,linea))
  borde = obtener_color(obtener_borde(identificador,simbolos,linea))  
  turtle.color(borde)
  if escalar == 0:
    escalar=1
  tx = obtener_tx(identificador, simbolos,linea)
  ty = obtener_ty(identificador, simbolos,linea)
  turtle.pensize(8)
  turtle.penup()

  
  #Trasladar circunferencia
  x1 = x1 + tx
  y1 = y1 + ty

  #turtle.setposition(x1, y1-(radio*44))
  #turtle.pendown()
  #turtle.circle(radio*44)

  #Escalar circunferencia
  turtle.penup()
  #turtle.setposition(x1, y1-(radio*44*escalar))
  turtle.setposition(x1*44, (y1*44)-(radio*44*escalar))
  turtle.pendown()
  turtle.fillcolor(relleno)
  turtle.begin_fill()
  turtle.circle(radio*44*escalar)
  turtle.end_fill()
Пример #18
0
def meet(x,y):
    turtle.pensize(15)
    m(x,y)
    e1(x,y)
    e2(x,y)
    f(x,y)
    TM(x,y)   
Пример #19
0
def init_turtle():
    """
    Стартовые настройки для рисования
    """
    turtle.colormode(255)
    turtle.speed(10)
    turtle.pensize(3)
def main():
    turtle.setup(800, 350, 200, 200)
    turtle.penup()
    turtle.fd(-300)
    turtle.pensize(5)
    drawDate(datetime.datetime.now().strftime('%Y%m%d'))
    turtle.hideturtle()
def n_sided_polygon(turtle, n, color="#FFFFFF", line_thickness=1, line_length=80):
	'''
	Draw an n-sided polygon
	input: turtle, number of sides, line color, line thickness, line length
	'''
	# for n times:
	# Draw a line, then turn 360/n degrees and draw another

	# set initial parameters
  	turtle.degrees()
  	turtle.pensize(line_thickness)
  	turn_angle = (360/n)

	# Draw each line segment and turn

  	for i in range(0,n):
	  turtle.color(color)
    	  turtle.pendown()
    	  turtle.forward(line_length)
   	  turtle.penup()
    	  turtle.left(turn_angle)

	# return the turtle to its original starting location
	turtle.left(turn_angle)

	return 0
def line(a1,b1,a2,b2,c):
    turtle.pu()
    turtle.goto(a1,b1)
    turtle.color(c)
    turtle.pd()
    turtle.pensize(10)
    turtle.goto(a2,b2)
Пример #23
0
def skidMark(lineLength):
    turtle.pensize(2)
    turtle.pencolor(0, 0, 0)
    for x in range(lineLength):
        turtle.pencolor(x,x,x)
        turtle.fd(x)
        turtle.right(90)
Пример #24
0
 def drawIt(backAgain):
     turtle.penup()
     turtle.setpos(0,vertHeight)
     turtle.pendown()
     upDown = True
     start = turtle.xcor()
     for i in range(iterLength):
         randomyUpDownVariance = randint(1,55)
         randomyBetweenLineVariance = randint(1,25)
         randPenSize = randint(2,10)
         randPenColor1 = randint(1,187)
         randPenColor2 = randint(1,193)
         randPenColor3 = randint(1,182)
         turtle.pensize(randPenSize)
         print turtle.xcor()
         tup = (randPenColor1, randPenColor2, randPenColor3)
         turtle.pencolor(tup)
         if upDown == True:
             upDown = False
             turtle.goto(start, (vertHeight + randomyUpDownVariance))
         elif upDown == False:
             upDown = True
             turtle.goto(start, -(vertHeight + randomyUpDownVariance))
         if backAgain == True:
             start -= randomyBetweenLineVariance
         elif backAgain == False:
             start += randomyBetweenLineVariance
     if (backAgain == True):
         drawIt(False)
Пример #25
0
def drawSetup(title,xlimits,xscale,ylimits,yscale,axisThickness=None):
	turtle.title(title)
	xmin, xmax = xlimits
	ymin, ymax = ylimits
	#turtle.setup(xmax-xmin,ymax-ymin,0,0) #window-size
	globals()['xmin'] = xmin
	globals()['xmax'] = xmax
	globals()['ymin'] = ymin
	globals()['ymax'] = ymax
	globals()['xscale'] = xscale
	globals()['yscale'] = yscale

	turtle.setworldcoordinates(xmin,ymin,xmax,ymax)
	#turtle.speed(0) #turtle.speed() does nothing w/ turtle.tracer(0,0)
	turtle.tracer(0,0)

	drawGrid()
	#drawGridBorder()
	
	turtle.pensize(axisThickness)

	drawXaxis()
	drawXtickers()
	numberXtickers()
	
	drawYaxis()
	drawYtickers()
	numberYtickers()

	turtle.pensize(1)
Пример #26
0
def drawFlower(xCenter = 0, yCenter = 0, xRightUp = 0, yRightUp = 0,
    xRightDown = 0, yRightDown = 0, xLeftUp = 0, yLeftUp = 0,
    xLeftDown = 0, yLeftDown = 0, radius = 10):
    turtle.pensize(3)
    turtle.color(1.0, 0.41, 0.70) # Hot Pink
    turtle.penup()
    turtle.goto(xCenter, yCenter - radius)
    turtle.pendown()
    turtle.circle(radius)
    turtle.penup()
    turtle.goto(xRightUp, yRightUp - radius)
    turtle.pendown()
    turtle.circle(radius)
    turtle.penup()
    turtle.goto(xRightDown, yRightDown - radius)
    turtle.pendown()
    turtle.circle(radius)
    turtle.penup()
    turtle.goto(xLeftUp, yLeftUp - radius)
    turtle.pendown()
    turtle.circle(radius)
    turtle.penup()
    turtle.goto(xLeftDown, yLeftDown - radius)
    turtle.pendown()
    turtle.circle(radius)
Пример #27
0
def drawLine(x1, y1, x2, y2):
    turtle.pensize(5)
    turtle.color(0.27, 0.51, 0.71) # Steel Blue
    turtle.penup()
    turtle.goto(x1, y1)
    turtle.pendown()
    turtle.goto(x2, y2)
Пример #28
0
def drawCircle(x = 0, y = 0, radius = 10, mycolor = (0.49, 0.99, 0.00)): # Lawn Green
    turtle.pencolor(mycolor[0], mycolor[1], mycolor[2])
    turtle.pensize(4)
    turtle.penup()
    turtle.goto(x, y - radius)
    turtle.pendown()
    turtle.circle(radius)
Пример #29
0
def SetupClock(radius):  
    # 建立表的外框  
    turtle.reset()  
    turtle.pensize(7)  
    for i in range(60):  
        Skip(radius)  
        if i % 5 == 0:  
            turtle.forward(20)  
            Skip(-radius - 20)  
             
            Skip(radius + 20)  
            if i == 0:  
                turtle.write(int(12), align="center", font=("Courier", 14, "bold"))  
            elif i == 30:  
                Skip(25)  
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))  
                Skip(-25)  
            elif (i == 25 or i == 35):  
                Skip(20)  
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))  
                Skip(-20)  
            else:  
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))  
            Skip(-radius - 20)  
        else:  
            turtle.dot(5)  
            Skip(-radius)  
        turtle.right(6)  
Пример #30
0
def writeText(s, x, y):
    turtle.pensize(1)
    turtle.color(0.28, 0.24, 0.55) # Dark Slate Blue
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()
    turtle.write(s, align="center", font=("Times", 15, "italic"))
Пример #31
0
def slash(R, r):
    interval = 10
    t.seth(90)
    big = pow((R**2) * 2, 0.5)
    small = big - 2 * interval
    for i in range(13):
        #bigger line
        t.penup()
        t.goto(0, 0)
        t.fd(R)
        t.pendown()
        t.right(135)
        t.fd(big)
        #smaller line
        t.left(135)
        t.penup()
        t.goto(0, 0)
        t.fd(pow((small**2) / 2, 0.5))
        t.pendown()
        t.right(135)
        t.fd(small)
        #bold line
        t.pensize(8)
        t.pencolor("black")
        t.left(135)
        t.penup()
        t.goto(0, 0)
        t.fd((R + pow((small**2) / 2, 0.5)) / 2)
        t.pendown()
        t.right(135)
        t.fd((big + small) / 2)
        t.pensize(2)
        t.pencolor("yellow")
        t.seth(90 + i * 30)
    else:
        #bigger line
        t.penup()
        t.goto(0, 0)
        t.fd(R)
        t.right(135)
        t.fd(big / 2)
        t.pendown()
        t.fd(big / 2)
        #smaller line
        t.left(135)
        t.penup()
        t.goto(0, 0)
        t.fd(pow((small**2) / 2, 0.5))
        t.right(135)
        t.fd(small / 2)
        t.pendown()
        t.fd(small / 2)
        #bold line
        t.pensize(8)
        t.pencolor("black")
        t.left(135)
        t.penup()
        t.goto(0, 0)
        t.fd((R + pow((small**2) / 2, 0.5)) / 2)
        t.right(135)
        t.fd((big + small) / 2 / 2)
        t.pendown()
        t.fd((big + small) / 2 / 2)
        t.pensize(2)
        t.pencolor("yellow")
        t.seth(90 + i * 30)
Пример #32
0
# -*- coding: utf-8 -*-
# @Time    : 2019/7/29 9:12
# @Author  : Eric Lee
# @Email   : [email protected]
# @File    : demo3.py
# @Software: PyCharm

# Python标准库中的GUI界面  -- 》  turtle
# turtle的简单使用
# 导入turtle  as 是给起一个别名
import turtle as t
# 设置画笔的大小  10px
t.pensize(10)
t.color('blue')
# 绘制 NEUSOFT
# 水平左移
# 抬笔
t.penup()
t.goto(-260, 0)
t.pd()

# 绘制 N
t.left(90)
t.forward(80)
t.right(145)
# 简写
t.fd(100)
t.lt(145)
t.fd(80)

# 绘制 S
Пример #33
0
import turtle

collist1 = [
    'red', 'crimson', 'orangered', 'darkorange', 'orange', 'gold', 'yellow',
    'greenyellow', 'lawngreen', 'limegreen', 'springgreen',
    'mediumspringgreen', 'aquamarine', 'turquoise', 'aqua', 'deepskyblue',
    'dodgerblue', 'mediumslateblue', 'mediumpurple', 'blueviolet',
    'darkviolet', 'purple', 'mediumvioletred'
]
colsel = collist1
angle = 85
interval = 2
turtle.bgcolor('black')
turtle.pensize(1)
turtle.tracer(10, 1)
colornum = 23


def loop():
    pensize = 1
    for i in range(1000):
        for j in range(colornum):
            ind = j % len(colsel)
            turtle.color(colsel[ind])
            turtle.forward((interval / colornum) * i)
        turtle.pensize(pensize)
        pensize = pensize * 1.1
        turtle.right(angle)


loop()
Пример #34
0
    for i in range(4, 8):
        t.write(constellations[i], font=("", 20, ""))
        t.penup()
        t.right(90)
        t.circle(-300, 30)
        t.left(90)
        t.pendown()


if __name__ == "__main__":
    #initialize
    t.setup(800, 800, 0, 0)
    t.speed(0)
    t.bgcolor("black")
    t.pencolor("yellow")
    t.pensize(2)

    #draw biggest circle
    circle(0, 0, 350)
    circle(0, 0, 325)
    circle(0, 0, 321)
    circle(0, 0, 306)
    line(321, 306, 72, 0)

    #draw small circle
    circle(0, 0, 204)
    circle(0, 0, 200)
    circle(0, 0, 186)
    line(200, 186, 72, 0)

    #square frame and line
import turtle as t

print('거북이를 키보드로 움직여 보아요')
print('\tA : 왼쪽으로 이동')
print('\tD : 오른쪽으로 이동')
print('\tW : 위쪽으로 이동')
print('\tS : 아래쪽으로 이동')
print('\tX : 프로그램 종료')

input('엔터키를 누르면 시작합니다!')
t.shape('turtle')
t.pensize(5)
t.color('purple')
t.speed(1500)

while True:
    direction = input('[A,S,D,F] : ')
    if 'X' == direction.upper():
        break
    elif 'D' == direction.upper():
        t.setheading(0)
    elif 'W' == direction.upper():
        t.setheading(90)
    elif 'A' == direction.upper():
        t.setheading(180)
    elif 'S' == direction.upper():
        t.setheading(270)
    else:
        continue

    t.forward(50)
Пример #36
0
import turtle
turtle.hideturtle()
turtle.pensize(width=10)
SIZE_X = 900
SIZE_Y = 900
turtle.setup(SIZE_X, SIZE_Y)
######################Border
turtle.penup()
turtle.goto(-300, 300)
turtle.pendown()
turtle.goto(-300, 300)
turtle.goto(-300, -300)
turtle.goto(300, -300)
turtle.goto(300, -270)
turtle.penup()
turtle.goto(300, -270)
turtle.goto(300, -220)
turtle.pendown()
turtle.goto(300, 300)
turtle.goto(-230, 300)
turtle.penup()
turtle.goto(-280, 300)
turtle.pendown()
turtle.goto(-300, 300)
######################Maze
turtle.penup()
turtle.goto(-230, 300)
turtle.pendown()
turtle.goto(-230, 250)
turtle.goto(-250, 250)
turtle.penup()
Пример #37
0
def main():
    turtle.screensize(800, 6000, "#F0F0F0")
    turtle.pensize(3)
    turtle.speed(9)
    drawAll()
Пример #38
0
import turtle

turtle.speed(0)
turtle.pensize(4)


def square(x, y, side, col, fill):  # this function draws a square
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()
    turtle.color(col)
    if fill:
        turtle.begin_fill()
    for i in range(4):
        turtle.forward(side)
        turtle.left(90)
    if fill:
        turtle.end_fill()


def triangle(x, y, side, col, fill):  # this function draws a square
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()
    turtle.color(col)
    if fill:
        turtle.begin_fill()
    for i in range(3):
        turtle.forward(side)
        turtle.left(120)
    if fill:
Пример #39
0
# coding=utf-8
import turtle
import time

turtle.speed(0)
turtle.pensize(5)
turtle.pencolor("yellow")  #green
turtle.fillcolor("red")

turtle.begin_fill()
for _ in range(5):
    turtle.forward(200)
    turtle.right(144)
turtle.end_fill()
time.sleep(2)

turtle.penup()
turtle.goto(-150, -120)
turtle.color("violet")
turtle.write("Done", font=('Arial', 40, 'normal'))

turtle.mainloop()
Пример #40
0
def heart4():
    import turtle
    import time

    # 画心形圆弧
    def hart_arc():
        for i in range(200):
            turtle.right(1)
            turtle.forward(2)

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

    love = input("请输入表白话语,默认为‘I Love You’:")
    signature = input("请签署你的大名,不填写默认不显示:")

    if love == '':
        love = 'I Love You'

    # 初始化
    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()  # 标记背景填充结束位置

    # 在心形中写上表白话语
    move_pen_position(0, 0)  # 表白语位置
    turtle.hideturtle()  # 隐藏画笔
    turtle.color('#CD5C5C', 'pink')  # 字体颜色
    # font:设定字体、尺寸(电脑下存在的字体都可设置)  align:中心对齐
    turtle.write(love, font=('Arial', 30, 'bold'), align="center")

    # 签写署名
    if signature != '':
        turtle.color('red', 'pink')
        time.sleep(2)
        move_pen_position(180, -180)
        turtle.hideturtle()  # 隐藏画笔
        turtle.write(signature, font=('Arial', 20), align="center")

    # 点击窗口关闭程序
    window = turtle.Screen()
    window.exitonclick()
Пример #41
0
#pythonDraw
import turtle
turtle.setup(650, 350, 200, 200)
turtle.penup()
turtle.fd(-250)
turtle.pendown()
turtle.pensize(23)
turtle.pencolor('purple')
turtle.seth(-40)
for i in range(4):
    turtle.circle(40, 80)
    turtle.circle(-40, 80)
turtle.circle(40, 40)
turtle.fd(40)
turtle.circle(16, 180)
turtle.fd(40 * 2 / 3)
turtle.done()
Пример #42
0
# DrawPython -- 课本46页蟒蛇程序示例

import turtle

turtle.setup(650, 350, 200, 200)
turtle.penup()
turtle.fd(-250)
turtle.pendown()
turtle.pensize(25)
turtle.pencolor("purple")
turtle.seth(-40)
for i in range(4):
    turtle.circle(40, 80)
    turtle.circle(-40, 80)
turtle.circle(40, 80 / 2)
turtle.fd(40)
turtle.circle(16, 180)
turtle.fd(40 * 2 / 3)
Пример #43
0
def Drawbianxing():
    j = int(input("number:"))
    i = 360.0 / j
    p = i
    for x in range(j):
        t.fd(50)
        t.seth(p)
        p = p + i


def DrawFiveStar():
    q = 36
    for x in range(5):
        t.seth(q)
        t.fd(200)
        q = q + 144


t.setup(2000, 2000, 200, 200)
t.penup()
t.fd(-200)

t.pendown()
t.pensize(25)
t.color("blue")

DrawFiveStar()

t.done()
Пример #44
0
# !/usr/bin/env python2
# coding=utf-8

import turtle as t

t.pensize(4)
t.hideturtle()
t.colormode(255)
t.color((255, 155, 192), "pink")
t.setup(840, 500)
t.speed(10)

# 鼻子
t.pu()
t.goto(-100, 100)
t.pd()
t.seth(-30)
t.begin_fill()
a = 0.4
for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a + 0.08
        t.lt(3)  # 向左转3度
        t.fd(a)  # 向前走a的步长
    else:
        a = a - 0.08
        t.lt(3)
        t.fd(a)
t.end_fill()

t.pu()
Пример #45
0
# * -- utf-8 -- *
# Author: Tang

import turtle as t

t.speed(10)
t.pensize(8)
t.hideturtle()
t.screensize(500, 500, bg='white')

# 猫脸
t.fillcolor('#00A1E8')
t.begin_fill()
t.circle(120)
t.end_fill()

t.pensize(3)
t.fillcolor('white')
t.begin_fill()
t.circle(100)
t.end_fill()

t.pu()
t.home()
t.goto(0, 134)
t.pd()
t.pensize(4)
t.fillcolor("#EA0014")
t.begin_fill()
t.circle(18)
t.end_fill()
Пример #46
0
    def __init__(self):

        objectList = [
            'object1small.gif', 'object2small.gif', 'object3small.gif'
        ]
        self.wn = turtle.Screen()
        turtle.tracer(0, 0)
        turtle.pensize(10)
        self.wn.setup(1800, 800)

        self.coords = [
            {
                '2': (-200, 300),
                '1': (-800, -300),
                'S': (200, 300),
                '3': (800, -300),
                '4': (0, -100),
                '5': (-200, 100),
                '6': (200, 100),
                '7': (-200, -300),
                '8': (200, -300)
            },
        ]
        # {'1':(-350,-350), '2':(-350,350),'3':(350,350),'S':(350,-350)},
        # {'2':(-350,-350), '3':(-350,350),'S':(350,350),'1':(350,-350)},
        # {'3':(-350,-350), 'S':(-350,350),'1':(350,350),'2':(350,-350)}
        # ]

        # self.coords = [
        # {'S':(-416,-416), '1':(-416,416),'2':(416,416),'3':(416,-416),'4':(0,0)},
        # {'S':(-416,416), '1':(416,416),'2':(416,-416),'3':(-416,-416),'4':(0,0)},
        # {'S':(416,416), '1':(416,-416),'2':(-416,-416),'3':(-416,416),'4':(0,0)},
        # {'S':(416,-416), '1':(-416,-416),'2':(-416,416),'3':(416,416),'4':(0,0)},
        # ]

        # self.coords = [
        # {'S':(0,-416), '1':(-416,416),'2':(0,416),'3':(416,416),'4':(0,0)}
        # # {'S':(-416,416), '1':(416,416),'2':(416,-416),'3':(-416,-416),'4':(0,0)},
        # # {'S':(416,416), '1':(416,-416),'2':(-416,-416),'3':(-416,416),'4':(0,0)},
        # # {'S':(416,-416), '1':(-416,-416),'2':(-416,416),'3':(416,416),'4':(0,0)},
        # ]
        self.allObjectLists = list(itertools.permutations(objectList, 3))
        self.allPaths = list()
        for i in range(1, 4):
            self.allPaths += list(itertools.permutations('12', i))
        self.allPaths = [list(i) for i in self.allPaths]
        # t = self.allPaths
        self.allPaths = [
            # A, B, C, AB, AC, BA, BC, CA, CB
            list('671'),
            list('6452'),
            list('3'),
            list('6712'),
            list('6713'),
            list('64521'),
            list('6452583'),
            list('31'),
            list('3852')
        ]

        # temp = [t[0],t[1],t[3],t[4],t[5],t[7],t[8],t[15],t[16],t[18],t[22],t[24],t[38],t[39],t[62],t[63]]
        # self.allPaths = temp

        # for i in range(len(self.allPaths)):
        # 	if '3' in self.allPaths[i]:
        # 		ind = self.allPaths[i].index('3')
        # 		self.allPaths[i].insert(ind,'4')

        for k in range(len(self.coords)):

            for i in range(1):
                last = False
                for j in range(len(self.allPaths)):
                    self.setup(self.wn, self.allObjectLists[i], self.coords[k],
                               k)
                    self.wn.turtles()[0].ht()
                    self.drawStimulus(self.wn, self.allPaths[j],
                                      self.coords[k])
                    self.agent.ht()
                    self.agentArrow.ht()
                    # self.agentTracer.ht()
                    turtle.update()
                    ts = turtle.getscreen()
                    ts.getcanvas().postscript(file="batch2_cb/stim" + str(k) +
                                              "_" + "set" + str(i) + "_" +
                                              "path" + str(j) + ".eps")
                    self.wn.clear()
                    turtle.tracer(0, 0)

        turtle.bye()
Пример #47
0
#haonan
import turtle
turtle.screensize(800, 800, "black")
turtle.pensize(2)

for i in range(300):
    if i < 100:
        turtle.pensize(1)
    elif i < 200:
        turtle.pensize(2)
    else:
        turtle.pensize(3)

    if i % 6 == 0:
        turtle.pencolor("red")
    elif i % 6 == 1:
        turtle.pencolor("yellow")
    elif i % 6 == 2:
        turtle.pencolor("blue")
    elif i % 6 == 3:
        turtle.pencolor("green")
    elif i % 6 == 4:
        turtle.pencolor("orange")
    else:
        turtle.pencolor("purple")
    turtle.fd(i / 2)
    turtle.left(61)

turtle.done()
import turtle
import random

##declaration area of global variable
swidht,shight,pSize,exitCout=300,300,3,0
r,g,b,angle,dist,curX,Cury=[0]*7

##a part of main
turtle.title('맘대로 더니는 거북이')
turtle.shape('turtle')
turtle.pensize(pSize)
turtle.setup(width=swidht+30,height=shight+30)
turtle.screensize(swidht,shight)

while True:
    r=random.random()
    g=random.random()
    b=random.random()
    turtle.pencolor((r,g,b))

    angle=random.randrange(0,360)
    dist=random.randrange(1,100)
    turtle.left(angle)
    turtle.forward(dist)
    curX=turtle.xcor()
    Cury=turtle.ycor()

    if(-swidht/2<=curX and curX<=swidht) and (-shight/2<=Cury and Cury<=shight/2):
        pass
    else:
        turtle.penup()
Пример #49
0
def mainLoop():

    # draw hanger
    turtle.penup()
    turtle.pensize(4)
    turtle.setposition(-50, 100)
    turtle.pendown()
    turtle.forward(100)
    turtle.backward(50)
    turtle.left(90)
    turtle.forward(220)
    turtle.right(90)
    turtle.forward(50)
    turtle.right(90)
    turtle.forward(20)
    turtle.left(90)
    turtle.penup()
    turtle.setposition(-300, -100)

    # alphabetic characters
    top_line = ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P']
    mid_line = ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L']
    btm_line = ['Z', 'X', 'C', 'V', 'B', 'N', 'M']

    # top line
    for i in range(10):
        turtle.pendown()
        turtle.begin_fill()

        turtle.fillcolor('light blue')
        turtle.forward(40)
        turtle.right(90)
        turtle.forward(40)
        turtle.right(90)
        turtle.forward(40)
        turtle.right(90)
        turtle.forward(40)
        turtle.right(90)

        turtle.penup()
        turtle.setposition(-290 + 50 * i, -130)
        turtle.pendown()
        turtle.write(top_line[i], font=("Arial", 14, "bold"))
        turtle.penup()
        turtle.setposition(-300 + 50 * i, -100)
        turtle.pendown()

        turtle.end_fill()
        turtle.penup()
        turtle.forward(50)

    # mid line
    turtle.setposition(-280, -165)
    for i in range(9):
        turtle.pendown()
        turtle.begin_fill()

        turtle.fillcolor('light green')
        turtle.forward(40)
        turtle.right(90)
        turtle.forward(40)
        turtle.right(90)
        turtle.forward(40)
        turtle.right(90)
        turtle.forward(40)
        turtle.right(90)

        turtle.penup()
        turtle.setposition(-270 + 50 * i, -195)
        turtle.pendown()
        turtle.write(mid_line[i], font=("Arial", 14, "bold"))
        turtle.penup()
        turtle.setposition(-280 + 50 * i, -165)
        turtle.pendown()

        turtle.end_fill()
        turtle.penup()
        turtle.forward(50)

    # bottom line
    turtle.setposition(-260, -230)
    for i in range(7):
        turtle.pendown()
        turtle.begin_fill()

        turtle.fillcolor('light blue')
        turtle.forward(40)
        turtle.right(90)
        turtle.forward(40)
        turtle.right(90)
        turtle.forward(40)
        turtle.right(90)
        turtle.forward(40)
        turtle.right(90)

        turtle.penup()
        turtle.setposition(-250 + 50 * i, -260)
        turtle.pendown()
        turtle.write(btm_line[i], font=("Arial", 14, "bold"))
        turtle.penup()
        turtle.setposition(-260 + 50 * i, -230)
        turtle.pendown()

        turtle.end_fill()
        turtle.penup()
        turtle.forward(50)

    # button press-call

    turtle.onscreenclick(btnClk, 1)
    turtle.listen()
Пример #50
0
        t.left(180)
        t.forward(60-level*4)
        t.left(180)
        t.right(20)
        
        tree(2,level+1)
        t.left(180)
        t.penup()
        t.forward(60-level*4)
        t.left(180)
        t.left(20)
        

t.colormode(255)
t.pencolor((0,0,0))
t.pensize(9)
t.penup()
t.goto(0,-100)
t.left(90)
t.pendown()
t.forward(60)

tree(1,1)
t.penup()
t.left(180)
t.forward(60)
t.left(180)
t.right(20)
tree(2,1)
t.penup()
t.left(180)
import turtle


def drawSnake(rad, angle, len, neckrad):
    for _ in range(len):
        turtle.circle(rad, angle)
        turtle.circle(-rad, angle)

    turtle.circle(rad, angle / 2)
    turtle.forward(rad / 2)  # 直线前进
    turtle.circle(neckrad, 180)
    turtle.forward(rad / 4)


if __name__ == "__main__":
    turtle.setup(1500, 1400, 0, 0)
    turtle.pensize(30)  # 画笔尺寸
    turtle.pencolor("green")
    turtle.seth(-40)  # 前进的方向
    drawSnake(70, 80, 2, 15)
Пример #52
0
import turtle
turtle.showturtle()
turtle.pendown()
turtle.pensize(10)
turtle.color('blue')
turtle.circle(50)
turtle.penup()
turtle.setx(120)
turtle.pendown()
turtle.color('black')
turtle.circle(50)
turtle.penup()
turtle.setx(240)
turtle.pendown()
turtle.color('red')
turtle.circle(50)
turtle.penup()
turtle.goto(180, -50)
turtle.pendown()
turtle.color('green')
turtle.circle(50)
turtle.penup()
turtle.setx(60)
turtle.pendown()
turtle.color('yellow')
turtle.circle(50)
import turtle

scr = turtle.Screen()
scr.bgcolor("yellow")
turtle.pensize(7)

for i in range(0, 5):
    turtle.left(72)
    turtle.forward(100)

turtle.exitonclick()
Пример #54
0
    for action in path:

        if action == 'L':
            t.setheading(180)

        if action == 'R':
            t.setheading(0)

        if action == 'U':
            t.setheading(90)

        if action == 'D':
            t.setheading(270)

        if action != 'N':
            t.forward(60)

        t.setheading(0)

    t.speed(0)


t.speed(0)
t.pensize(4)
t.shape('turtle')
t.setposition(300, 300)
t.clear()
t.setheading(180)

draw_grid()
Пример #55
0
from turtle import *
import turtle
import random

turtle.hideturtle()
# turtle.bgcolor('black')
# turtle.color('white')
turtle.speed(0)
turtle.delay(0)

turtle.pensize(0.5)
width = 1900
height = 1080
turtle.setup(width, height, startx=0, starty=0)

# fill the background (bgcolor does not save by itself using .postscript())
# turtle.pu()
# turtle.goto(-1000, -500)
# canvas = turtle.getcanvas()
# turtle.fillcolor(turtle.Screen().bgcolor())
# turtle.begin_fill()

# turtle.forward(width+2), turtle.left(90)
# turtle.forward(height+2), turtle.left(90)
# turtle.forward(width+2), turtle.left(90)
# turtle.forward(height+2), turtle.left(90)
# turtle.end_fill()

#reposition starting point
turtle.pu()
turtle.goto(-550, -400)
Пример #56
0
import turtle as tt
import random

tt.bgcolor("black")
#turn off animations
tt.tracer(0, 0)
tt.pencolor("black")
tt.setpos(0, -400)
#draw trunk
trunkLen = 500
trunkWidth = 50
tt.pencolor("brown")
tt.left(90)
tt.pensize(trunkWidth)
tt.forward(trunkLen)
tt.backward(5)

tt.speed(9)
tt.update()


def drawFlower(size):
    if random.randint(0, 3) == 0:
        tt.pencolor("yellow")
    else:
        tt.pencolor("pink")
    tt.pensize(3)
    tt.forward(size)
    tt.backward(size * 2)
    tt.forward(size)
    tt.left(90)
Пример #57
0
import turtle as t

t.speed(3)
#t.bgcolor('black')
t.pensize(3)


def func():
    for i in range(200):
        t.right(1)
        t.forward(1)


t.color('black', 'red')
t.begin_fill()
t.left(140)
t.forward(111.65)
func()
t.left(120)
func()
t.forward(111.65)
t.end_fill()
t.hideturtle()
t.done()
Пример #58
0
def coch(level):
    coch_a(400, level)
    turtle.right(120)
    coch_a(400, level)
    turtle.right(120)
    coch_a(400, level)
    turtle.hideturtle()


if __name__ == '__main__':
    turtle.tracer(False)
    turtle.setup(600, 600)
    turtle.penup()
    turtle.bgcolor("white")
    turtle.pensize(2)
    turtle.pencolor('red')
    turtle.goto(-200, 100)
    turtle.speed(5)
    turtle.pendown()
    coch(3)
    turtle.pu()
    ts = turtle.getscreen().getcanvas(
    )  #.postscript(file="coch.eps") #.eps文件即postscript脚本
    import canvasvg
    canvasvg.saveall("coch.svg", ts)
    #  import cairosvg
    #  with open("coch.svg") as svg_input, open("coch.png", 'wb') as png_output:  # svg转换png
    #      cairosvg.svg2png(bytestring=svg_input.read(), write_to=png_output)
    turtle.tracer(True)
    turtle.exitonclick()
Пример #59
0
import math as m
EAST = 0
SOUTH = 270
WEST = 180
NORTH = 90
A_TURN = 90
GLASS_WIDTH = 40
HALF_WIDTH = 20
GLASS_HEIGHT = 30
HALF_HEIGHT = 15
import turtle
turtle.hideturtle()
turtle.pensize(3)
turtle.speed(0)
turtle.penup()
turtle.goto(50, 50)
turtle.pendown()
turtle.setheading(EAST)
turtle.forward(GLASS_WIDTH)
turtle.left(A_TURN)
turtle.forward(GLASS_HEIGHT)
turtle.left(A_TURN)
turtle.forward(GLASS_WIDTH)
turtle.left(A_TURN)
turtle.forward(GLASS_HEIGHT)
turtle.setheading(EAST)
turtle.penup()
turtle.goto(50, 65)
turtle.pendown()
turtle.goto(-50, 65)
turtle.setheading(SOUTH)
Пример #60
0
    (x, y) = t.pos()
    inside = left_limit < x < right_limit and bottom_limit < y < top_limit
    return inside


def move_turtle(line_length):
    pen_colors = [
        'red', 'orange', 'yellow', 'green', 'blue', 'purple', 'pink', 'white',
        'cyan'
    ]
    t.pencolor(random.choice(pen_colors))
    if inside_window():
        angle = random.randint(0, 180)
        t.right(angle)
        t.forward(line_length)
    else:
        t.backward(line_length)


line_length = get_line_length()
line_width = get_line_width()

t.shape('turtle')
t.fillcolor('green')
t.bgcolor('black')
t.speed('fastest')
t.pensize(line_width)

while True:
    move_turtle(line_length)