Example #1
0
def play():           # 게임을 실제로 플레이 하는 함수.
    global score
    global playing
    t.forward(10)       # 주인공 거북이 10만큼 앞으로 이동합니다.
    if random.randint(1, 5) == 3: # 1~5사이에서 뽑은 수가 3이면(20%확률)
        ang = te.towards(t.pos())
        te.sethading(ang)        # 악당 거북이가 주인공 거북이를 바라봅니다
    speed = score + 5            # 점수에 5를 더해서 속도를 올립니다.
                                 # 점수가 올라가면 빨라집니다.
                                 
    if speed > 15:               # 속도가 15를 넘지는 않도록 합니다
        speed = 15
    te.forward(speed)
    
    if t.distance(te) < 12:      # 주인공과 악당의 거리가 12보다 작으면
                                 # 게임을 종료합니다.  
        
        text = "Score : " + str(score)
        message("Game Over", text)
        playing = False
        score = 0
    
    
    if t.distance(ts) < 12:      # 주인공과 먹이의 거리가 12보다 작으면(가까우면)
        score = score + 1        # 점수를 올립니다.
        t.write(score)           # 점수를 화면에 표시합니다.
        star_x = random.randint(-230, 230)
        star_y = random.randint(-230, 230)
        ts.goto(star_x, star_y)  # 먹이를 다른 곳으로 옮깁니다.
        
    if playing:
        t.ontimer(play, 100)     # 게임 플레이 중이면 0.1초후
Example #2
0
def draw_spiral(radius):
    original_xcor = t.xcor()
    original_ycor = t.ycor()
    speed = 1
    while True:
        t.forward(speed)
        t.left(10)
        speed += 0.1
        if t.distance(original_xcor, original_ycor) > radius:
            break
Example #3
0
def spiral(radius):
    xcor = turtle.xcor()
    ycor = turtle.ycor()
    speed = 1
    while True:
        turtle.forward(speed)
        turtle.left(10)
        speed += 1 * 0.01
        if turtle.distance(xcor, ycor) > radius:
            break
Example #4
0
 def runhalfway():
     randvert = random.choice(vertices)
     whole = turtle.distance(randvert)
     half = whole/2
     t.setheading(randvert)
     t.pencolor('#FFFFFE')
     t.forward(half)
     t.pencolor('#000000')
     t.dot()
     t.pencolor('#FFFFFE')
Example #5
0
def moveTurtle(radius):
    while True:
        global speed
        screen.onkey(speedUp, "Up")
        screen.onkey(speedDown, "Down")
        screen.onkey(addTurtle, "space")
        screen.listen()
        for turtle in screen.turtles():
            if turtle.distance(0,0) > radius:
                turtle.forward(-(speed*2))
                turtle.setheading(random.randrange(0,360,10))
            else :
                turtle.forward(speed)
Example #6
0
def fire():
    ang = t.heading()
    while t.ycor() > 0:
        t.forward(15)
        t.right(5)

    d = t.distance(target, 0)
    t.sety(random.randint(10, 100))

    if d < 25:
        t.color("blue")
        t.write("성공", False, "center", ("", 15))
    else:
        t.color("red")
        t.write("실패", False, "center", ("", 15))
    t.color("black")
    t.goto(-200, 10)
    t.setheading(ang)
def fire():  # [스페이스]키를 누르면 거북이 대포를 발사합니다.
    ang = t.heading()  # 현재 거북이가 바라보는 각도를 기억합니다.
    while t.ycor() > 0:  # 거북이가 땅 위에 있는 동안 반복합니다.
        t.forward(15)  # 15만큼 앞으로 이동합니다.
        t.right(5)  # 오른쪽으로 5도 회전합니다.

    # while 반복문을 빠져나오면 거북이가 땅에 닿은 상태입니다.
    d = t.distance(target, 0)  # 거북이와 목표 지점과의 거리를 구합니다.
    t.sety(random.randint(10, 100))  # 성공 또는 실패 메시지를 표시할 위치를 지정합니다.
    if d < 25:  # 거리 차이가 25보다 작으면 목표 지점에 명중한 것으로 처리합니다.
        t.color("blue")
        t.write("Good!", False, "center", ("", 15))
    else:  # 그렇지 않으면 실패한 것으로 처리합니다.
        t.color("red")
        t.write("Bad!", False, "center", ("", 15))
    t.color("black")  # 거북이 색상을 검은색으로 되돌립니다.
    t.goto(-200, 10)  # 거북이 위치를 처음 발사했던 곳으로 되돌립니다.
    t.setheading(ang)  # 각도도 처음 기억해둔 각도로 되돌립니다.
