예제 #1
0
파일: engine.py 프로젝트: sbihel/retrogames
	def heading(self):
		'''
		Returns the direction the object should be facing.  By
		default, this is towards where the object will be moving.
		'''
		return turtle.towards(self.x + self.deltax,
				      self.y + self.deltay)
예제 #2
0
def hlNotNext(pointOne, pointTwo, label, distance):
    chart = [0, 0, 45, 85, 135, 195, 265, 345]
    turtle.goto(pointOne[0] - 12, pointOne[1] + 16)
    turtle.pendown()
    middle = [(pointOne[0] + pointTwo[0]) / 2, pointOne[1] + chart[distance]]
    turtle.goto((pointOne[0] + pointTwo[0]) / 2, pointOne[1] + chart[distance])
    turtle.setheading(turtle.towards(pointTwo[0] + 12, pointTwo[1] + 16))
    turtle.goto(pointTwo[0] + 12, pointTwo[1] + 16)
    turtle.penup()
    drawArrows()
    turtle.setheading(180)
    turtle.goto(middle[0] - 5, middle[1])
    turtle.write(label, font=("Arial", 6, "normal"))
예제 #3
0
def triangulos(n, base, lado):
    #x0 = -base/2
    #x1 = base/2
    #y0 = y1 = sqrt((base/2)^2 + lado^2)
    x = -base/2
    y = -math.sqrt((base/2)**2 + lado**2)
    #x e y são coordenadas do canto inferior esquerdo do triangulo maior
    for i in range(n):
        turtle.setheading(turtle.towards(x, y)) #aponta na direcao do canto inferior esquerdo
        turtle.forward((i+1)*lado) #avanca o comprimento de n (i+1) lados sendo n o numero do triangulo a desenhar atualmente
        turtle.goto(-turtle.position()[0],turtle.position()[1]) #vai para a posicao simetrica ao canto inferior esquerdo (canto inferior direito)
        turtle.goto(0,0) #volta à origem, canto superior
    turtle.hideturtle()
    turtle.exitonclick()
예제 #4
0
def forwardBox(distance):
    original_xcor = 0
    original_ycor = 0
    x_dist = 0
    y_dist = 0
    while distance > 0:
        if x_dist >= 100 or y_dist >= 100:
            turtle.setheading(turtle.towards(0, 0))
            print("wall: " + str(turtle.xcor()) + ", " + str(turtle.ycor()) + " : " + str(distance))
        turtle.forward(1)
        x_dist = math.fabs(turtle.xcor() - original_xcor)
        y_dist = math.fabs(turtle.ycor() - original_ycor)
        distance -= 1
    print("final: " + str(turtle.xcor()) + ", " + str(turtle.ycor()) + " : " + str(distance))
예제 #5
0
파일: Logo.py 프로젝트: Tayloz10/CSCI-135
def draw_arc(p1, p2, ext):
    turtle.up()
    turtle.goto(p1)
    turtle.seth(turtle.towards(p2))
    a = turtle.heading()
    b = 360 - ext
    c = (180 - b) / 2
    d = a - c
    e = d - 90
    r = dist(p1, p2) / 2 / math.sin(math.radians(b / 2))
    turtle.seth(e)
    turtle.down()
    turtle.circle(r, ext, 100)
    return (turtle.xcor(), turtle.ycor())
예제 #6
0
    def move(self):
        current_x, current_y = self.location
        turtle.setposition(current_x, current_y)

        #Use turtle.towards() function to find the direction of movement
        destination_x, destination_y = self.destination
        direction = turtle.towards(destination_x, destination_y)

        #Calculate person's new position after moving half radius towards the destination
        next_x = current_x + self.radius // 2 * math.sin(
            math.radians(direction))
        next_y = current_y + self.radius // 2 * math.cos(
            math.radians(direction))

        self.location = (next_x, next_y)
예제 #7
0
def draw_clothoid_line(fun_length, fun_angle, fun_times):
    """
    功能:绘图函数(迭代)
    :param fun_length: 函数内部单位长度
    :param fun_angle:函数内部单位角度
    :param fun_times:函数循环次数
    :return: 循环次数
    """
    for i in range(1, fun_times):
        turtle.left(fun_angle)
    turtle.forward(fun_length)
    fun_angle += 1
    set_position = turtle.position()
    set_direction = turtle.towards(0, 0)
    print(set_position)
    print(set_direction)
예제 #8
0
def circle(start, end):
    "Draw circle from start to end."
    #PM = punto medio entre los puntos
    pmx=(start.x+end.x)/2
    pmy=(start.y+end.y)/2
    turtle.penup()
    turtle.setpos(start.x,start.y)
    turtle.pendown()
    ang = turtle.towards(end.x,end.y)
    turtle.setheading(ang)
    rad = math.hypot(abs(pmx-start.x),abs(pmy-start.y))
    
    begin_fill()
    turtle.circle(rad)
    end_fill()

    pass  # TODO
예제 #9
0
def arrowarc(p0, p1, r_factor, label=''):
    import math
    dx = p1[0] - p0[0]
    dy = p1[1] - p0[1]
    d = (dx**2 + dy**2)**0.5
    r = (1 + r_factor) * d / 2

    turtle.penup()
    turtle.goto(p0)
    turtle.pendown()
    turtle.setheading(turtle.towards(p1))

    half_angle = math.degrees(math.asin(d / (2 * r)))
    turtle.left(half_angle)
    turtle.circle(-r, half_angle)
    turtle.stamp()
    turtle.write(label, font=('Arial', 32, 'normal'))
    turtle.circle(-r, half_angle)
