Пример #1
1
def draw_circle(x,y):
	turtle.penup()
	turtle.goto(x,y)
	turtle.pendown()
	turtle.begin_fill()
	turtle.circle(10)
	turtle.end_fill()
def circle(a,b):
    turtle.color("green")
    turtle.pu()
    turtle.goto(a,b)
    turtle.pd()
    turtle.setheading(90)
    turtle.circle(40)
Пример #3
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()
Пример #4
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)
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)
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
Пример #7
0
	def draw(self):
		
		turtle.penup()
		turtle.goto(self.point_st)
		turtle.pendown()
		turtle.color(self.border_c, self.fill_c)	
		self._draw()
Пример #8
0
def entrance(pointOne):
    turtle.goto(pointOne[0], pointOne[1] + 36)
    turtle.setheading(270)
    turtle.pendown()
    turtle.forward(15)
    turtle.penup()
    drawArrows()
Пример #9
0
def d(fill=False):
    '''draws a capital D'''
    turtle.setheading(0)
    if fill: bf()
    fd(20)
    circle(20, 90)
    fd(70)
    circle(20, 90)
    fd(20)
    lt(90)
    fd(110)
    lt(90)
    if fill: ef()
    pu()
    turtle.goto(turtle.xcor() + 10, turtle.ycor() + 10)
    pd()
    cfc = fc()
    fc(turtle.getscreen().bgcolor())
    bf()
    fd(10)
    circle(10, 90)
    fd(70)
    circle(10, 90)
    fd(10)
    lt(90)
    fd(90)
    ef()
    lt(90)
    pu()
    turtle.goto(turtle.xcor() + 40, turtle.ycor() - 10)
    pd()
    fc(cfc)
Пример #10
0
def drawmountain(x,y,color):
	t.up
	t.goto(x,y)
	t.down
	t.color(color)
	t.begin_fill()
	t.backward(200)
	t.right(120)
	t.backward(200)
	t.right(120)
	t.backward(200)
	t.right(120)
	t.end_fill()
	t.up

	t.goto(x-75,y+125)
	t.down
	t.color("White")
	t.begin_fill()
	t.backward(50)
	t.right(120)
	t.backward(50)
	t.right(120)
	t.backward(50)
	t.right(120)
	t.end_fill()
	t.up
Пример #11
0
def curva(simbolos,identificador,linea):
  p1= obtener_punto(1,identificador,simbolos)
  p2= obtener_punto(2,identificador,simbolos)
  
  x1 = int (obtener_x(p1,simbolos))
  y1 = int (obtener_y(p1,simbolos))
  x2 = obtener_x(p2,simbolos)
  y2 = obtener_y(p2,simbolos)  

  rotar = obtener_rotar(identificador, simbolos,linea)
  escalar = obtener_escalar(identificador, simbolos,linea)
  relleno = obtener_color(obtener_relleno(identificador,simbolos,linea))  
  turtle.color(relleno)

  tx = obtener_tx(identificador, simbolos,linea)
  ty = obtener_ty(identificador, simbolos,linea)
  potencia = obtener_potencia(identificador,simbolos)
  
  #Trasladar recta
  x1 = int(x1*44 + tx*44)
  x2 = int(x2*44 + tx*44)
  y1 = y1*44 + ty*44
  y2 = y2*44 + ty*44  
  turtle.penup()
  for x in range(x1,x2):
  	turtle.goto(x+(44), (x+(44))**potencia)
  	turtle.pendown()
Пример #12
0
def main():
    """
    Tous les phase du battleship passe par le main()
    et il sert de boucle principal car il est appelé à
    tous les 0.5 secondes
    """
    if i.phase == "PlaceShip":
        i.placeShip()
    elif i.phase == "Attack": # Nom fictif
        i.attack()
    elif i.phase == "win":
        print('Vous avez gagné!')
        turtle.goto(0,0)
        turtle.pencolor('black')
        turtle.write('Vous avez gagné!',align="center",font=("Arial",70, "normal"))
        i.phase = "exit"
    elif i.phase == "lose":
        print('Vous avez perdu!')
        turtle.goto(0,0)
        turtle.pencolor('black')
        turtle.write('Vous avez perdu!',align="center",font=("Arial",70, "normal"))
        i.phase = "exit"
    elif i.phase == "exit":
        turtle.exitonclick()
        return None
    else:
        print('out')

    turtle.ontimer(main,500)