Example #8
0
def fire():  # space를 누르면 거북이 대포를 발사
    ang = t.heading()  # 현재 거북이가 바라보는 각도를 기억함
    while t.ycor() > 0:  # 거북이가 땅위에 있는동안 반복
        t.forward(15)  # 15만큼 전진
        t.right(5)

    # while 반복문을 빠져나오면 거북이가 땅에 닿은 상태
    d = t.distance(target, 0)  # 거북이와 목표 지점과의 거리를 구함
    t.sety(random.randint(10, 100))  # 성공 또는 실패를 표시할 위치를 지정
    if d < 25:  # 거리 차이가 25보다 작으면 목표 지점에 명중한 것으로 처리
        t.color("blue")
        t.write("Good!", False, "center", ("", 15))
    else:  # 그렇지 않으면 실패한 것으로 처리
        t.color("red")
        t.write("Bad!", False, "center", ("", 15))
        t.color("black")  # 거북이 색을 검은색으로 되돌림
        t.goto(-200, 10)  # 거북이 위치를 처음 발사했던 곳으로 되돌림
        t.setheading(ang)  # 각도도 처음 기억해 둔 각도로 되돌림
def shoot():
    ang=t.heading() #the angle will be determined by the user after adjusted by up/down keys
    while t.ycor()>0: #this function will go on while it's above the ground y=0
        t.forward(15) #keep moving by distance 15
        t.right(5) #keep turning by 5 degrees

    #warning : we're still in the middle of function shoot()

    d=t.distance(target,0) #calculating the distance between t and the target
    t.sety(random.randint(10,100))
    if d<25: #when the distance <25, it will be considered as success
        t.color("blue")
        t.write("Good",False,"center",("Courier",15))
    else:
        t.color("red")
        t.write("Bad",False,"center",("Courier",15))
    t.color("black") #return back to black colour
    t.goto(-200,10) #let turtle go back to the original position
    t.setheading(ang) #let turtle set back to the original angle
def fire():  # space bar를 누르면 거북이 대포 발사
    ang = t.heading()  # 현재 거북이가 바라보는 각도를 기억합니다.
    while t.ycor() > 0:
        t.fd(15)
        t.rt(5)

    # while 반복문을 빠져나오면 거북이가 땅에 닿은 상태입니다.
    d = t.distance(target, 0)  # 거북이와 목표지점과의 거리구하기
    t.sety(random.randint(10, 100))  # 성공 실패를 표시할 위치 정하기
    if d < 10:  # 목표지점과의 차이가 10미만이면 명중으로 처리
        t.color("blue")
        t.write("Good", False, "center", ("", 15))
    else:
        t.color("red")
        t.write("Bad", False, "center", ("", 15))

    t.color("black")
    t.goto(-200, 10)  # 거북이 위치를 처음으로 되돌림
    t.setheading(ang)  # 각도도 처음의 각도로 원위치
Example #11
0
def fire(): #발사
    ang = t.heading() #각도 기억
    while t.ycor() > 0: # 거북이 땅위에 있는동안 반복
        t.forward(15)
        t.right(5)

    # while문이 끝나면 거북이는 땅
    d = t.distance(target, 0) #목표 지점과 거리
    t.sety(random.randint(10, 100)) #성공 실패 표시할 위치 지정

    if d < 25: #거리 차이가 25미만 명중
        t.color("blue")
        t.write("Good!",False,"center",("",15))
    else: #아니면 실패
        t.color("red")
        t.write("Bad!",False,"center",("",15))
    t.color("black") #거북이 색 검정색으로 되돌리기
    t.goto(-200, 10) #거북이 위치 처음 발사 했던 곳으로 되돌리기
    t.setheading(ang) #각도가 처음 기억해둔 각도로 되돌리기