예제 #10
0
    def move(self):
        """Moves this person radius / 2 towards their destination. If their
        destination is closer than radius / 2, they will move directly to their
        destination instead.
        """
        turtle.penup()  # Ensure nothing is drawn while moving
        turtle.setpos(self.location)

        distance = distance_2d(self.location, self.destination)

        # Clamp distance below radius / 2 (inclusive)
        half_radius = self.radius / 2
        if distance > half_radius:
            distance = half_radius

        # Move the person towards their destination
        turtle.setheading(turtle.towards(self.destination))
        turtle.forward(distance)
        self.location = turtle.pos()
예제 #11
0
def odmocnina(n):
    turtle.forward(100)
    turtle.left(90)
    turtle.forward(100)
    for i in range(n - 1):
        rot = turtle.towards(
            0, 0)  # vypočíta uhol na ktorý sa má natočiť na bod 0,0
        dist = turtle.distance(0, 0)  # vypočíta vzdialenosť od bodu 0,0
        turtle.setheading(
            rot)  # natočí 'koritnačku' podla uhlu daným premennou rot
        turtle.forward(
            dist
        )  # posunie 'koritnačku' podla vzdialenosti daným premonnou dist
        turtle.backward(dist)
        turtle.right(90)
        turtle.forward(100)
    print(
        "%.2f" %
        (dist /
         100))  # Kvôli grafickéhu znázorneniu je potrebné výsledok vydeliť 100
예제 #12
0
def plot_horizontal_measurement(v1, v2, label, align='top', delta_y=-30):
    (x1, y1) = vertex2pos(v1)
    (x2, y2) = vertex2pos(v2)

    x1 = min(x1, x2)
    x2 = max(x1, x2)
    y = delta_y + (min(y1, y2) if align == 'bottom' else max(y1, y2))

    turtle.penup()
    turtle.shape('arrow')
    turtle.goto((x1 + 10, y))
    turtle.setheading(180)
    turtle.stamp()
    turtle.pendown()
    turtle.goto((x2 - 10, y))
    turtle.setheading(0)
    turtle.stamp()
    turtle.penup()

    turtle.goto(((x1 + x2) / 2, y))
    turtle.setheading(turtle.towards((x2, y)))
    turtle.left(90)
    turtle.write(label, align='center', font=('Arial', 16, 'normal'))
예제 #13
0
def main():

    import turtle
    import cmath


    first_x = int(input("Enter first x coordinate: "))
    first_y = int(input("Enter first y coordinate: "))
    first_coord = (first_x, first_y)
    second_x = int(input("Enter second x coordinate: "))
    second_y = int(input("Enter second y coordinate: "))

#drawing axis
    turtle.pendown()
    turtle.forward(-250)
    turtle.forward(500)
    turtle.forward(-250)
    turtle.left(90)
    turtle.forward(250)
    turtle.forward(-500)
    turtle.forward(250)
    turtle.right(90)

    turtle.penup()
#drawing line
    turtle.goto(first_x, first_y)
    turtle.pendown()
    turtle.dot()

    direction = turtle.towards(second_x, second_y)
    distance = ((((second_x - first_x) ** 2) + ((second_y - first_y) ** 2)) ** (float(1/2)))
    turtle.left(direction)
    print(float(direction))
    turtle.forward(float(distance))
    print(distance)
    turtle.dot()
예제 #14
0
    def draw(self):
        points = self.get_points()
        turtle.speed(2)  # draw a little faster...

        turtle.clear()
        turtle.penup()

        if len(points) > 0:
            start = points.pop(0)
        else:
            start = (0, 0)

        turtle.setposition(start)
        points.append(start)  # be sure we connect the ends

        turtle.pendown()
        for point in points:
            d = turtle.distance(point)
            h = turtle.towards(point)
            turtle.setheading(h)
            turtle.forward(d)

        turtle.hideturtle()
        turtle.exitonclick()
예제 #15
0
def plot_vertical_measurement(v1, v2, label, align='left', delta_x=-30):
    # TODO: generalize using rotational transform
    (x1, y1) = vertex2pos(v1)
    (x2, y2) = vertex2pos(v2)

    y1 = min(y1, y2)
    y2 = max(y1, y2)
    x = delta_x + (max(x1, x2) if align == 'right' else min(x1, x2))

    turtle.penup()
    turtle.shape('arrow')
    turtle.goto((x, y1 + 10))
    turtle.setheading(-90)
    turtle.stamp()
    turtle.pendown()
    turtle.goto((x, y2 - 10))
    turtle.setheading(90)
    turtle.stamp()
    turtle.penup()

    turtle.goto((x, (y1 + y2) / 2))
    turtle.setheading(turtle.towards((x, y2)))
    turtle.left(90)
    turtle.write(label, align='center', font=('Arial', 16, 'normal'))
예제 #16
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.shape("circle")

t.seth(r.randint(0,360))    #처음 시작점에서 랜덤으로 원의 방향을 설정

t.fd(1)                     #원을 소량 이동시켜서 이동한 각도를 fowards함수를 이용하여 구합니다.           
ang=t.towards(0,0)          

#t.down()
while True:                 #계속해서 원을 5씩 움직임

       t.fd(5)

       if t.xcor()<=-250 or t.xcor()>=250:  #원이 좌벽과, 우벽을 만났을때(수직벽)
              a=t.xcor()                  # 이때의 x좌표와 y좌표를 a,b로 기억합니다.
              b=t.ycor()
              horizontal()                #horizontal함수를 이용해서 원의 방향을 바꿈
              t.fd(1)                     #원을 소량 앞으로 이동시켜 회전한 각도를 ang에 저장
              ang=t.towards(a,b)
       
       
       if t.ycor()>=250 or t.ycor()<=-250: #원이 천장,바닥과 만났을때(수평벽)