Пример #13
0
def line(a, b, x, y):
    "Draw line from `(a, b)` to `(x, y)`."
    import turtle
    turtle.up()
    turtle.goto(a, b)
    turtle.down()
    turtle.goto(x, y)
Пример #14
0
    def draw_path(self, positions):
        '''
        Draws the path given by a position list
        '''

        def position_to_turtle(pos):
            '''Converts a maze position to a turtle position'''
            return (home_x + _DRAW_SIZE * pos[0], home_y - _DRAW_SIZE * pos[1])

        # Get maze size
        width, height = self.size

        # Prepare turtle
        home_x = (-(_DRAW_SIZE * width) / 2) + (_DRAW_SIZE / 2)
        home_y = ((_DRAW_SIZE * height) / 2) - (_DRAW_SIZE / 2)

        turtle.showturtle()
        turtle.pencolor(_DRAW_PATH)

        # Move to star
        turtle.penup()
        turtle.goto(home_x, home_y)
        turtle.pendown()

        # Draw the path
        for pos in positions:
            turtle.goto(position_to_turtle(pos))
Пример #15
0
def draw_stars():
	for i in range(NSTARS):
		x = random.randint(MINX, MAXX)
		y = random.randint(GROUNDY, MAXY)
		turtle.goto(x, y)
		turtle.color('white')
		turtle.dot(1)
Пример #16
0
def circle(x,y,size):
	turtle.pu()
	turtle.goto(x,y)
	turtle.pd()
	turtle.begin_fill()
	turtle.circle(size)
	turtle.end_fill()
Пример #17
0
	def choix_position(self):
		#position aléatoire dans l'écran
		self.x = random.randint(-350, 350)
		self.y = random.randint(-350, 350)
		tt.up()
		tt.goto(self.x, self.y)
		tt.down()
def drawPoint(x, y): 
    turtle.penup() # Pull the pen up
    turtle.goto(x, y)
    turtle.pendown() # Pull the pen down
    turtle.begin_fill() # Begin to fill color in a shape
    turtle.circle(3) 
    turtle.end_fill() # Fill the shape
Пример #19
0
def drawCircleAt(turtleX, turtleY, circleSize):
    turtle.penup()
    turtle.goto(turtleX,turtleY)
    turtle.pendown()
    turtle.begin_fill()
    turtle.circle(circleSize)
    turtle.end_fill()
Пример #20
0
    def tegnGitter(i0,i1,j0,j1):
        """Gitteret har søjler fra i0 til og med i1 og rækker fra
j0 til og med j1.  Først blankstilles lærredet"""
        xmin,ymin = toXY(i0,j0)
        xlen,ylen = (i1-i0+2)*cs,(j1-j0+2)*cs
        tt.clear()
        tt.penup()
        tt.color(kodefarve[4])
        # vandrette linjer
        x,y = xmin-cs/2,ymin
        tt.setheading(0) # øst
        for j in range(j0,j1+2):
            tt.goto(x,y)
            tt.pendown()
            tt.forward(xlen)
            tt.penup()
            y += cs
        # lodrette linjer
        x,y = xmin,ymin-cs/2
        tt.setheading(90) # nord
        for i in range(i0,i1+2):
            tt.goto(x,y)
            tt.pendown()
            tt.forward(ylen)
            tt.penup()
            x += cs
Пример #21
0
def f(l, n):
	t.up()
	t.goto( - l / 2, l / 3 )
	t.down()
	for i in rang(3):
		vk(l, n)
		t.right(120)
Пример #22
0
def printwin(turtle):
  turtle.stamp()
  turtle.hideturtle()
  turtle.penup()
  turtle.goto(0,0)
  turtle.color("green")
  turtle.write("You Win!",font=("Arial",30), align = "center")
Пример #23
0
def alpha_beta_helper():
	global state, root, alpha_time
	initialize()
	print("PLEASE WAIT!!!")
	root = TreeNode(-1000)
	time1 = time.time()
	alpha_beta(root, 1, state)
	init_screen()
	drawLine()
	drawGrid()
	drawColumns()
	drawRows()
	caliberate()
	col = root.ans
	row = -1
	turtle.onscreenclick(goto)
	for i in range(4):
		if state[i][col] == 0:
			row = i
			break
	state[row][col] = 1
	drawDot(row, col, 1)
	var = (int)(input("Enter 1 to continue playing or 0 to stop."))
	time2 = time.time()
	alpha_time = time2-time1
	if(var == 1):
		turtle.clear()
		turtle.goto(0, 0)
		turtle.penup()
		turtle.right(270)
		alpha_beta_helper()
	else:
		write_analysis(3)