def fire():
    ang=t.heading()
    while t.ycor()>0:
        t.forward(15)
        t.right(5)
    d=t.distance(target,0)#터틀과 타겟과의 거리
    t.color("red")
    
    t.sety(r.randint(100,200)) #성공 또는 실패를 표시할 위치
    if d<25:
        t.color("black")
            t.write("G00D!",False,"center",("",50))
        else:
        t.color("red")
        t.write("BAD!",False,"center",("",50))

    t.color("black")
    t.goto(-200,10)
    t.setheading(ang)
Example #13
0
def fire(turtle_pos_x, turtle_pos_y):  # SpaceBar를 누르면 거북이 대포를 발사합니다.
    while t.xcor() <= cannon_range:  # 거북이가 땅 위에 있는 동안 반복합니다.
        t.setpos(turtle_pos_x, turtle_pos_y)
        turtle_pos_x += 1
        turtle_pos_y = calculate_pos_y(turtle_pos_x, cannon_range)

    # while 반복문을 빠져나오면 거북이가 땅에 닿은 상태입니다.
    d = t.distance(target, 0)  # 거북이와 목표 지점과의 거리를 구합니다.
    t.sety(random.randint(10, 100))  # 성공 또는 실패를 표시할 위치를 지정합니다.
    if d < 25:  # 거리 차이가 25보다 작으면 목표 지점에 명중한 것으로 처리합니다.
        t.color("blue")
        t.write("Good!", False, "center", ("", 15))

    else:  # 그렇지 않으면 실패한 것으로 처리합니다.
        t.color("red")
        t.write("Bad!", False, "center", ("", 15))

    t.color("black")  # 거북이 색을 검은색으로 되돌립니다.
    t.goto(-200, 10)  # 거북이 위치를 처음 발사했던 곳으로 되돌립니다.
def fire():  #대포를 발사하는 함수
    ang = t.heading()
    while t.ycor() > 0:  #turtle의 y 좌표가 0을 넘으면 계속 반복
        t.forward(15)
        t.right(5)

    d = t.distance(target, 0)  #turtle과 (target, 0)사이의 거리를 구함
    t.sety(random.randint(10, 100))  #성공, 실패 글자를 띄울 y좌표값을 정함

    if d < 25:  #turtle과 (target,0) 의 거리가 25보다 작을 때
        t.color("blue")
        t.write("Success!", False, "center", ("", 15))
    else:
        t.color("red")  #turtle과 (target,0)의 거리가 25보다 클 때
        t.write("Fail", False, "center", ("", 15))

    t.color("black")
    t.goto(-200, 10)  #시작점으로 다시 돌아감
    t.setheading(ang)  #시작할 때 각도로 다시 돌려놓음.
Example #15
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
Example #16
0
def fire():
    ang = t.heading()   #현재 바라보는 각도를 구해서 변수에 저장
    while t.ycor() > 0: #거북이가 땅 위에 있는동안 반복
        t.forward(15)
        t.right(5)

    #while 반복문을 빠져나오면 거북이가 땅에 닿은 상태
    d = t.distance(target, 0)
    #성공 또는 실패를 표시할 위치
    t.sety(random.randint(10,100))
    if d < 25:
        t.color("blue")
        t.write("Good!", False, "center", ("", 15))
    else:
        t.color("red")
        t.write("Bad!", False, "center", ("", 15))
    #거북이 원위치
    t.color("black")
    t.goto(-200, 10)
    t.setheading(ang)
Example #17
0
def ss():
    turtle.pendown()
    circleheading = 0
    circleincrementer = random.randrange(30, 50)
    circlestep = 360 / circleincrementer
    turtle.showturtle()
    turtle.penup()
    tilemaker = random.randrange(2, 8)
    for sss in range(0, circleincrementer):
        turtle.tracer(0, 0)
        circleheading = circleheading + circlestep
        turtle.setheading(circleheading)
        turtle.forward(circleincrementer * 8)
        turtle.pendown()
        turtle.circle(turtle.distance(0, 0) * .02, 360, tilemaker)
        for ttt in range(1, 10):
            turtle.forward(random.randrange(-10, 10))
            forcemultiplier()
            turtle.penup()
            turtle.home()