예제 #17
0
t.forward(100)
t.pos()

a = t.xcor()  # x좌표
b = t.ycor()  # y좌표

t.goto(50, 50)  # 특정 좌표로 이동
t.setx(-50)  # x좌표 값 조정
t.sety(-50)  # y좌표 값 조정
t.pos()

t.distance(100, 100)  # 현재 위치와 (100,100)의 거리

t.heading()

t.towards(10, 10)  # 현재 위치에서 (10,10)을 바라보는 각도

t.setheading(45)  # 거북이 머리 각도 조정
t.forward(50)
t.home()


# 이벤트 설정(함수)
def f():
    t.forward(10)


t.onkeypress(f, "Up")
t.onscreenclick(t.goto)
t.listen()
t.title("Welcome")  # 창 제목 설정
예제 #18
0
    else:        
        t.lt(2*(360-ang))        
def make_r(x,y,d):       #상자 만드는 함수       
    t.up()       
    t.goto(x,y)      
    t.down()       
    for x in range(4):              
        t.fd(d)             
        t.lt(90)
t.pensize(5)make_r(-250,-250,500)     #상자 만들기
t.up()
t.home()
t.shape("turtle")
t.speed(0)
t.setheading(random.randint(0,360))      #거북이 방향 랜덤하게 지정
ang=t.towards(0,0)
d=500
for x in range(200):       #반복함수 통해 거북이가 움직이는 경로 지정    ang=t.heading()
    while True:
        t.fd(3)        
        x=t.xcor()       
        y=t.ycor()
        
        if y >= 250:           
            top_wall()           
            break
        
        if y <= -250:            
            bottom_wall()           
            break
            
예제 #19
0
	def heading(self):
		return turtle.towards(self.x, self.y)
예제 #20
0
import turtle as t

t.goto(100, 50)
t.xcor()
d = t.distance(100, 100)
print(d)
ang = t.heading()
ang = t.towards(10, 10)
t.setheading(90)
t.home()


def f():
    t.forward(10)
    t.onkeypress(f, "Up")
    t.onscreenclick(t.goto)
    t.title("welcome")
예제 #21
0
def cuadrilatero(simbolos,identificador,linea):
  p1= obtener_punto(1,identificador,simbolos)
  p2= obtener_punto(2,identificador,simbolos)
  p3= obtener_punto(3,identificador,simbolos)
  p4= obtener_punto(4,identificador,simbolos)

  #Obtener coordenadas
  x1 = obtener_x(p1,simbolos)*44
  y1 = obtener_y(p1,simbolos)*44
  x2 = obtener_x(p2,simbolos)*44
  y2 = obtener_y(p2,simbolos)*44
  x3 = obtener_x(p3,simbolos)*44
  y3 = obtener_y(p3,simbolos)*44
  x4 = obtener_x(p4,simbolos)*44
  y4 = obtener_y(p4,simbolos)*44

  tx = obtener_tx(identificador, simbolos,linea)
  ty = obtener_ty(identificador, simbolos,linea)
  
  borde = obtener_color(obtener_borde(identificador,simbolos,linea))
  relleno = obtener_color(obtener_relleno(identificador,simbolos,linea))

  #Trasladar cuadrilatero
  x1 = x1 + tx*44
  y1 = y1 + ty*44  
  x2 = x2 + tx*44
  y2 = y2 + ty*44
  x3 = x3 + tx*44
  y3 = y3 + ty*44
  x4 = x4 + tx*44
  y4 = y4 + ty*44	

  #Caucular punto medio de cuadrilatero
  x5 = inferior_izquierdo(x1,x2,x3,x4,y1,y2,y3,y4,0)
  y5 = inferior_izquierdo(x1,x2,x3,x4,y1,y2,y3,y4,1)
  x6 = superior_derecho(x1,x2,x3,x4,y1,y2,y3,y4,0)
  y6 = superior_derecho(x1,x2,x3,x4,y1,y2,y3,y4,1)
  punto_medio_x = (x5 + x6) / 2 
  punto_medio_y = (y5 + y6) / 2

  print punto_medio_x, punto_medio_y

  #Calculo de distancias
  d1 = math.sqrt(((punto_medio_x -x1)**2)+((punto_medio_y-y1)**2))
  d2 = math.sqrt(((punto_medio_x -x2)**2)+((punto_medio_y-y2)**2))
  d3 = math.sqrt(((punto_medio_x -x3)**2)+((punto_medio_y-y3)**2))
  d4 = math.sqrt(((punto_medio_x -x4)**2)+((punto_medio_y-y4)**2))
  
  #Calculo de angulos
  turtle.penup()  
  turtle.setposition(punto_medio_x, punto_medio_y)
  a1 = turtle.towards(x1,y1)
  a2 = turtle.towards(x2,y2)
  a3 = turtle.towards(x3,y3)
  a4 = turtle.towards(x4,y4)

  escalar = obtener_escalar(identificador, simbolos,linea)
  #Calcular nuevos puntos para escalar
  if escalar != 0:
    turtle.setposition(punto_medio_x, punto_medio_y)
    turtle.setheading(0)
    turtle.lt(a1)
    turtle.forward(d1*escalar)
    x1 = turtle.xcor()
    y1 = turtle.ycor()

    turtle.setposition(punto_medio_x, punto_medio_y)
    turtle.setheading(0)
    turtle.lt(a2)
    turtle.forward(d2*escalar)
    x2 = turtle.xcor()
    y2 = turtle.ycor()
   
    turtle.setposition(punto_medio_x, punto_medio_y)
    turtle.setheading(0)
    turtle.lt(a3)
    turtle.forward(d3*escalar)
    x3 = turtle.xcor()
    y3 = turtle.ycor()

    turtle.setposition(punto_medio_x, punto_medio_y)
    turtle.setheading(0)
    turtle.lt(a4)
    turtle.forward(d4*escalar)
    x4 = turtle.xcor()
    y4 = turtle.ycor()

  rotar = obtener_rotar(identificador, simbolos,linea)
  if rotar != 0:
    #Calcular nuevos puntos para rotar
    turtle.setposition(punto_medio_x, punto_medio_y)
    turtle.setheading(0)
    turtle.lt(a1+rotar)
    turtle.forward(d1)
    x1 = turtle.xcor()
    y1 = turtle.ycor()

    turtle.setposition(punto_medio_x, punto_medio_y)
    turtle.setheading(0)
    turtle.lt(a2+rotar)
    turtle.forward(d2)
    x2 = turtle.xcor()
    y2 = turtle.ycor()
   
    turtle.setposition(punto_medio_x, punto_medio_y)
    turtle.setheading(0)
    turtle.lt(a3+rotar)
    turtle.forward(d3)
    x3 = turtle.xcor()
    y3 = turtle.ycor()

    turtle.setposition(punto_medio_x, punto_medio_y)
    turtle.setheading(0)
    turtle.lt(a4+rotar)
    turtle.forward(d4)
    x4 = turtle.xcor()
    y4 = turtle.ycor()

  #Dibujar cuadrilatero
  turtle.color(borde)         
  turtle.penup()
  turtle.setposition(x1,y1)
  turtle.pendown()
  turtle.pensize(8)
  turtle.fillcolor(relleno)
  turtle.begin_fill()
  turtle.setposition(x2,y2)
  turtle.setposition(x3,y3)
  turtle.setposition(x4,y4)
  turtle.setposition(x1,y1)
  turtle.end_fill()