Пример #24
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)
Пример #25
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
Пример #26
0
def hands( freq=166 ):
    """Draw three hands.

    :param freq: Frequency of refresh in milliseconds.
    """
    global running
    now= datetime.datetime.now()
    time= now.time()
    h, m, s, ms = time.hour, time.minute, time.second, int(time.microsecond/1000)

    # Erase old hands.
    while turtle.undobufferentries():
        turtle.undo()

    # Draw new hands.
    hand( h*5+m/60+s/3600, .6*R, 3 )
    hand( m+s/60, .8*R, 2 )
    hand( s+ms/1000, .9*R, 1 )

    # Draw date and time
    turtle.penup(); turtle.home()
    turtle.goto( 0, -120 ); turtle.write( now.strftime("%b %d %H:%M:%S"), align="center", font=("Helvetica", 24, "normal") )

    # Reschedule hands function
    if running:
        # Reset timer for next second (including microsecond tweak)
        turtle.ontimer( hands, freq-(ms%freq) )
Пример #27
0
def roach(turt):
    #make moves a global variable
    global moves
    turt.pencolor(randrange(255),randrange(255),randrange(255))
    turtle.up()
    turtle.goto(0,0)
    turtle.down()
    #write the code for roach to go & turn
    while True:
        moves += 1
        turt_heading = randrange(0,361)
        turt.left(turt_heading)
        turt_length = randrange(0,31)
        turt.forward(turt_length)
        distance = dist(turt)
        #if statement to determine if the roach is outside the circle or inside
        #if inside, keep moving
        #if outside, stop moving
        #return coordinate
        if distance >= 200:
            break
    turt.up()
    moves += moves                      #accummulate total moves
    print(moves)
    return moves
Пример #28
0
def drawCloud(words, num = 20):
    """ Draws a wordcloud with 20 random words, sized by frequency found in 
    the WORDS dictionary. """
    t.reset()
    t.up()
    t.hideturtle()
    topCounts = sorted([words[word] for word in list(words.keys()) if len(word) > 3])
    largest = topCounts[0]
    normalized_counts = {}
    for item in list(words.keys()):
        if len(item) > 3:
            newSize = int(float(words[item]) / largest * 24)
            normalized_counts[item] = newSize
    
    size = t.screensize()
    width_dim = (int(-1 * size[0] / 1.5), int(size[0] / 2))
    height_dim = (int(-1 * size[1] / 1.5), int(size[1] / 1.5))
    

    for item in random.sample(list(normalized_counts.keys()), num):
        t.goto(random.randint(*width_dim), random.randint(*height_dim))
        t.color(random.choice(COLORS))
        try:
            t.write(item, font = ("Arial", int(normalized_counts[item]), "normal"))
        except:
            try:
                t.write(str(item, errors = 'ignore'), font = ("Arial", int(normalized_counts[item]), "normal"))
            except:
                pass
Пример #29
0
def draw_circle(x,y,r,t):
    t.pu()
    t.goto(x+r,y)
    t.setheading(90)
    t.pd()
    t.circle(r)
    t.pu()
Пример #30
0
def draw_tree(x,y):
    startPosX = x
    startPosY = y
    turtle.setpos(x,y)
    turtle.fillcolor("green")
    turtle.begin_fill()
    for i in range(0,4):
        x -=40
        y -=80
        turtle.goto(x,y)
        coords.append(turtle.pos())
        x += 20
        turtle.goto(x,y)
    bottomCorner = turtle.pos()
    x = startPosX
    y = startPosY
    turtle.setpos(x,y)
    for i in range(0,4):
        x +=40
        y -=80
        turtle.goto(x,y)
        coords.append(turtle.pos())
        x -= 20
        turtle.goto(x,y)
    turtle.goto(bottomCorner)
    turtle.end_fill()
import turtle as t


y_max = 300
x_max = 300

ay = -10
dt = 0.1

x, y, Vx, Vy = 0, 0, 10, 0

while True:
    x += Vx*dt
    y += Vy*dt + ay*dt**2/2 
    Vy += ay*dt
    t.goto(x, y)
    if abs(y) >= y_max and Vy<0:
        Vy *= -0.9
        print(y, Vy)
    if abs(x) >= x_max:
        Vx *= -1