Example #18
0
def launch() :
	#1. 포물선 생성-땅에 닿을 때까지 돌진 2. 타깃이랑 거북이 거리 차이 확인 3. 태초마을
	#타겟은 랜덤으로 50-150
	angle = t.heading()
	
	while t.ycor() > 0 :
		t.fd(20)
		t.right(5)
	
	dis = t.distance(target, 0)
	t.sety(r.randint(10, 100))
	if dis <= 25 :
		t.pencolor('blue')
		t.write('Bingo!!!!!!!!!!!!!', False, "center", ("",15))
		t.pencolor('black')
	else :
		t.pencolor('red')
		t.write('Daaaammmmmmmmmmm!!!!!!!', False, "center", ("", 15))
		t.pencolor('black')
	t.goto(-200,10)
	t.setheading(angle)
Example #19
0
def fire():  #스페이스누르면 발사
    a = t.heading()  #거북이가 바라보는 각도 저장
    while t.ycor() > 0:  #거북이의 y좌표 ycor
        t.forward(15)
        t.rt(1)

    #while 이 빠지면 스탑

    d = t.distance(ta, 0)  #거북이와 목표지점과의 거리
    t.sety(r.randint(300, 400))  #글자표시 영역

    if d <= 714 and d >= 696:
        t.color("blue")
        t.write("good", False, "center", ("", 15))
    else:
        t.color("red")
        t.write("bed", False, "center", ("", 15))

    t.goto(-900, 10)
    t.color("black")
    t.setheading(a)
Example #20
0
def go ():
	ang=t.heading()
	#포물선 날아가기
	while t.ycor()>0:
		t.fd(15)
		t.right(5)
	
	d=t.distance(target,0)
	t.sety(r.randint(10,100))
	#타겟에 닿으면 굿 아니면 배드
	if d <= 25:
		t.pencolor('green')
		t.write("Good!",False,"center",("",15))
		t.pencolor('black')
	else:
		t.pencolor('red')
		t.write("Bad!",False,"center",("",15))
		t.pencolor('black')
		
				
	t.goto(-200,10)
	t.setheading(ang)
Example #21
0
def shot () : 
	# 거북이 포물선으로 발사 후 땅에 닿을 때까지 반복
	ang= t.heading()
	while t.ycor()> 0 :
		t.fd (15)
		t.right (5)
		
	# 타겟과 거북이 거리 차이 확인 후 문구 띄우기	
	d = t.distance(target,0)
	t.sety(random.randint(10,100))
	if d <= 25 :
		t.color('blue')
		t.write("Great",False,"center",("",15))
		
	else :
		t.color('red')
		t.write("Bad",False,"center",("",15))
		
	# 거북이 다시 돌아가기
	t.goto(-200,10)
	t.setheading(ang)
	t.color('black')
Example #22
0
def fire():
    ang = t.heading()  # 현재 거북이가 바라보는 각도를 기억
    while t.ycor() > 0:  # 거북이가 땅 위에 있는 동안 반복
        t.forward(15)
        t.right(5)  # while 반복문을 빠져나오면 거북이는 땅에 도착

    d = t.distance(target, 0)  # 거북이와 목표지점 사이의 거리는?
    t.sety(random.randint(10, 100))  # 성공/실패를 표시할 위치 지정
    if d < 25:  # 거리 차이 < 25 : 명중으로 처리
        t.color("blue")
        t.write("Good!", False, "center", ("", 15))

        t.write("새로운 게임을 시작합니다.", False, "Center", ("", 15))
        t.reset()

        t.goto(-300, 0)
        t.down()
        t.goto(300, 0)

        target = random.randint(50, 150)
        t.pensize(3)
        t.color("green")
        t.up()
        t.goto(target - 25, 2)
        t.down()
        t.goto(target + 25, 2)

        t.color("black")
        t.up()
        t.goto(-200, 10)
        t.settheading(20)

    else:  # 명중이 아니라면?
        t.color("red")
        t.write("Bad!", False, "center", ("", 15))
        t.color("black")
        t.goto(-200, 10)  # 처음 발사했던 곳으로 거북이 원 위치
        t.setheading(ang)  # 거북이 각도도 원상 복구