예제 #22
0
polygon(3)  # 삼각형을 그립니다.
polygon(5)  # 오각형을 그립니다.

#그림을 그리지 않고 거북이를 100만큼 이동시킵니다.

t.up()
t.fd(100)
t.down()

polygon2(3, 75)  #한 변이 75인 삼각형을 그립니다.
polygon2(5, 100)  #한 변이 100인 오각형을 그립니다.

a = t.distance(3000, 3000)  # 현재위치에서 (x,y) 좌표까지의 거리
b = t.heading()  # 현재 바라보고 있는 각도를 구함
c = t.towards(3000, 3000)  # 현재 위치에서 (x,y) 위치까지 바라보는 각도를 구함

print("distince : ", a)
print("angele   : ", b)
print("angeleC   : ", c)

t.setheading(90)  # 거북이가 화면 위쪽(90도)을 바라봅니다.
t.home()  # 거북이가 화면 가운데인 (0,0)에서 오른쪽(0도)로 초기화 됩니다.


def up():
    print("up function In")
    t.setheading(90)
    t.forward(10)

예제 #23
0
draw_square(-320, -260, 660, 440)

# big star center
star_part_x = -320
star_part_y = -260 + 440
star_part_s = 660 / 30
center_x, center_y = star_part_x + star_part_s * 5, star_part_y - star_part_s * 5
turtle.setpos(center_x, center_y)
turtle.lt(90)
draw_star(star_part_x + star_part_s * 5, star_part_y - star_part_s * 2,
          star_part_s * 3)

# draw 1st small star
turtle.goto(star_part_x + star_part_s * 10,
            star_part_y - star_part_s * 2)  # go to 1st small star center
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)

# draw 2nd small star
turtle.goto(star_part_x + star_part_s * 12,
            star_part_y - star_part_s * 4)  # go to 1st small star center
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)

# draw 3rd small star
turtle.goto(star_part_x + star_part_s * 12,
            star_part_y - star_part_s * 7)  # go to 1st small star center
예제 #24
0
def dragging(x,y):
    turtle.ondrag(None)
    turtle.setheading(turtle.towards(x,y))
    turtle.goto(x,y)
    turtle.ondrag(dragging)
예제 #25
0
	def heading(self):
		dx = self.dirx
		dy = self.diry
		return turtle.towards(self.x + dx, self.y + dy)