Пример #32
0
import turtle as t
import random  # 랜덤함수를 생성
a = random.randint(0, 359)  #a는 0도부터 359도까지 랜덤 설정

#벽만들기
t.speed(0)  #가장 빠르게
t.up()  #꼬리들기
t.goto(-250, -250)  #벽을 그리기 위해 시작점으로 이동
t.down()  #꼬리내리기
for x in range(4):
    t.fd(500)
    t.lt(90)
#거북이 중앙으로 가기
t.up()
t.home()
t.down()
#랜덤 설정된 각도로 회전후 벽까지 이동
t.seth(a)
while -250 < t.xcor() < 250 and -250 < t.ycor() < 250:
    t.fd(1)  # 벽에 부딪히기 전까지 앞으로 1만큼씩 이동
#while True: #아래를 무한 반복
#a=t.heading()
if 0 < a < 45:
    t.lt(180 - 2 * a)
    t.fd(1)
    while -250 < t.xcor() < 250 and -250 < t.ycor() < 250:
        t.fd(1)
if 45 < a < 90:
    t.rt(2 * a)
    t.fd(1)
    while -250 < t.xcor() < 250 and -250 < t.ycor() < 250:
Пример #33
0
REDUCE_RATE = 0.7
WIDTH_RATE = 0.1
RANDOM_RATE_MIN = 0.9
RANDOM_RATE_MAX = 1.1


def tree(length):
    rate = random.uniform(RANDOM_RATE_MIN, RANDOM_RATE_MAX)
    len = length * rate
    t.width(len * WIDTH_RATE)
    t.forward(len)
    if len > MIN_LENGTH:
        sub = len * REDUCE_RATE
        t.left(ANGLE)
        tree(sub)
        t.right(2 * ANGLE)
        tree(sub)
        t.left(ANGLE)
    t.backward(len)


t.speed(0)
t.penup()
t.goto(0, -200)
t.pendown()
t.setheading(90)

tree(120)

t.exitonclick()
Пример #34
0
import turtle as t
All = []

with open('input.txt') as file:
    for line in file:
        A = line.rstrip().split(", ")
        One_of_all = []
        for i in range (0, len(A)-1, 2):
          new = (int(A[i]), int(A[i+1]))
          One_of_all.append(new)
          i+=2
        All.append(One_of_all)

x=0
for i in All:
  t.up()
  t.goto(x, 0)
  for x1,x2 in i:
    t.down()
    t.goto(x1 + x, x2)
  x+=100


Пример #35
0
turtle.title('거북이가 맘대로 다니기')
turtle.shape('turtle')
turtle.pensize(pSize)
turtle.setup(width=swidth + 30, height=sheight + 30)
turtle.screensize(swidth, sheight)

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(-swidth/2<=curX and curX <= swidth/2) and (-sheight/2 <= curY and curY<=sheight/2):
        pass
    else:
        turtle.penup()
        turtle.goto(0,0)
        turtle.pendown()
        
        exitCount += 1
        if exitCount >= 5:
            break
        
turtle.done()
Пример #36
0
def level_1():
    turtle.clear()
    turtle.pu()
    turtle.speed(0)
    turtle.pensize(20)
    turtle.color("grey")
    turtle.goto(-220, 220)
    turtle.pd()
    turtle.goto(220, 220)
    turtle.goto(220, -220)
    turtle.goto(-220, -220)
    turtle.goto(-220, 220)
    turtle.pu()
    turtle.goto(0, 0)
Пример #37
0
def line(startX, startY, endX, endY, color):
    turtle.penup()  # Поднять перо.
    turtle.goto(startX, startY)  # Переместить в начальную точку.
    turtle.pendown()  # Опустить перо.
    turtle.pencolor(color)  # Задать цвет заливки.
    turtle.goto(endX, endY)  # Нарисовать треугольник.
Пример #38
0
for three in range(1):
    t.down()
    t.fd(50)
    t.left(60)
    t.bk(60)
    t.right(60)
    t.fd(30)
    t.left(90)
    t.bk(50)
    t.right(90)
    t.bk(50)
    t.up()

for five in range(1):
    t.goto(70, 0)
    t.down()
    t.fd(50)
    t.bk(50)
    t.right(90)
    t.fd(50)
    t.left(90)
    t.fd(50)
    t.right(90)
    t.fd(50)
    t.right(90)
    t.fd(50)
    t.right(180)  # возвращаем исходное направление
    t.up()