Example #23
0
def fire():
    ang = t.heading()  # 현재 거북이가 바라보는 각도를 기억합니다.
    while t.ycor() > 0:  # 거북이가 땅 위에 있는 동안 반복합니다.
        t.fd(15)  # 15만큼 전진
        t.right(5)  # 5도만큼 회전

    #while 반복문을 빠져나오면 거북이가 땅에 닿은 상태입니다.

    d = t.distance(target, 0)  #거북이와 목표 지점과의 거리를 구합니다.
    t.sety(random.randint(10, 100))  #성공 또는 실패를 표시할 위치를 지정합니다.

    if d < 25:  #거리 차이가 25보다 작으면 목표 지점에 명중한 것으로 처리
        t.color("blue")
        t.write("Good!", False, "center", ("", 15))
        t.color("black")
        t.goto(-200, 10)  # 거북이 위치를 처음 발사했던 곳으로 되돌립니다.
        t.setheading(0)
    else:
        t.color("red")
        t.write("Bad!", False, "center", ("", 15))
        t.color("black")  # 거북이 색을 검은색으로 되돌립니다.
        t.goto(-200, 10)  # 거북이 위치를 처음 발사했던 곳으로 되돌립니다.
        t.setheading(ang)  # 각도도 처음 기억해 둔 각도로 되돌립니다.
Example #24
0
def play():
    global lastPosition
    global itemExists
    global scoreCount
    while(flag):
        currentLocation = Point((t.xcor(), t.ycor()))
        for l in loc:
            if(l.onLine(currentLocation)):
                gameover()

    
        if(not itemExists):
            genSquare()
        if(t.distance(gen) < 15):
            gen.ht()
            score.clear()
            scoreCount += 1
            score.write("Score: %d" % scoreCount, font=("Helvetica",18))
            itemExists = False
        if(t.xcor() >= 350 or t.xcor() <= -355 or t.ycor() >= 290 or t.ycor() <= -333):
            hitWall()
        t.fd(3)
        movedLocation = Point((t.xcor(), t.ycor()))

        for l in loc:
            if(t.heading() == 90):
                if(l.intersect(Line(movedLocation, Point((t.xcor(), movedLocation.y - 2.9))))):
                    gameover()
            elif(t.heading() == 270):
                if(l.intersect(Line(movedLocation, Point((t.xcor(), movedLocation.y + 2.9))))):
                    gameover()
            elif(t.heading() == 180):
                if(l.intersect(Line(movedLocation, Point((movedLocation.x - 2.9, t.ycor()))))):
                    gameover()
            else:
                if(l.intersect(Line(movedLocation, Point((movedLocation.x + 2.9, t.ycor()))))):
                    gameover()
Example #25
0
def play():
    global lastPosition
    global itemExists
    global scoreCount
    while(flag):
        coords = [t.xcor(), t.ycor()]
        coordx1 = [t.xcor()-1, t.ycor()]
        coordx2 = [t.xcor()-2, t.ycor()]
        
        if coords in loc or coordx1 in loc or coordx2 in loc:
            gameover()
    
        loc.append(coords)
        if(not itemExists):
            genSquare()
        if(t.distance(gen) < 15):
            gen.ht()
            score.clear()
            scoreCount += 1
            score.write("Score: %d" % scoreCount, font=("Helvetica",18))
            itemExists = False
        if(t.xcor() >= 350 or t.xcor() <= -355 or t.ycor() >= 290 or t.ycor() <= -333):
            hitWall()
        t.fd(3)
Example #26
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()
Example #27
0
def fire():
  ang = t.heading()
  while t.ycor()>0:
    t.forward(15)
    t. right(5)

  d = t.distance(target,0)
  t.sety(random.randint(10, 100))
  if d < 15:
    def gogo():
      t.goto(-200,10)
      t.ontimer(t.color("green") | t.write("Perfect!" , False, "center" | ("", 15)), 3/1000)
      t.setheading(ang)


  elif d < 25:
    t.color("blue")
    t.write("Great!", False, "center", ("", 15))
    t.goto(-200,10)
    t.ontimer(clear, 3/1000)
    t.setheading(ang)


  elif d < 40:
    t.color("purple")
    t.write(ontimer "Good!", False, "center", ("", 15))
    t.goto(-200,10)
    t.ontimer(clear, 3/1000)
    t.setheading(ang)

  else:
    t.color("red")
    t.write("Bad!", False, "center", ("", 15))
    t.goto(-200,10)
    t.ontimer(clear, 3/1000)
    t.setheading(ang)