예제 #26
0
파일: mv.py 프로젝트: islarrab/raplog
def ejecutaCuadruplos():
    global ieje, arreglotemp, a, auxCuad1, auxCuad2, auxCuad3
    
    while ieje < getTotalCuad():
        if ieje == dir.f_forward: #forward
            v1 = lee_memoria(arreglotemp.param.pop())
            turtle.forward(v1)
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            a = True

        elif ieje == dir.f_backward: #backward
            v1 = lee_memoria(arreglotemp.param.pop())
            turtle.backward(v1)
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            a = True
            
        elif ieje == dir.f_right: #right
            v1 = lee_memoria(arreglotemp.param.pop())
            turtle.right(v1)
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            a = True
            
        elif ieje == dir.f_left: #left
            v1 = lee_memoria(arreglotemp.param.pop())
            turtle.left(v1)
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            a = True

        elif ieje == dir.f_goto: #turtle_goto
            v1 = lee_memoria(arreglotemp.param.pop())
            v2 = lee_memoria(arreglotemp.param.pop())
            turtle.goto(v1,v2)
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            a = True
            
        elif ieje == dir.f_setx: #setx
            v1 = lee_memoria(arreglotemp.param.pop())
            turtle.setx(v1)
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            a = True
            
        elif ieje == dir.f_sety: #sety
            v1 = lee_memoria(arreglotemp.param.pop())
            turtle.sety(v1)
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            a = True

        elif ieje == dir.f_speed: #speed
            v1 = lee_memoria(arreglotemp.param.pop())
            turtle.speed(v1)
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            a = True

        elif ieje == dir.f_position: #position
            v1 = turtle.position()
            arreglotemp.valor = v1
            a = True

        elif ieje == dir.f_towards: #towards
            v1 = lee_memoria(arreglotemp.param.pop())
            v2 = lee_memoria(arreglotemp.param.pop())
            turtle.towards(v1,v2)
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            a = True
        
        elif ieje == dir.f_mathpow: #mathpow
            v1 = lee_memoria(arreglotemp.param.pop())
            v2 = lee_memoria(arreglotemp.param.pop())
            guarda_en_memoria(10000, math.pow(v1,v2))
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            a = True
        
        elif ieje == dir.f_begin_fill:
            turtle.begin_fill()
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            a = True
        
        elif ieje == dir.f_end_fill:
            turtle.end_fill()
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            a = True
        
        elif ieje == dir.f_color:
            v1 = lee_memoria(arreglotemp.param.pop())
            v2 = lee_memoria(arreglotemp.param.pop())
            turtle.color(v1, v2)
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            a = True
        
        elif ieje == dir.f_pencolor:
            v1 = lee_memoria(arreglotemp.param.pop())
            v2 = lee_memoria(arreglotemp.param.pop())
            v3 = lee_memoria(arreglotemp.param.pop())
            turtle.pencolor(v1, v2, v3)
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            a = True
        
        elif ieje == dir.f_fillcolor:
            v1 = lee_memoria(arreglotemp.param.pop())
            v2 = lee_memoria(arreglotemp.param.pop())
            v3 = lee_memoria(arreglotemp.param.pop())
            turtle.fillcolor(v1, v2, v3)
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            a = True

        cuad= cuadruplos[ieje]
        ieje +=1
        
        op= cuad[0]
        if(cuad[1]>=160000):
            auxCuad1=cuad[1]
            cuad[1]=lee_memoria(cuad[1])
        if(cuad[2]>=160000):
            auxCuad2=cuad[2]
            cuad[2]=lee_memoria(cuad[2])
        
        if op == dir.suma: # suma
            v1 = lee_memoria(cuad[1])
            v2 = lee_memoria(cuad[2])
            guarda_en_memoria(cuad[3], v1+v2)

        elif op == dir.resta: #resta
            v1 = lee_memoria(cuad[1])
            v2 = lee_memoria(cuad[2])
            guarda_en_memoria(cuad[3], v1-v2)
            
        elif op == dir.multi: #multiplicacion
            v1 = lee_memoria(cuad[1])
            v2 = lee_memoria(cuad[2])
            guarda_en_memoria(cuad[3], v1*v2)
            
        elif op == dir.div: #division
            v1 = lee_memoria(cuad[1])
            v2 = lee_memoria(cuad[2])
            guarda_en_memoria(cuad[3], v1/v2)
            
        elif op == dir.menorq: #menor que
            v1 = lee_memoria(cuad[1])
            v2 = lee_memoria(cuad[2])
            guarda_en_memoria(cuad[3], v1<v2)

        elif op == dir.mayorq: #mayor que
            v1 = lee_memoria(cuad[1])
            v2 = lee_memoria(cuad[2])
            guarda_en_memoria(cuad[3], v1>v2)
                    
        elif op == dir.igual: #igual
            v1 = lee_memoria(cuad[1])
            v2 = lee_memoria(cuad[2])
            guarda_en_memoria(cuad[3], v1==v2)
        
        elif op == dir.difer: #diferente a
            v1 = lee_memoria(cuad[1])
            v2 = lee_memoria(cuad[2])
            guarda_en_memoria(cuad[3], v1!=v2)
         
        elif op == dir.asigna: #asignacion
            if cuad[3]>=160000:
                auxCuad3=cuad[3]
                cuad[3]=lee_memoria(cuad[3])
            if arreglotemp.valor != 0 or arreglotemp.valor:
                v1 = arreglotemp.valor
                arreglotemp.valor = 0
            else:
                v1 = lee_memoria(cuad[1])
            if type(v1) == memglobal.tipoMem(cuad[3]):
                guarda_en_memoria(cuad[3], v1)
            else:
                print "* " + str(type(v1)) + ' no se puede asignar con un ' + str(memglobal.tipoMem(cuad[3]))

        elif op == dir.andd: #and
            v1 = lee_memoria(cuad[1])
            v2 = lee_memoria(cuad[2])
            if v1 and v2:
                guarda_en_memoria(cuad[3], True)
            else:
                guarda_en_memoria(cuad[3], False)

        elif op == dir.orr: #or
            v1 = lee_memoria(cuad[1])
            v2 = lee_memoria(cuad[2])
            if v1 or v2:
                guarda_en_memoria(cuad[3], True)
            else:
                guarda_en_memoria(cuad[3], False)

        elif op == dir.nott: #not
            v1 = lee_memoria(cuad[1])
            if v1:
                guarda_en_memoria(cuad[3], False)
            else:
                guarda_en_memoria(cuad[3], True)
            
        elif op == dir.printt: # print
            v1 = lee_memoria(cuad[1])
            if type(v1) == type([]):
                print lee_arreglo(v1)
            else:
                print v1
        
        elif op == dir.gotof: # gotof
            v1 = lee_memoria(cuad[1])
            if type(v1) == bool or type(v1) == int:
                if v1 == False or v1 == 0:
                    ieje = int(cuad[3])
            else:
                print "* " + str(type(v1)) + " No es valido."
        
        elif op == dir.gotov: # gotov
            v1 = lee_memoria(cuad[1])
            if type(v1) == bool or type(v1) == int:
                if v1 == True or v1 != 0:
                    ieje = int(cuad[3])
            else:
                print "* " + str(type(v1)) + " No es valido."        
        elif op == dir.goto: # goto
            ieje = int(cuad[3])

        elif op == dir.menorigualq: #menorigual que
            v1 = lee_memoria(cuad[1])
            v2 = lee_memoria(cuad[2])
            guarda_en_memoria(cuad[3], v1<=v2)

        elif op == dir.mayorigualq: #mayorigual que
            v1 = lee_memoria(cuad[1])
            v2 = lee_memoria(cuad[2])
            guarda_en_memoria(cuad[3], v1>=v2)

        elif op == dir.era: #era
            arrFun = Funciones()
        
        elif op == dir.gosub: # gosub
            arreglotemp.ieje = ieje
            stack.append(arreglotemp)
            ieje = cuad[1]
            arreglotemp = arrFun
        
        elif op == dir.ret: # ret
            arreglotemp = stack.pop()
            ieje = arreglotemp.ieje
            
        elif op == dir.param: # param
            v1 = lee_memoria(cuad[1])
            direccionP = cuad[3]
            arrFun.setParam(direccionP, v1, arreglotemp, memresto)

        elif op == dir.retorno: # return
            tipoRetorno = memglobal.tipoMem(cuad[1])
            v1 = lee_memoria(cuad[1])
            arreglotemp = stack.pop()
        
            if tipoRetorno == type(v1):
                arreglotemp.valor = v1
            else:
                print "* " + str(type(v1)) + "no es un tipo correcto, se espera el tipo", tipoRetorno, "."   
            ieje = arreglotemp.ieje
            
        elif op == dir.scan: #scan
            v1 = memglobal.tipoMem(cuad[3])(raw_input("-"))
            if type(v1) == memglobal.tipoMem(cuad[3]):
                guarda_en_memoria(cuad[3], v1)
            else:
                print "* " + str(type(v1)) + ' no se puede asignar con un ' + str(memglobal.tipoMem(cuad[3]))    

        elif op == dir.verifica: #verifica
            v1 = lee_memoria(cuad[1])
            li = cuad[2]
            ls = cuad[3]
            if not(v1 >= li and v1 <= ls):
                print "* " + str(v1) + ' No esta dentro del limite ' + str(li) + ' - ' + str(ls)

        elif op == -1: #termina el programa
            break

        if auxCuad1 != None:
            cuad[1]=auxCuad1
            auxCuad1=None
        if auxCuad2 != None:
            cuad[2]=auxCuad2
            auxCuad2=None
        if auxCuad3 != None:
            cuad[3]=auxCuad3
            auxCuad3=None