for fourth in range(1):
Пример #39
0
        position = free_points[rand_index]
        while position in wall_list:
            rand_index = random.randint(0, len(free_points) - 1)
            position = free_points[rand_index]
        new_position = (position[0] + 10, position[1] - 10)
        food_pos.append(new_position)
        food.goto(new_position)
        b=food.stamp()
        food_stamps.append(b)
        food.hideturtle()
make_food()        
############################################
turtle.hideturtle()
turtle.penup()
turtle.pensize(5)
turtle.goto(250, 250)
turtle.pendown()
turtle.goto(250, 280)
turtle.goto(180, 280)
turtle.goto(180, 250)
turtle.goto(250, 250)
turtle.penup() 
turtle.goto(215, 255)
timer = turtle.clone()
b = turtle.clone()
b.penup()
b.showturtle()
b.shape("square")
b.color("grey")
b.goto(223,265)
s=turtle.clone()
Пример #40
0
def move_car():
    global direction,wall_list, score
    my_car = car.pos()
    carx_pos = my_car[0]
    cary_pos = my_car[1]
    if direction == UP:
        car.goto(carx_pos , cary_pos + square_size)
    elif direction == DOWN:
        car.goto(carx_pos , cary_pos - square_size)
    elif direction == RIGHT:
        car.goto(carx_pos + square_size , cary_pos)

    elif direction == LEFT:
        car.goto(carx_pos - square_size , cary_pos)
        
    
        
    car.showturtle()

    my_car = car.pos()
    car_pos_list.append(my_car)
    new_car_stamp = car.stamp()
    car_stamp_list.append(new_car_stamp)
    old_car_stamp = car_stamp_list.pop(0)
    car.clearstamp(old_car_stamp)
    car_pos_list.pop(0)

    carx_pos = my_car[0]
    cary_pos = my_car[1]
    my_car_new = (carx_pos-square_size/2,cary_pos+square_size/2)
    if my_car_new in wall_list:
        #############################
        if direction == UP:
            car.goto(my_car[0], my_car[1] - square_size)
            pygame.mixer.music.load("something.wav")
            pygame.mixer.music.play(1)
            pygame.mixer.music.set_volume(1)

            
            
            #########################
        elif direction == DOWN:
            car.goto(my_car[0], my_car[1] + square_size)
            pygame.mixer.music.load("something.wav")
            pygame.mixer.music.play(1)
            pygame.mixer.music.set_volume(1)

                
            
            ################################3
        elif direction == LEFT:
            car.goto(my_car[0]+square_size, my_car[1])
            pygame.mixer.music.load("something.wav")
            pygame.mixer.music.play(1)
            pygame.mixer.music.set_volume(1)

            
            
            #################################
        elif direction == RIGHT:
            car.goto(my_car[0] - square_size, my_car[1])
            pygame.mixer.music.load("something.wav")
            pygame.mixer.music.play(1)
            pygame.mixer.music.set_volume(1)
            

        #############################################
    if carx_pos >= 250:
        car.goto(my_car[0] - square_size , my_car[1])
    if carx_pos <= -250:
        car.goto(my_car[0] + square_size , my_car[1])
    if cary_pos >= 250:
        car.goto(my_car[0] , my_car[1]- square_size )
    if cary_pos <= -250:
        car.goto(my_car[0]  , my_car[1]+ square_size)
    
    
    if car.pos() in food_pos:
        food_ind=food_pos.index(car.pos())
        food.clearstamp(food_stamps[food_ind])
        old_food = food_pos.pop(food_ind)
        food_id = food_stamps.pop(food_ind)
        pygame.mixer.music.load("eatingsounds.wav")
        pygame.mixer.music.play(1)
        pygame.mixer.music.set_volume(1)
        score += 1
    elif score == 30:
        turtle.goto(0,0)
        turtle.color('white')
        turtle.write('YOU WIN',font=("Arial" , 40,"normal"),align="center")
        print('YOU WIN')
        pygame.mixer.music.stop
        time.sleep(5)
        quit()
    def eye(self, eye_type):
        print("画眼睛....")
        if eye_type == "large":
            # 设置填充颜色
            turtle.fillcolor("red")
            # left eye
            turtle.goto(-100, 150)
            # 准备填充
            turtle.begin_fill()
            turtle.pendown()
            turtle.circle(40, 360)
            # 填充结束
            turtle.end_fill()
            turtle.penup()

            # 眼睛中的黑色部分
            turtle.fillcolor("black")
            turtle.goto(-120, 150)
            # 准备填充
            turtle.begin_fill()
            turtle.pendown()
            turtle.circle(15, 360)
            # 填充结束
            turtle.end_fill()
            turtle.penup()

            # right eye
            # 设置填充颜色
            turtle.fillcolor("red")
            # 光标移位
            turtle.goto(60, 150)
            # 准备填充
            turtle.begin_fill()
            turtle.pendown()
            turtle.circle(40, 360)
            # 填充结束
            turtle.end_fill()
            turtle.penup()

            # right 眼睛中的黑色部分
            turtle.fillcolor("black")
            turtle.goto(40, 150)
            # 准备填充
            turtle.begin_fill()
            turtle.pendown()
            turtle.circle(15, 360)
            # 填充结束
            turtle.end_fill()
            turtle.penup()

        elif eye_type == "small":
            # left eye
            # 设置填充颜色
            turtle.fillcolor("red")
            turtle.goto(-120, 140)
            # 准备填充
            turtle.begin_fill()
            turtle.pendown()
            turtle.circle(20, 360)
            # 填充结束
            turtle.end_fill()
            turtle.penup()
            # 眼球
            turtle.fillcolor("black")
            turtle.goto(-120, 150)
            # 准备填充
            turtle.begin_fill()
            turtle.pendown()
            turtle.circle(4, 360)
            # 填充结束
            turtle.end_fill()
            turtle.penup()

            # right eye
            # 设置填充颜色
            turtle.fillcolor("red")
            turtle.goto(30, 150)
            turtle.begin_fill()
            turtle.pendown()
            turtle.circle(20, 360)
            # 填充结束
            turtle.end_fill()
            turtle.penup()

            # right 眼球
            turtle.fillcolor("black")
            turtle.goto(30, 155)
            # 准备填充
            turtle.begin_fill()
            turtle.pendown()
            turtle.circle(4, 360)
            # 填充结束
            turtle.end_fill()
            turtle.penup()