Example #28
0
        t.left(360 / n)


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)
Example #29
0
def draw_art():
    window = turtle.Screen()
    window.bgcolor ("cyan")
    turtle.position()
    (0.00,0.00)
    turtle.home()
    ##Draw first Rosace (a and b)
    #Create the turtle a - Draws a circle from squares
    a = turtle.Turtle()
    a.shape("circle")
    a.color("white")
    a.speed(8)
    for i in range (1,25):
        draw_square(a)
        a.right(15)
    #change colors
    a.color("cyan")
    window.bgcolor ("white")
    #Create the turtle b
    b = turtle.Turtle()
    b.shape("circle")
    b.color("aquamarine")
    b.speed(8)
    for i in range (1,13):
        draw_circle(b)
        b.right(30)
    #change colors back
    window.bgcolor ("cyan")
    a.color("white")
    b.color("fuchsia")
    ##Second Rosace on the right (d and e)
    #Create turtle d
    d = turtle.Turtle()
    d.shape("circle")
    d.color("white")
    d.speed(8)
    d.goto(240,-250)
    turtle.distance(d)
    240.0
    for i in range (1,25):
        draw_square(d)
        d.right(15)
    #Create turtle e
    e = turtle.Turtle()
    e.shape("circle")
    e.color("fuchsia")
    e.speed(8)
    e.goto(240,-250)
    turtle.distance(e)
    240.0
    for i in range (1,13):
        draw_circle(e)
        e.right(30)
    ##Second Rosace on the right (d and e)
    #Create turtle d
    d = turtle.Turtle()
    d.shape("circle")
    d.color("white")
    d.speed(8)
    d.goto(240,250)
    turtle.distance(d)
    240.0
    for i in range (1,25):
        draw_square(d)
        d.right(15)
    #Create turtle e
    e = turtle.Turtle()
    e.shape("circle")
    e.color("fuchsia")
    e.speed(8)
    e.goto(240,250)
    turtle.distance(e)
    240.0
    for i in range (1,13):
        draw_circle(e)
        e.right(30)
    ##Third Rosace above(f and g)
    f = turtle.Turtle()
    f.shape("circle")
    f.speed(8)
    f.goto(-240,-250)
    turtle.distance(f)
    240.0
    f.color("white")
    for i in range (1,25):
        draw_square(f)
        f.right(15)
    g = turtle.Turtle()
    g.shape("circle")
    g.color("fuchsia")
    g.speed(8)
    g.goto(-240,-250)
    turtle.distance(g)
    240.0
    for i in range (1,13):
        draw_circle(g)
        g.right(30)
    ##Forth Rosace left(h and i)
    h = turtle.Turtle()
    h.shape("circle")
    h.color("white")
    h.speed(8)
    h.goto(-240,250)
    turtle.distance(h)
    240.0
    for i in range (1,25):
        draw_square(h)
        h.right(15)
    #Create turtle j
    j = turtle.Turtle()
    j.shape("circle")
    j.color("fuchsia")
    j.speed(8)
    j.goto(-240,250)
    turtle.distance(j)
    240.0
    for i in range (1,13):
        draw_circle(j)
        j.right(30)
    #change colors
    window.bgcolor("white")
    a.color("cyan")
    b.color("cyan")
    d.color("cyan")
    e.color("cyan")
    f.color("cyan")
    j.color("cyan")
    
    window.exitonclick()
