def shoot(): global bulletgo global bulletready by = bullet.ycor() if by == -900: bulletready = 1 bulletgo = 0 if bulletready == 0: bullet.ht() if bulletready == 1: x = player.xcor() - 10 y = player.ycor() + 80 bullet.st() bullet.goto(x, y) bullet.setheading(90) while bulletgo <= 50: bullet.speed(1) bullet.forward(10) bulletgo += 1 bulletready == 0 for opponent in opponents: collision(opponent, bullet) if bulletgo >= 50: bullet.speed(0) bullet.ht() bulletgo = 100 bullet.goto(-900, -900)
def draw_l(word): turtle.up() turtle.clear() turtle.setposition(0, 0) turtle.setheading(0) turtle.bk(INITIAL_POS[0]) turtle.down() turtle.st() stack = [] for char in word: if char == '0': turtle.fd(SIZE[0]) if char == '1': turtle.fd(SIZE[0]) if char == '[': stack.append((turtle.position(), turtle.heading())) turtle.lt(45) if char == ']': position, heading = stack.pop() turtle.up() turtle.setposition(position) turtle.setheading(heading) turtle.rt(45) turtle.down() turtle.ht()
def draw_onclick_stack(self): import turtle turtle.clear() turtle.home() a = input("\n**** CREATE STACK ****") n = int(input("Enter the number of nodes to be drawn: ")) loadwindow = turtle.screensize() turtle.ht() turtle.penup() turtle.goto(0, -250) turtle.st() turtle.pendown() turtle.speed(10) for i in range(0, n): b = int(input("enter elements to the node:")) print(i) turtle.ht() turtle.lt(90) turtle.fd(70) turtle.rt(90) turtle.fd(70) turtle.rt(90) turtle.fd(70) turtle.rt(90) turtle.fd(70) turtle.rt(90) #turtle.fd(70) #turtle.stamp() turtle.write(b, font="Arial", align='left') turtle.fd(i + 70) turtle.rt(90)
def on_screen_click(mousex, mousey): print("I have been teleported to ({},{})".format(mousex, mousey)) t.ht() t.goto(mousex, mousey) global cleared cleared = False t.st()
def m(x, y): turtle.bye() turtle.ht() turtle.clear() turtle.bgcolor("yellow") tym1() t = 0 c = b + " " for i in str(c): if (t < len(b) - 1): if (b[t - 1] != " " and i != " "): turtle.bgcolor("green") j = 0 while (j <= 1500000): j += 1 if (i != " " and c[t - 1] != " "): turtle.bgcolor("green") j = 0 while (j <= 1500000): j += 1 conv(d[i]) t += 1 turtle.write("end", align="center", font=("Arial", 35, "normal")) turtle.st() def n(x, y): turtle.bye() turtle.onclick(n)
def change_position(): opponent.speed(0) opponent.penup() opponent.ht() new_xpos = random.randint(-400, 400) new_ypos = random.randint(0, 100) opponent.goto(new_xpos, new_ypos) opponent.st()
def Polygon(n, head): turtle.st() turtle.goto(0,0) turtle.pd() for i in range (n): turtle.fd(50) turtle.delay(50) turtle.left(head)
def drawEdge(e): turtle.st() ((sx, sy), (ex, ey)) = e turtle.goto(sx * 300, sy * 300) turtle.pendown() turtle.goto(ex * 300, ey * 300) turtle.dot() turtle.penup() turtle.ht()
def make_circle(): m = 3 for p in range(120): turtle.left(3) turtle.forward(m) if p > 60: turtle.st() turtle.shape('turtle') turtle.ht()
def chess_board(li): turtle.tracer(0, 0) WIDTH = 40 turtle.st() turtle.pu() turtle.goto(-len(li) / 2 * WIDTH, len(li) / 2 * WIDTH) turtle.pd() turtle.setup(width=len(li) * WIDTH + WIDTH, height=len(li) * WIDTH + WIDTH) turtle.title("Solving N-Queen...") def square(coloring): if coloring: turtle.begin_fill() for h in range(4): turtle.fd(WIDTH) turtle.rt(90) turtle.end_fill() else: for k in range(4): turtle.fd(WIDTH) turtle.rt(90) for i in range(1, len(li) + 1): for j in range(1, len(li) + 1): if ((i + j) % 2 == 0) or (i % 2 != 0 and j % 2 != 0): square(True) turtle.fd(WIDTH) else: square(False) turtle.fd(WIDTH) turtle.pu() turtle.goto(-len(li) / 2 * WIDTH, -WIDTH * i + len(li) / 2 * WIDTH) turtle.pd() turtle.pu() turtle.ht() for item in enumerate(li, 1): if item[0] <= len(li) / 2 and item[1] <= len(li) / 2: turtle.goto(-WIDTH * (len(li) / 2 + 1 - item[0]) + WIDTH / 2, WIDTH * (len(li) / 2 + 1 - item[1]) - WIDTH / 2) turtle.dot(WIDTH / 2, 'red') if item[1] <= len(li) / 2 < item[0]: turtle.goto(WIDTH * (item[0] - len(li) / 2) - WIDTH / 2, WIDTH * (len(li) / 2 + 1 - item[1]) - WIDTH / 2) turtle.dot(WIDTH / 2, 'red') if item[0] <= len(li) / 2 < item[1]: turtle.goto(-WIDTH * (len(li) / 2 + 1 - item[0]) + WIDTH / 2, -WIDTH * (item[1] - len(li) / 2) + WIDTH / 2) turtle.dot(WIDTH / 2, 'red') if item[0] > len(li) / 2 and item[1] > len(li) / 2: turtle.goto(WIDTH * (item[0] - len(li) / 2) - WIDTH / 2, -WIDTH * (item[1] - len(li) / 2) + WIDTH / 2) turtle.dot(WIDTH / 2, 'red') turtle.mainloop()
def infoPrt(): print('coordinate: ' + str(t.pos())) print('angle: ' + str(t.heading())) t.pensize(3) t.hideturtle() t.colormode(255) t.color("black") t.setup(700, 650) t.speed(10) t.st()
def show(self): turtle.ht() if self.pillars_down: for i in range(self.count_pillars): lx = self.x - self.size / 2 + i * (self.size / (self.count_pillars - 1)) turtle.penup() turtle.goto(self.x, self.y + self.size / 3) turtle.pendown() turtle.goto(lx, self.y - self.size / 6) turtle.penup() turtle.goto(self.x, self.y - self.size / 12) turtle.pendown() turtle.fillcolor('black') turtle.begin_fill() turtle.circle(self.size / 4) turtle.end_fill() turtle.penup() turtle.fillcolor(self.color) turtle.goto(self.x - self.size / 2, self.y + self.size / 4) turtle.pendown() turtle.begin_fill() turtle.fd(self.size) i = math.pi / 2 while i <= 3 * math.pi / 2: sx = (self.size / 2) * math.sin(i) sy = (self.size / 3) * math.cos(i) turtle.goto(self.x + sx, self.y + self.size / 4 + sy) i += math.pi / self.size turtle.end_fill() turtle.fillcolor('red') n = self.count_lamps + 2 for i in range(1, n - 1): dx = self.size / (n - 1) turtle.begin_fill() turtle.penup() turtle.goto(self.x - self.size / 2 + i * dx, self.y + self.size / 14) turtle.pendown() turtle.circle(dx / 4) turtle.end_fill() turtle.penup() if self.show_name: turtle.goto(self.x, self.y + self.size / 2) turtle.pendown() turtle.write(self.name, align='center') turtle.penup() turtle.goto(0, 0) turtle.st()
def colour(t): tr.setposition(t[0]*r,(11-S-t[1])*r) tr.color("pink","pink") tr.st() #time.sleep(0.5) tr.ht() tr.color("green","green") tr.pendown() tr.shape("square") q=tr.stamp() tr.penup() clr[t]=q
def botmove(y, x): global A, B X = (x - A) / ABS(x - A) Y = (y - B) / ABS(y - B) if ((X, Y) != (0, 0)): tr.shape('bot' + d1[(X, Y)] + '.gif') tr.st() global u tr.clearstamp(u) tr.setpos(-315 + a + x * r, -225 + b + (6 - y) * r) A = x B = y
def clearscreen(): player.st() player.setheading(0) player.penup() player.speed(0) player.goto(0, 0) player.pendown() player.pensize(1000) player.pencolor("white") player.forward(1000) player.right(90) player.forward(1000) player.right(90) player.forward(1000) player.right(90) player.forward(1000) player.right(90) player.forward(1000) player.right(90) player.forward(1000) player.right(90) player.setheading(180) player.penup() player.speed(0) player.goto(0, 0) player.pendown() player.pensize(1000) player.pencolor("white") player.forward(1000) player.right(90) player.forward(1000) player.right(90) player.forward(1000) player.right(90) player.forward(1000) player.right(90) player.forward(1000) player.right(90) player.forward(1000) player.right(90) player.penup() player.pensize(ps) player.pencolor("black") player.goto(0, 0) title() title2() write_rule() player.pendown()
def present(vector): t.pensize(2) t.st() center() colorv = vector.getColor() t.color(colorv) if dimcheck(vector.getComp()): x = vector.getComp()[0] y = vector.getComp()[1] finalx = x * tscale finaly = y * tscale t.pendown() t.goto(finalx, finaly) addtriangle(vector, finalx, finaly) t.color(0, 0, 0) t.pensize(1)
def init_cp(self, cp_list): turtle.ht() self.start_point = cp_list[-1] self.start_ang = math.atan2( cp_list[0][1] - cp_list[-1][1], cp_list[0][0] - cp_list[-1][0]) * 180 / math.pi turtle.speed(0) for l in cp_list: turtle.up() turtle.setposition(l[0], l[1] - 600) turtle.seth(0) turtle.down() turtle.circle(600) turtle.up() turtle.setposition(self.start_point) turtle.seth(self.start_ang) turtle.st()
def move_player(): global village, if_player_food my_pos = turtle.pos() x_pos = my_pos[0] y_pos = my_pos[1] if direction == RIGHT: turtle.goto(x_pos + (1.5 * SQUARE_SIZE), y_pos) #print("you moved to the right!") elif direction == LEFT: turtle.goto(x_pos - (1.5 * SQUARE_SIZE), y_pos) #print("you moved to the left!") elif direction == UP: turtle.goto(x_pos, y_pos + (1.5 * SQUARE_SIZE)) #print("you moved UP") elif direction == DOWN: turtle.goto(x_pos, y_pos - (1.5 * SQUARE_SIZE)) #print("you moved DOWN") my_pos = turtle.pos() pos_list.append(my_pos) #print(pos_list[-1]) global TIME_STEP global count #limiting the player in the border if x_pos > SIZE_X / 2: turtle.ht() turtle.goto(-SIZE_X / 2 + 10, y_pos) turtle.st() elif x_pos <= -SIZE_X / 2: turtle.ht() turtle.goto(SIZE_X / 2, y_pos) turtle.st() elif y_pos > SIZE_Y / 2: turtle.ht() turtle.goto(x_pos, -SIZE_Y / 2 + 2) turtle.st() elif y_pos <= -SIZE_Y / 2: turtle.ht() turtle.goto(x_pos, SIZE_Y / 2 - 2) turtle.st() if -30 < enemy.pos()[0] - turtle.pos()[0] < 30 and -30 < enemy.pos( )[1] - turtle.pos()[1] < 30: turtle.goto(-100, 0) turtle.pencolor("white") time1.clear() turtle.write("ghost won!", font=("Ariel", 48, "normal")) time.sleep(5) quit() turtle.ontimer(move_player, TIME_STEP)
def turtlespecs(turtle, clr='black', speed=0, pu=True, ht=True): """ A function to set parameters for a Turtle.Turtle()-instance. :param turtle: turtle.Turtle() :param clr: string with color. :param speed: int 0-10 :param pu: Pen up :param ht: Hide-turtle """ turtle.speed(speed) turtle.color(clr) if pu: turtle.pu() else: turtle.pd() if ht: turtle.ht() else: turtle.st()
def addtriangle(vector, x, y): if dimcheck(vector.getComp()): t.st() t.up() arrowSize = (modul(vector.getComp())) / 5 arrowSize *= tscale t.seth(m.degrees(dotangle(vector.getComp(), [10, 0]))) t.goto(x, y) t.pendown() t.right(150) t.forward(arrowSize) t.backward(arrowSize) t.right(60) t.forward(arrowSize) t.backward(arrowSize) center()
def laad_doolhof(path="doolhof3.txt"): global env turtle.ht() (env.doolhof, env.s, env.e) = lees_doolhof(path) env.start = env.s env.cv = turtle.getcanvas() env.w = env.cv.winfo_width() env.h = env.cv.winfo_height() env.dh = len(env.doolhof) env.dw = len(env.doolhof[0]) env.cw = env.w / env.dw env.ch = env.h / env.dh draw_doolhof(env.cv, env.doolhof) turtle.penup() turtle.speed(5) move_to(env.s) turtle.right(turtle.heading()) turtle.st()
def Render_world(world): turtle.penup() turtle.speed(0) turtle.ht() turtle.screensize(100, 100, "black") print(world) print(world[1]) print(world[1][1]) for x in range(5): for y in range(5): if world[x][y][0] == 'G': turtle.shape('MySquareGrass') turtle.setposition(world[x][y][1], world[x][y][2]) turtle.stamp() else: turtle.shape('MySquareWater') turtle.setposition(world[x][y][1], world[x][y][2]) turtle.stamp() turtle.shape('MySquare') turtle.setposition(0, 0) turtle.st()
def full_song(x): for i in range (x): song(m) #full_song() def song(s): print(s) m = str(input('give me text for multipying: ')) full_song(int(input('how many times: '))) ''' import turtle turtle.st() turtle.speed(1) turtle.shape('classic') turtle.delay = 2 def make_circle(): m = 3 for p in range(120): turtle.left(3) turtle.forward(m) if p > 60: turtle.st() turtle.shape('turtle') turtle.ht()
from turtle import * from turtle import setup as st aX = [-7, 12] aY = [-3.5, 3.5] Dx = 800 Dy = Dx / ((aX[1] - aX[0]) / (aY[1] - aY[0])) st(Dx, Dy) Nmax = 1000 setworldcoordinates(aX[0], aY[0], aX[1], aY[1]) def MyFunc(): up() width(5) color("black") dx = (aX[1] - aX[0]) / Nmax goto(-7, 3) up() down() goto(-3, 3) up() down() right(90) for i in range(93): left(1.9) forward(0.1) goto(6, -3) goto(11, 2)
def move_player(): global village, if_player_food, direction, gdirection my_pos = turtle.pos() x_pos = my_pos[0] y_pos = my_pos[1] def ghostChase(): if direction == RIGHT: enemy.goto(x_pos + (1.5*SQUARE_SIZE), y_pos) #print("you moved to the right!") elif direction == LEFT: enemy.goto(x_pos - (1.5*SQUARE_SIZE), y_pos) #print("you moved to the left!") elif direction == UP: enemy.goto(x_pos, y_pos + (1.5*SQUARE_SIZE)) #print("you moved UP") elif direction == DOWN: enemy.goto(x_pos, y_pos - (1.5*SQUARE_SIZE)) turtle.ontimer(ghostChase, TIME_STEP) if direction == RIGHT: turtle.goto(x_pos + (1.5*SQUARE_SIZE), y_pos) #print("you moved to the right!") elif direction == LEFT: turtle.goto(x_pos - (1.5*SQUARE_SIZE), y_pos) #print("you moved to the left!") elif direction == UP: turtle.goto(x_pos, y_pos + (1.5*SQUARE_SIZE)) #print("you moved UP") elif direction == DOWN: turtle.goto(x_pos, y_pos - (1.5*SQUARE_SIZE)) #print("you moved DOWN") my_pos = turtle.pos() pos_list.append(my_pos) #print(pos_list[-1]) global TIME_STEP global count #limiting the player in the border if x_pos > SIZE_X/2: turtle.ht() turtle.goto(-SIZE_X/2 + 10, y_pos) turtle.st() elif x_pos <= -SIZE_X/2: turtle.ht() turtle.goto(SIZE_X/2, y_pos) turtle.st() elif y_pos > SIZE_Y/2: turtle.ht() turtle.goto(x_pos, -SIZE_Y/2+2) turtle.st() elif y_pos <= -SIZE_Y/2: turtle.ht() turtle.goto(x_pos, SIZE_Y/2-2) turtle.st() if if_player_food == True: enemy.shape("ghost.gif") turtle.shape("player_F.gif") elif if_player_food == False: enemy.shape("ghost_F.gif") turtle.shape("player.gif") if -30 <enemy.pos()[0] - turtle.pos()[0] < 30 and -30 < enemy.pos()[1] - turtle.pos()[1] < 30 and if_player_food == False: village.st() enemy.goto(0,0) time.sleep(0.5) #updating player with food status if_player_food = True if -40 <enemy.pos()[0] - turtle.pos()[0] < 40 and -40 < enemy.pos()[1] - turtle.pos()[1] < 40 and if_player_food == True: score.clear() count -=100 scores.append(count) score.pencolor("white") score.write("score: "+str(count),font=("Arial", 28, "normal")) if_player_food = False enemy.goto(0,0) time.sleep(0.2) if (-15 <village.pos()[0] - turtle.pos()[0] < 15 and -15 < village.pos()[1] - turtle.pos()[1] < 15) and if_player_food == True: score.clear() count +=100 scores.append(count) score.pencolor("white") score.write("score: "+str(count),font=("Arial", 28, "normal")) enemy.shape("ghost_F.gif") turtle.shape("player.gif") if_player_food = False if count < 0: turtle.goto(0,0) turtle.pencolor("white") turtle.write("Ghost won!", font = ("Ariel", 28,"normal")) time.sleep(5) quit() if count == 1000: turtle.goto(0,0) turtle.pencolor("white") turtle.write("PLayer won!", font = ("Ariel", 28,"normal")) time.sleep(5) quit() turtle.ontimer(move_player,TIME_STEP)
def WASD(W): if (True): if (True): if (True): print("-") if (W == "w"): turtle.forward(50) elif (W == "a"): turtle.left(90) elif (W == "s"): turtle.right(180) turtle.forward(25) elif (W == "d"): turtle.right(90) elif (W == "ss"): turtle.backward(25) elif (W == "c"): turtle.clear() elif (W == "r"): turtle.reset() elif (W == "bgc"): color = input("What color?") turtle.bgcolor(color) elif (W == "shape"): shape = input("What shape?") turtle.shape(shape) elif (W == "pic"): pic = input("Type the name of the pic") turtle.bgpic(pic) elif (W == "efill"): turtle.end_fill() elif (W == "sleep"): print("Going to Sleep") WASD("st") wer = 0 while (wer < 10): WASD("a") wer = (wer+1) WASD("ht") WASD("bcb") input() wer = 0 while (wer < 10): WASD("a") wer = (wer+1) WASD("ht") WASD("r") WASD("ht") turtle.bgcolor("white") WASD("stop") elif (W == "shutdown script"): print("Running Shutdown Scripts") turtle.shape("turtle") wer = 0 WASD("st") while (wer < 10): WASD("a") wer = (wer+1) WASD("ht") # turtle.bgpic("shutdown") WASD("bcb") WASD("www") WASD("d") WASD("ww") elif (W == "fill"): turtle.begin_fill() elif (W == "stop"): return(31415926535897) elif (W == "bcb"): turtle.bgcolor("black") elif (W == "2x2"): WASD("w") WASD("a") WASD("w") WASD("a") WASD("w") WASD("a") WASD("w") WASD("d") WASD("w") WASD("d") WASD("w") WASD("d") WASD("w") WASD("d") WASD("w") WASD("d") WASD("w") WASD("d") WASD("w") WASD("d") WASD("w") WASD("w") WASD("d") WASD("w") WASD("d") WASD("w") WASD("d") WASD("w") WASD("w") WASD("d") WASD("w") WASD("d") WASD("w") WASD("d") WASD("w") WASD("w") WASD("d") WASD("w") WASD("d") WASD("w") elif (W == "ww"): turtle.forward(25) elif (W == "www"): turtle.forward(100) elif (W == "wwww"): turtle.forward(200) elif (W == "bgw"): turtle.bgcolor("white") elif (W == "w2"): turtle.forward(9500) elif (W == "w1"): turtle.forward(4750) elif (W == "ht"): turtle.ht() elif (W == "st"): turtle.st() else: print("invalid move") else: print("") else: print("") else: print("")
def worm(): t.pensize(3) t.color('black', 'green') t.pu() t.goto(-400, 100) t.pd() t.begin_fill() t.circle(-100) t.end_fill() t.pu() t.goto(-250, 25) t.pd() t.begin_fill() t.circle(-100) t.end_fill() t.pu() t.goto(-50, 0) t.pd() t.begin_fill() t.circle(-100) t.end_fill() t.pu() t.goto(100, -125) t.pd() t.begin_fill() t.circle(-100) t.end_fill() t.pu() t.goto(250, -200) t.pd() t.begin_fill() t.circle(100) t.end_fill() t.pu() t.goto(350, -25) t.pd() t.begin_fill() t.circle(100) t.end_fill() t.pu() t.goto(300, 50) t.pd() t.color('red') t.goto(350, 25) t.goto(400, 50) t.pu() t.goto(325, 175) t.pd() t.color('black') t.goto(300, 250) t.goto(250, 200) t.pu() t.goto(375, 175) t.pd() t.goto(400, 250) t.goto(450, 200) t.st()
import turtle as t t.pensize(3) t.hideturtle() t.colormode(255) t.color("black") t.setup(700, 650) t.speed(10) t.st() t.pu() t.goto(-210, 86) t.pd() t.seth(85) t.circle(-100, 40) p_ear = t.pos() t.circle(-100, 10) t.seth(25) t.circle(-170, 50) # right ear t.seth(40) t.circle(-250, 30) t.begin_fill() t.circle(-250, 22) t.seth(227) t.circle(-270, 15) t.end_fill() t.circle(-270, 28)
import turtle p=100 while(p>0): if(p==10 or p==30 or p==50 or p==70 or p==90): turtle.color('red') if(p==20 or p==40 or p==60 or p==80 or p==100): turtle.color('yellow') turtle.ht() turtle.st() p=p-1 print turtle.isvisible() turtle.exitonclick()
def showTurtle(): t.st() return
start = (3, 5) masterRoute = [] while (len(stop) > 0): q = findnearest(start) masterRoute.append(q[1]) w = deposit(q[0]) masterRoute.append(w[1]) start = w[1][-1] print(masterRoute) tr.shape('botsouth.gif') goto(3, 5) tr.shape('botsouth.gif') tr.st() time.sleep(1) m = [] for i in masterRoute: m.extend(i) q1 = ((len(m) - 1) * 21) / 15 q2 = (turn(m) * 21) / 15 print(q1 + q2, 'seconds') print(q1 * 15, 'cms') tr.tracer(1, 25) k = 0 u = None for i in masterRoute: for j in i:
for i in range(10000000): # 거북이가 계속 돌아 다니도록 큰 수를 for 문에 주어 반복시킨다. t.fd(1.5) #거북이가 1.5씩 전진 a =float(t.xcor()) # a에 실수형으로 거북이 x좌표 실시간 저장 c = float(t.ycor()) # c에 실수형으로 거북이 y좌표 실시간 저장 b = float(t.heading()) # b에 실수형으로 거북이 각도 저장 col = r.choice(colors) # col 에 사전에 정의해준 colors 배열에 있는 색중 랜덤으로 바꿔주면서 저장 if a >=150 and c>=150: # ?표 박스 장애물의 실행이다 t.ht() #거북이가 해당 x좌표와 y좌표를 동시에 (and 함수로 지정) 넘어가면 사라지도록 지정해준다. if (a >=-250 and a<= 250) and (c>=-60 and c<=70): #거북이가 육지를 밟았을때의 실행이다 t.st() #거북이가 지정된 해당 좌표안에 들어오면 (x좌표-250~250 y좌표 -60~70동시에 만족한다면) t.speed(10) #가장 느린 속도로 가도록 지정 만약 ?표 박스를 만나서 투명화 되었다면 투명을 다시푼다. if (a <= -150 and a >=-200) and (c >=150 and c <= 200): # 소용돌이 장애물의 실행이다. t.speed(2) #설정한 좌표 범위(소용돌이) 를 만나면 2의 속도로 소용돌이에 휘말리도록 설정 for i in range(8): #for문으로 소용돌이를 그려준것과 유사한 방법으로 소용돌이에 휘말리는 효과를 표현하였다. t.circle(5 * i, 80) if a>=250 : # 거북이가 x축좌표 경계값250을 넘어가는것을 방지해준다. t.speed(0) #거북이가 경계값 을 만나거나 넘어가면 가장 빠른 속도로 반응하도록 설정 t.color(col) #경계값을 만나는 순간 사전에 정의해준 col 함수로 colors배열에 있던 색중에 랜덤으로 골라 거북이 색을 바꿔준다. t.setheading(180-b) #거북이가 경계값을 만나는 순간 입사각을 고려해서 반사각으로 나아가도록 설정해 준다. accelx(3,2,20) #거북이가 경계값을 만나는 순간 사전에 정의해준 가속도 함수 accelx 를 이용하여 1단계 속도3 2단계 속도2 로 각각 20씩 이동하도록 해준다. if c <=-250: # if문을 사용하여 거북이가 y축좌표 경계값-250을 넘어가는것을 방지해주며 경계값을 만나는 순간 가속도 함수를 실행하고 t.speed(0) # 입사각 을 고려하여 거북이의 각도를 반사각으로 돌리며 거북이 색을 랜덤하게 바꾼다.
def showTurtle(): t.st() return