예제 #27
0
파일: star_5.py 프로젝트: rainmo/rainm2py
    turtle.end_fill()
print(turtle.pos())

turtle.pu()
draw_square(-320, -260, 660, 440)
star_part_x = -320
star_part_y = -260 + 440
star_part_s = 660 / 30
center_x, center_y = star_part_x + star_part_s * 5, star_part_y - star_part_s * 5
turtle.setpos(center_x, center_y)  # big star center
turtle.lt(90)
draw_star(star_part_x + star_part_s * 5, star_part_y - star_part_s * 2, star_part_s * 3)

# draw 1st small star
turtle.goto(star_part_x + star_part_s * 10, star_part_y - star_part_s * 2)    # go to 1st small star center
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)

# draw 2nd small star
turtle.goto(star_part_x + star_part_s * 12, star_part_y - star_part_s * 4)    # go to 1st small star center
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)

# draw 3rd small star
turtle.goto(star_part_x + star_part_s * 12, star_part_y - star_part_s * 7)    # go to 1st small star center
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
예제 #28
0
파일: main.py 프로젝트: yuanli123/python
star_y = -260
len_x = 660
len_y = 440
draw_rectangle(star_x, star_y, len_x, len_y)
#draw the big star
pice = 660 / 30
big_center_x = star_x + 5 * pice
big_center_y = star_y + len_y - pice * 5
t.goto(big_center_x, big_center_y)
t.left(90)
t.forward(pice * 3)
t.right(90)
draw_star(t.xcor(), t.ycor(), pice * 3)
#draw the small star
t.goto(star_x + 10 * pice, star_y + len_y - pice * 2)
t.left(t.towards(big_center_x, big_center_y) - t.heading())
t.forward(pice)
t.right(90)
draw_star(t.xcor(), t.ycor(), pice)
#draw the second star
t.goto(star_x + pice * 12, star_y + len_y - pice * 4)
t.left(t.towards(big_center_x, big_center_y) - t.heading())
t.forward(pice)
t.right(90)
draw_star(t.xcor(), t.ycor(), pice)
#draw the third
t.goto(star_x + pice * 12, star_y + len_y - 7 * pice)
t.left(t.towards(big_center_x, big_center_y) - t.heading())
t.forward(pice)
t.right(90)
draw_star(t.xcor(), t.ycor(), pice)
예제 #29
0
__author__ = 'coderdojo'
import turtle
distance = 0
while turtle.distance(0,0) < 100:
    turtle.setheading(turtle.towards(0,0))
    turtle.forward(50)
turtle.exitonclick()
예제 #30
0
 def heading(self):
     dx = self.dirx
     dy = self.diry
     return turtle.towards(self.x + dx, self.y + dy)