Example #30
0
def updatescreen():

    """
        This function does:
            1. Decrease the width of the river
            2. Check if the player has hit the borders
            3. Move the enemies
            4. Check if the player has collided with an enemy
            5. Update the screen
            6. Schedule the next update
    """
    
    # Global variables that will be changed in the function
    global river_width

    # Part 4.2
    # Decrease the width of the river by river_width_update
    
    if river_width >= minimum_river_width:
        upper_river_border.sety(upper_river_border.ycor() - river_width_update)
        lower_river_border.sety(lower_river_border.ycor() + river_width_update)
        river_width = river_width - 2*river_width_update

    # until it reaches minimum_river_width
    # Part 4.3
    # 4.3.1 Check if the player has hit the borders
    # The vertical distance between the player's turtle and the 
    # borders must be large enough, otherwise the player loses
    # the game
    if  upper_river_border.ycor() - turtle.ycor() < safe_distance_from_border:
        gameover("You lose!")
        return
    if turtle.ycor() - lower_river_border.ycor() < safe_distance_from_border:
        gameover("You lose!")
        return
    # Part 5.2
    # Move the enemies
    # For every enemy in enemies
    
        # 5.2.1. Move the enemy to the right
        # 5.2.2. If the enemy moves out of the screen, move it 
        #    to the left hand side and generate its speed and 
        #    position randomly
    speed=random.randint(1,5)
    for i in range(number_of_enemies):
        enemies[i].forward(enemy_speeds[i])
        if enemies[i].xcor() > (window_width+enemy_width)/2:
            x= -int((window_width+enemy_width)/2)
            y= random.randint(int(-(river_width - enemy_height)/2), int(((river_width - enemy_height)/2)))
            enemies[i].goto(x,y)
            enemy_speeds[i]=(random.randint(enemy_speed_min,enemy_speed_max))

       
        # Part 5.3
        # Check collision
        if turtle.distance(enemies[i]) < safe_distance_from_enemy:
            gameover("Your turtle was eaten!")
            return
    # Part 3 (3-4 of 4)
    # 3.3. Update the screen
    turtle.update()
    # 3.4. Schedule an update in 'update_interval' milliseconds

    turtle.ontimer(updatescreen,update_interval)   
Example #31
0
    new_color = random.randint(1, 9)

    if new_color == 1:
        new_color = "red"
    elif new_color == 2:
        new_color = "orange"
    elif new_color == 3:
        new_color = "yellow"
    elif new_color == 4:
        new_color = "light green"
    elif new_color == 5:
        new_color = "green"
    elif new_color == 6:
        new_color = "violet"
    elif new_color == 7:
        new_color = "dark blue"
    elif new_color == 8:
        new_color = "purple"
    else:
        new_color = "black"

    turtle.forward(step)
    turtle.right(turn)

    if turtle.distance(0, 0) >= 200.0:
        turtle.up()
        turtle.home()
        turtle.color(new_color)
        turtle.down()
Example #32
0
turtle.setheading(30)
turtle.ht()

pointList = [origin] # add origin as first coordinate to list of points to be used to draw hexagram

turtle.pendown() 
turtle.fd(hexSide) # first line drawn before loop so that position != origin

atOrigin = False

while atOrigin == False: # obtain coordinates for points of hexagon
    pointList.append(turtle.pos())
    turtle.right(hexAngle)
    turtle.fd(hexSide)

    if turtle.distance(origin) < 1.0:
        atOrigin = True

print(pointList)

turtle.clear() # clear hexagon and prepare to draw unicursal hexagram
turtle.penup()
turtle.setpos(pointList[5])

turtle.pendown() # draw unicursal hexagram
turtle.goto(pointList[1])
turtle.goto(pointList[3])
turtle.goto(pointList[0])
turtle.goto(pointList[4])
turtle.goto(pointList[2])
turtle.goto(pointList[5])
Example #33
0
def turn_left():
    t.seth(180)

def play():
    t.fd(4)
    ang=te.towards(t.pos())
    te.seth(ang)
    te.fd(3)

    
t.onkeypress(turn_up,"Up")
t.onkeypress(turn_down,"Down")
t.onkeypress(turn_right,"Right")
t.onkeypress(turn_left,"Left")
t.listen()

s=0
while True:
    play()
    if t.distance(te)<20:
        print("잡혔다!")
        t.write("Game Over"+str(s)+"점",False,"center",("",20))
        while True==x:
            x=False
    if t.distance(ts)<20:
        s=s+1
        print("먹었다!")
        tsx=random.randint(-230,230)
        tsy=random.randint(-230,230)
        ts.goto(tsx,tsy)        
Example #34
0
__author__ = 'coderdojo'
import turtle
distance = 0
while turtle.distance(0,0) < 100:
    turtle.setheading(turtle.towards(0,0))
    turtle.forward(50)
turtle.exitonclick()
Example #35
0
def dist(x, y):
    return turtle.distance(x, y)