Пример #42
0
'''

# Using Turtle - https://docs.python.org/3.3/library/turtle.html
import turtle
from random import randrange

turtle.circle(15)

turtle.circle(35, steps=3)

# input("Wait")

turtle.colormode(255)
turtle.penup()
turtle.goto(0, 150)
turtle.pensize(12)
turtle.pendown()
# Ignore this line
for _ in range(36):
    turtle.forward(35)
    turtle.right(10)
    turtle.pensize(randrange(100))
    turtle.pencolor(randrange(255), randrange(255), randrange(255))

turtle.done()

# Math with dates in datetime - https://docs.python.org/3/library/datetime.html
from datetime import datetime

currentTime = datetime.now()
Пример #43
0
def screenLeftClick(x, y):
    global r, g, b
    turtle.pencolor((r, g, b))
    turtle.pendown()
    turtle.goto(x, y)
Пример #44
0
# CTI-110
# P4T1b: Initials
# William Starling
# 10/15/2019
#
# Import Turtle.
import turtle

# Hide the turtle arrow.
turtle.hideturtle()

# Pick pen up.
turtle.penup()

# Go to X and Y coordinates of (-250,250).
turtle.goto(-250, 250)

# Put the Pen down to draw.
turtle.pendown()

# Set pen size as 5.
turtle.pensize(5)

# Set pen color as sky blue.
turtle.pencolor('sky blue')

# Turn right 70 degrees.
turtle.right(70)

# Go forward 150 pixels.
turtle.forward(150)
Пример #45
0
import turtle

length = eval(input("Enter the length of a star: "))

turtle.penup()
turtle.goto(0, length / 2)
turtle.pendown()

turtle.right(72)
turtle.forward(length)

turtle.right(144)
turtle.forward(length)

turtle.right(144)
turtle.forward(length)

turtle.right(144)
turtle.forward(length)

turtle.right(144)
turtle.forward(length)

turtle.done()
Пример #46
0
import turtle as t
t.speed(10)
t.penup()
t.goto(-320, -260)
t.pendown()
t.color('red', 'red')
t.begin_fill()
#画国旗背景
for i in range(2):
    t.forward(660)
    t.left(90)
    t.forward(440)
    t.left(90)
t.end_fill()


def draw_star(center_x, center_y, r):
    t.setpos(center_x, center_y)
    pt1 = t.pos()
    t.circle(-r, 72)
    pt2 = t.pos()
    t.circle(-r, 72)
    pt3 = t.pos()
    t.circle(-r, 72)
    pt4 = t.pos()
    t.circle(-r, 72)
    pt5 = t.pos()
    #画五角星
    t.color('yellow', 'yellow')
    t.begin_fill()
    t.goto(pt3)
Пример #47
0
def movepen(x, y, angle):
    t.penup()
    t.goto(x, y)
    t.setheading(angle)
    t.pendown()
Пример #48
0
import turtle as tl
import random
for i in range(60):
    tl.penup()
    tl.goto(random.randint(-300, 300), random.randint(-300, 300))
    tl.pendown()
    red_amount = random.randint(0, 60) / 100.0
    blue_amount = random.randint(50, 100) / 100.0
    green_amount = random.randint(0, 70) / 100.0
    tl.pencolor((red_amount, blue_amount, green_amount))
    circle_size = random.randint(10, 40)
    tl.pensize(random.randint(1, 5))
    tl.speed(10)
    for i in range(6):
        tl.circle(circle_size)
        tl.left(45)
tl.done()
Пример #49
0
import turtle

# Everything that comes after the # is a
# comment.
# It is a note to the person reading the code.
# The computer ignores it.
# Write your code below here...

# ...and end it before the next line.

turtle.penup()  #Brings the pen up, so
#nothing will be drawn
#Puts the pen down, so we
#are ready to draw!
turtle.goto(10, 20)  #Go to the position “x"&"y",
#but write in numbers
#instead

turtle.penup()  #Pick up the pen so it doesn’t
#draw
turtle.goto(-200, -100)  #Move the turtle to the
#position (-200, -100)
#on the screen
turtle.pendown()  #Put the pen down to start
#drawing
#Draw the M:
turtle.goto(-200, -100 + 200)
turtle.goto(-200 + 50, -100)
turtle.goto(-200 + 100, -100 + 200)
turtle.goto(-200 + 100, -100)
Пример #50
0
#RoseDraw.py
import turtle as t
# 定义一个曲线绘制函数
def DegreeCurve(n, r, d=1):
    for i in range(n):
        t.left(d)
        t.circle(r, abs(d))
# 初始位置设定
s = 0.2 # size
t.setup(450*5*s, 750*5*s)
t.pencolor("black")
t.fillcolor("red")
t.speed(100)
t.penup()
t.goto(0, 900*s)
t.pendown()
# 绘制花朵形状
t.begin_fill()
t.circle(200*s,30)
DegreeCurve(60, 50*s)
t.circle(200*s,30)
DegreeCurve(4, 100*s)
t.circle(200*s,50)
DegreeCurve(50, 50*s)
t.circle(350*s,65)
DegreeCurve(40, 70*s)
t.circle(150*s,50)
DegreeCurve(20, 50*s, -1)
t.circle(400*s,60)
DegreeCurve(18, 50*s)
t.fd(250*s)
screen.bgcolor("black")
goto(0, screenMaxY - 200)
color('grey')
write("The Pita Hero!!", align="center", font=("Arial", 50))
goto(0, screenMaxY - 215)
write("CoOl GaMe WiTh CoOl FeAtUrEs...YoU hAvE tO pLaY iT!", align="center")
turtle.showturtle()
goto(0, screenMaxY - 350)
write("Play game", align="center", font=("Ariel", 20))
goto(0, screenMaxY - 400)
write("Score table", align="center", font=("Ariel", 20))
goto(0, screenMaxY - 450)
write("How to play", align="center", font=("Ariel", 20))
turtle.register_shape("Falafel.gif")
turtle.shape("Falafel.gif")
turtle.goto(-200, -200)
turtle.stamp()
turtle.register_shape("player.gif")
turtle.shape("player.gif")
turtle.goto(200, -200)
turtle.stamp()
xclick = 0
yclick = 0


def variables(rawx, rawy):
    global xclick
    global yclick
    xclick = int(rawx // 1)
    yclick = int(rawy // 1)
    print((xclick, yclick))
Пример #52
0
import turtle
turtle.goto(50, 50)
turtle.goto(50, 0)
turtle.goto(0, 0)
turle.mainloop()
Пример #53
0
import turtle

turtle.setup(640, 480)
turtle.bgcolor('gray')
turtle.fillcolor('green')
turtle.pencolor('red')
turtle.pensize(3)
turtle.hideturtle()
turtle.dot()
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.dot()
turtle.pencolor('black')
turtle.write('X= ' + str(turtle.xcor()) + '\nY= ' + str(turtle.ycor()))
turtle.showturtle()
#turtle.done()
Пример #54
0
import turtle
# Everything that comes after the # is a
#comment
# It is a note to the person reading this code.
# The computer ignores it.
# Write your code below here...


#...and end it before the next line.

# draw m
turtle.penup()
turtle.goto(-200,-100)
turtle.pendown()
turtle.goto(-200,100)
turtle.goto(-150,-100)
turtle.goto(-100,100)
turtle.goto(-100,-100)
turtle.penup()

#draw e

turtle.goto(-50,-100)
turtle.pendown()
turtle.goto(-50,100)
turtle.goto(50,100)
turtle.penup()
turtle.goto(-50,0)
turtle.pendown()
turtle.goto(50,0)
turtle.penup()
Пример #55
0
import turtle
import random

bg = turtle.Screen()
bg.bgcolor("black")

turtle.penup()
turtle.goto(-170, -180)
turtle.color("white")
turtle.pendown()
turtle.forward(350)

turtle.penup()
turtle.goto(-160, -150)
turtle.color("white")
turtle.pendown()
turtle.forward(300)

turtle.penup()
turtle.goto(-150, -120)
turtle.color("white")
turtle.pendown()
turtle.forward(250)

turtle.penup()
turtle.goto(-100, -100)
turtle.color("pink")
turtle.begin_fill()
turtle.pendown()
turtle.forward(140)
turtle.left(90)
Пример #56
0
    turtle.goto(pt1)
    turtle.goto(pt4)
    turtle.goto(pt2)
    turtle.goto(pt5)
    turtle.fill(False)
turtle.speed(5)
turtle.penup()
star_x=-320
star_y=-260
len_x=660
len_y=440
draw_rectangle(star_x,star_y,len_x,len_y)
pice=660/30
big_center_x=star_x+5*pice
big_center_y=star_y+len_y-pice*5
turtle.goto(big_center_x,big_center_y)
turtle.left(90)
turtle.forward(pice*3)
turtle.right(90)
draw_star(turtle.xcor(),turtle.ycor(),pice*3)
turtle.goto(star_x+10*pice,star_y+len_y-pice*2)
turtle.left(turtle.towards(big_center_x,big_center_y)-turtle.heading())
turtle.forward(pice)
turtle.right(90)
draw_star(turtle.xcor(),turtle.ycor(),pice)
turtle.goto(star_x+pice*12,star_y+len_y-7*pice)
turtle.left(turtle.towards(big_center_x,big_center_y)-turtle.heading())
turtle.forward(pice)
turtle.right(90)
draw_star(turtle.xcor(),turtle.ycor(),pice)
turtle.goto(star_x+pice*10,star_y+len_y-9*pice)
Пример #57
0
import turtle
firstE = -50

secondE = 100

# Everything that comes after the # is a
# comment.
# It is a note to the person reading the code.
# The computer ignores it.
# Write your code below here...
turtle.penup()  #Pick up the pen so it doesn’t
#draw
turtle.goto(-200, -100)  #Move the turtle to the
#position (-200, -100)
#on the screen
turtle.pendown()  #Put the pen down to start
#drawing
#Draw the M:
turtle.goto(-200, -100 + 200)
turtle.goto(-200 + 50, -100)
turtle.goto(-200 + 100, -100 + 200)
turtle.goto(-200 + 100, -100)

turtle.penup()

turtle.goto(firstE, -100)

turtle.pendown()

turtle.goto(firstE, 100)
turtle.goto(firstE + 75, 100)
Пример #58
0
    "goto": {
        "left": -25,
        "right": 60
    },
    "heading": 180,
    "forward": 40,
    "left": 144
}, {
    "goto": {
        "left": -100,
        "right": 10
    },
    "heading": 300,
    "forward": 40,
    "left": 144
}]

for i in range(len(arr)):
    data = arr[i]
    turtle.begin_fill()
    turtle.up()
    turtle.goto(data["goto"]["left"], data["goto"]["right"])
    turtle.setheading(data["heading"])
    turtle.down()
    for j in range(5):
        turtle.forward(data["forward"])
        turtle.left(data["left"])
    turtle.end_fill()

turtle.hideturtle()
turtle.done()
Пример #59
0
def MovePen(x, y):
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()
Пример #60
0
import turtle


x=0
while x<300:
    y = x**2/300
    turtle.goto(x,  y)
    x=x+100

turtle.mainloop()