예제 #31
0
#backgroud
turtle.pu()
draw_square(-300, -200, 600, 400)
ss_x = -300
ss_y = -200 + 400
ss_s = 600 / 30
s_x, s_y = ss_x + ss_s * 5, ss_y - ss_s * 5
turtle.setpos(s_x, s_y)
#big star
turtle.lt(90)
draw_star(ss_x + ss_s * 5, ss_y - ss_s * 2, ss_s * 3)

#small star1
turtle.goto(ss_x + ss_s * 10, ss_y - ss_s * 2)
turtle.lt(round(turtle.towards(s_x, s_y)) - turtle.heading())
turtle.fd(ss_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), ss_s)

#small star2
turtle.goto(ss_x + ss_s * 12, ss_y - ss_s * 4)
turtle.lt(round(turtle.towards(s_x, s_y)) - turtle.heading())
turtle.fd(ss_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), ss_s)

#small star3
turtle.goto(ss_x + ss_s * 12, ss_y - ss_s * 7)
turtle.lt(round(turtle.towards(s_x, s_y)) - turtle.heading())
turtle.fd(ss_s)
예제 #32
0
def triangulo(simbolos,identificador,linea):
  
  p1= obtener_punto(1,identificador,simbolos)
  p2= obtener_punto(2,identificador,simbolos)
  p3= obtener_punto(3,identificador,simbolos)

  x1 = obtener_x(p1,simbolos)
  y1 = obtener_y(p1,simbolos)
  x2 = obtener_x(p2,simbolos)
  y2 = obtener_y(p2,simbolos)
  x3 = obtener_x(p3,simbolos)
  y3 = obtener_y(p3,simbolos)

  tx = obtener_tx(identificador, simbolos,linea)
  ty = obtener_ty(identificador, simbolos,linea)
  
  borde = obtener_color(obtener_borde(identificador,simbolos,linea))
  relleno = obtener_color(obtener_relleno(identificador,simbolos,linea))

  #Trasladar triangulo
  x1 = x1*44 + tx*44
  y1 = y1*44 + ty*44  
  x2 = x2*44 + tx*44
  y2 = y2*44 + ty*44
  x3 = x3*44 + tx*44
  y3 = y3*44 + ty*44

  #Calculos de lados
  a =  math.sqrt(((x2 -x1)**2)+((y2-y1)**2)) #Opuesto de p3
  b =  math.sqrt(((x3 -x1)**2)+((y3-y1)**2)) #Opuesto de p2
  c =  math.sqrt(((x3 -x2)**2)+((y3-y2)**2)) #Opuesto de p1

  #Calculo de incentro
  incentro_x = (( (x1*c) + (x2*b) + (x3*a) ) / (a+b+c) )
  incentro_y = (( (y1*c) + (y2*b) + (y3*a) ) / (a+b+c) ) 

  #Calculo de distancias
  d1 = math.sqrt(((incentro_x -x1)**2)+((incentro_y-y1)**2))
  d2 = math.sqrt(((incentro_x -x2)**2)+((incentro_y-y2)**2))
  d3 = math.sqrt(((incentro_x -x3)**2)+((incentro_y-y3)**2))

  #Calculo de angulos
  turtle.penup()  
  turtle.setposition(incentro_x, incentro_y)
  a1 = turtle.towards(x1,y1)
  a2 = turtle.towards(x2,y2)
  a3 = turtle.towards(x3,y3)

  escalar = obtener_escalar(identificador, simbolos,linea)
  #Calcular nuevos puntos para escalar
  if escalar != 0:
    turtle.setposition(incentro_x, incentro_y)
    turtle.setheading(0)
    turtle.lt(a1)
    turtle.forward(d1*escalar)
    x1 = turtle.xcor()
    y1 = turtle.ycor()

    turtle.setposition(incentro_x, incentro_y)
    turtle.setheading(0)
    turtle.lt(a2)
    turtle.forward(d2*escalar)
    x2 = turtle.xcor()
    y2 = turtle.ycor()
   
    turtle.setposition(incentro_x, incentro_y)
    turtle.setheading(0)
    turtle.lt(a3)
    turtle.forward(d3*escalar)
    x3 = turtle.xcor()
    y3 = turtle.ycor()

  rotar = obtener_rotar(identificador, simbolos,linea)
  if rotar != 0: 
    #Calcular nuevos puntos para rotar
    turtle.setposition(incentro_x, incentro_y)
    turtle.setheading(0)
    turtle.lt(a1+rotar)
    turtle.forward(d1)
    x1 = turtle.xcor()
    y1 = turtle.ycor()

    turtle.setposition(incentro_x, incentro_y)
    turtle.setheading(0)
    turtle.lt(a2+rotar)
    turtle.forward(d2)
    x2 = turtle.xcor()
    y2 = turtle.ycor()
   
    turtle.setposition(incentro_x, incentro_y)
    turtle.setheading(0)
    turtle.lt(a3+rotar)
    turtle.forward(d3)
    x3 = turtle.xcor()
    y3 = turtle.ycor()

  #Dibujar triangulo
  turtle.penup()
  turtle.setposition(x1,y1)
  turtle.pendown()
  turtle.color(borde)
  turtle.fillcolor(relleno)
  turtle.begin_fill()
  turtle.pensize(8)
  turtle.setposition(x2,y2)
  turtle.setposition(x3,y3)
  turtle.setposition(x1,y1)
  turtle.end_fill()
예제 #33
0

def dist(x, y):
    return turtle.distance(x, y)


def toward(x, y):
    return turtle.towoards(x, y)


turtle = turtle.Turtle()

turtle.shape('turtle')
turtle.speed(1)
# 태극 원
a = turtle.towards(300, -200)
turtle.right(-a)
turtle.forward(100)
# move(100,0)

turtle.pensize(3)
turtle.color('red')
turtle.begin_fill()
turtle.left(90)
turtle.circle(100, 180)
turtle.end_fill()
turtle.color('blue')
turtle.begin_fill()

turtle.circle(100, 180)
turtle.end_fill()
예제 #34
0
star_y = -260
len_x = 660
len_y = 440
draw_rectangle(star_x, star_y, len_x, len_y)
#draw the big star
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)
#draw the small star
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)
#draw the second star
turtle.goto(star_x + pice * 12, star_y + len_y - pice * 4)
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)
#draw the third
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)
예제 #35
0
# draw star of David
import turtle
import math

turtle.penup()
turtle.seth(30)
vertex = []
for i in range(6):
    turtle.fd(200)
    vertex.append(turtle.pos())
    turtle.left(60)
print(vertex)

len_of_side = math.sqrt((vertex[0][0] - vertex[2][0])**2 +
                        (vertex[0][1] - vertex[2][1])**2)

turtle.goto(vertex[4])
turtle.pendown()
for x in range(0, 6, 2):
    turtle.seth(turtle.towards(vertex[x]))
    turtle.fd(len_of_side)

turtle.penup()
turtle.goto(vertex[5])
turtle.pendown()
for x in range(1, 6, 2):
    turtle.seth(turtle.towards(vertex[x]))
    turtle.fd(len_of_side)

turtle.done()
예제 #36
0
파일: engine.py 프로젝트: ZeGmX/Projet_jeu
    def heading(self):
        '''
		Returns the direction the object should be facing.  By
		default, this is towards where the object will be moving.
		'''
        return turtle.towards(self.x + self.deltax, self.y + self.deltay)
SPEED = 5
print(xbox.get_name())
while True:
    try:
        pygame.event.get()

        # Get the locations of the joystick
        ax0 = xbox.get_axis(0)
        ax1 = -xbox.get_axis(1)

        # Use these locations to power the turtle
        pos = turtle.pos()
        mov = turtle.Vec2D(ax0, ax1)

        # Combine the movement with our position
        new_pos = pos + SPEED * mov

        if ax0 != 0 and ax1 != 0:
            # print(f"Heading: {turtle.heading()}")
            # print(f"Angle Between: {angle_between}")
            angle = turtle.towards(new_pos)
            turtle.setheading(angle)

        turtle.setpos(new_pos)
        clock.tick(20)
    except KeyboardInterrupt:
        break

pygame.quit()
예제 #38
0
import turtle

turtle = turtle.Turtle()

# turtle. towards(x, y=None)
# x – a number or a pair/vector of numbers or a turtle instance
# y – a number if x is a number, else None
# Return the angle between the line from turtle position to position specified by (x,y),the vector or the other turtle
# This depends on the turtle’s start orientation which depends on the mode - “standard”/”world” or “logo”).

turtle.goto(10, 10)
print(turtle.towards(0,0))
예제 #39
0
def play():
    global score
    global playing

    angle = villain.towards(t.pos())
    villain.setheading(angle)

    speed = (score / 10 + 3)
    if speed > 15:
        speed = 15
    villain.penup()
    villain.forward(speed)
    villain.pendown()
    t.forward(5 + (speed * 0.7))

    #player거북이와 villain거북이가 만나면 game over
    if t.distance(villain) < 20:
        text = "SCORE:" + str(score)
        title("GAME OVER", text, "REGAME: press space")
        playing = False
        score = 0
        crush.play()

#player 거북이가 벽에 닿으면 반대 방향으로 전진
    x = t.xcor()
    y = t.ycor()
    if x >= 390 or x <= -390 or y >= 290 or y <= -290:  #(x는 WIDTH/2-10, y는 HEIGHT/2-10이 안되게 )
        angle2 = t.towards(-t.pos())
        t.setheading(angle2)

#점수는 random
    movex = random.randint(-230, 230)
    movey = random.randint(-230, 230)
    random_s = [10, 40, 30, 20, 50, 100, -10, -30]
    if t.distance(food) < 12:
        score = score + random.choice(random_s)
        food.penup()
        food.goto(movex, movey)
        food.pendown()
        scorestring = "SCORE: " + str(score)
        scorepen.clear()
        scorepen.write(scorestring, False, "left", font=("Bold", 15, "bold"))
        eatfood.play()
    if t.distance(food2) < 12:
        score = score + random.choice(random_s)
        movex = random.randint(-230, 230)
        movey = random.randint(-230, 230)
        food2.penup()
        food2.goto(movex, movey)
        food2.pendown()
        scorestring = "SCORE: " + str(score)
        scorepen.clear()
        scorepen.write(scorestring, False, "left", font=("Bold", 15, "bold"))
        eatfood.play()
    if t.distance(food3) < 12:
        score = score + random.choice(random_s)
        movex = random.randint(-230, 230)
        movey = random.randint(-230, 230)
        food3.penup()
        food3.goto(movex, movey)
        food3.pendown()
        scorestring = "SCORE: " + str(score)
        scorepen.clear()
        scorepen.write(scorestring, False, "left", font=("Bold", 15, "bold"))
        eatfood.play()
    if t.distance(food5) < 12:
        score = score + random.choice(random_s)
        movex = random.randint(-230, 230)
        movey = random.randint(-230, 230)
        food5.penup()
        food5.goto(movex, movey)
        food5.pendown()
        scorestring = "SCORE: " + str(score)
        scorepen.clear()
        scorepen.write(scorestring, False, "left", font=("Bold", 15, "bold"))
        eatfood.play()


# player가 작동시키지 않아도 게임이 시작하면 거북이는 움직인다
    if playing:
        t.ontimer(play, 100)