Example #36
0
>>> t.fd(30)
>>> t.goto(20.30)
Traceback (most recent call last):
  File "<pyshell#53>", line 1, in <module>
    t.goto(20.30)
  File "<string>", line 8, in goto
  File "C:\Users\PC-23\AppData\Local\Programs\Python\Python37\lib\turtle.py", line 1774, in goto
    self._goto(Vec2D(*x))
TypeError: type object argument after * must be an iterable, not float
>>> t.goto(300,300)
>>> t.setx(20)
>>> t.sety(30)
>>> t.circle(20)
>>> t.heading
<function heading at 0x00000169EA31DE18>
>>> t.distance(200.430)
Traceback (most recent call last):
  File "<pyshell#59>", line 1, in <module>
    t.distance(200.430)
  File "<string>", line 8, in distance
  File "C:\Users\PC-23\AppData\Local\Programs\Python\Python37\lib\turtle.py", line 1858, in distance
    return abs(pos - self._position)
UnboundLocalError: local variable 'pos' referenced before assignment
>>> t.distance(20.24)
Traceback (most recent call last):
  File "<pyshell#60>", line 1, in <module>
    t.distance(20.24)
  File "<string>", line 8, in distance
  File "C:\Users\PC-23\AppData\Local\Programs\Python\Python37\lib\turtle.py", line 1858, in distance
    return abs(pos - self._position)
UnboundLocalError: local variable 'pos' referenced before assignment
turtle.pendown()
turtle.circle(100)
turtle.penup()
turtle.goto(0,0)
turtle.pendown()


#repaets forever
while True:
    turtle.pensize(3)
    turtle.pencolor(rainbow.nextRainbowColor())    
    #turning random angle
    turtle.left(random.randint(-30,30))
    #turtle move 15 units in direction
    turtle.forward(10)
    if turtle.distance(0,0)>100:
        turtle.right(angle=180)
        turtle.forward(distance=10)
  
   
     









turtle.done()
Example #38
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")
Example #39
0
#!/usr/bin/python

import turtle

line_size = 6
angle = 45;

while True:
	turtle.forward(line_size)
	line_size += 3
	turtle.left(angle)
	turtle.width( int( line_size/8 ) )

	if turtle.distance(0,0) > 200:
		break
	

turtle.exitonclick()
ym=random.randrange(0, 270)
turtle.goto(xm, ym)
turtle.pd()
turtle.circle(30, 360)

#Mit der Variablen anzahl zählen wir die benötigten Markierungen
#Lege ihren Startwert fest
anzahl=1

#Die Turtle wird in den Ursprung gesetzt
turtle.pu()
turtle.goto(0, 0)
turtle.pd()

#Unter abstand speicherst du den Abstand zwischen M und der Turtle
abstand=turtle.distance(xm, ym)

#Es wird entschieden, ob die Turtle im Zielkreis ist
#Die Turtle wird zufällig im Gehege platziert
#Der neue Abstand zum Kreismittelpunkt wird ermittelt
#Sie verrichtet ihr Geschäft der Grösse 10
#Die Zufallspositionen werden gezählt
while(abstand>30):
    turtle.pu()
    turtle.goto(random.randrange(0, 300), random.randrange(0, 300))
    turtle.pd()
    abstand=turtle.distance(xm, ym)
    print(abstand)
    turtle.color(0.7,0.4,0.1)
    turtle.circle(10, 360)
    turtle.color(0,0,0)
Example #41
0
import turtle
import random

radius = random.randint(100,300)
x = turtle.xcor()
y = turtle.ycor()
speed = 2
while True:
    turtle.forward(speed)
    turtle.right(10)
    speed += 0.05
    if turtle.distance(x, y) > radius:
        break
input()        
Example #42
0
import turtle,random

turtle.tracer(100)
total=0
inside=0

print "Hold on, I'm drawing 3000 points."

while total<3000:
  x=(random.random()*100.0)-50
  y=(random.random()*100.0)-50
  turtle.up()
  turtle.goto(x,y)
  turtle.down()
  if turtle.distance(0,0)<=50.0:
    turtle.pencolor("blue")
    inside+=1.0
  else:
    turtle.pencolor("orange")
  turtle.dot()
  total+=1.0

first_pi=4.0*(inside/total)
print "Dots method: pi~",first_pi,"\n"

print "Here, lemme try something else."
second_pi=0
for i in xrange(1000):
  if i%2!=0:
    if (i%4)==1: