def show_robot(self, xyh): turtle.clearstamps() turtle.color("green") turtle.shape('turtle') turtle.setposition([xyh[0] * self.mapScale, xyh[1] * self.mapScale]) turtle.setheading(90 - xyh[2]) turtle.stamp()
def show_particles(self, particles): self.update_cnt += 1 if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1: return turtle.clearstamps() turtle.shape('tri') # Particle weights are shown using color variation show_color_weights = 1 #len(weights) == len(particles) draw_cnt = 0 px = {} for i, p in enumerate(particles): draw_cnt += 1 if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 1: # Keep track of which positions already have something # drawn to speed up display rendering scaled_x = int(p.x * self.one_px) scaled_y = int(p.y * self.one_px) scaled_xy = scaled_x * 10000 + scaled_y if not scaled_xy in px: px[scaled_xy] = 1 turtle.setposition([p.x + self.width / 2, p.y + self.height / 2]) turtle.setheading(p.theta / pi * 180.0) if(show_color_weights): weight = p.w else: weight = 0.0 turtle.color(self.weight_to_color(weight)) turtle.stamp()
def draw_track(x, y): velocity = t.numinput("입력", "속도 :", 50, 30, 100) ##turtle.numinput():두개의 인자를 요청하는 함수이며, 첫 인자는 'prompt'두 번째 인자는'default'입니다. ##prompt는 입력하려고 하는 숫자를 설명하는 내용의 텍스트 'default'는 값을 입력하지 않았을 때 함수가 받아들일 값입니다. angle = math.radians(t.numinput("입력", "각도", 30, 0, 360)) ## 도>라디안으로 바꿔주는 함수입니다. ex)radians(90)=1.57 t.clearstamps() ## 화면의 모든 스탬프를 클리어합니다. t.hideturtle() ##거북이를 화면에서 숨기는 기능의 함수입니다. showturtle와 반대의 함수 t.setpos(x, y) ## 좌표(x,y)로 이동 == t.goto(a,b)와 같은 함수 t.showturtle() ##거북이를 화면에 표시하는 함수 t.stamp() ##현재위치에 스탬프 찍기 hl = -(t.window_height() / 2) # t.window_height() : 터틀창의 높이를 반환하는 함수 ux = velocity * math.cos(angle) uy = velocity * math.sin(angle) while True: uy = uy + (-1 * a_g) * drawing_time dy = t.ycor() + (uy * drawing_time) - (a_g * drawing_time ** 2) / 2 ##t.ycor() : 현재위치의 y좌표 반환 dx = t.xcor() + (ux * drawing_time) # t.xcor() : 현재위치의 x좌표 반환 if dy > hl: t.goto(dx, dy) t.stamp() else: break ##완료시 반복문 탈출
def show_particles(self, particles): self.update_cnt += 1 if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1: return turtle.clearstamps() turtle.shape('tri') # Particle weights are shown using color variation show_color_weights = 1 #len(weights) == len(particles) draw_cnt = 0 px = {} for i, p in enumerate(particles): draw_cnt += 1 if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 1: # Keep track of which positions already have something # drawn to speed up display rendering scaled_x = int(p.x * self.one_px) scaled_y = int(p.y * self.one_px) scaled_xy = scaled_x * 10000 + scaled_y if not scaled_xy in px: px[scaled_xy] = 1 turtle.setposition( [p.x + self.width / 2, p.y + self.height / 2]) turtle.setheading(p.theta / pi * 180.0) if (show_color_weights): weight = p.w else: weight = 0.0 turtle.color(self.weight_to_color(weight)) turtle.stamp()
def move(): global score global snakeSize turtle.setheading(headDirection) turtle.color("black") turtle.penup() turtle.shape("square") turtle.stamp( ) #Snake moves forward - stamping green squares to represent the location of the body - by an x or y value of 20 to ensure it stays in line with the game board and food. turtle.fd(20) if score <= 5: #Speed of the turtle is based on the length of the snake (difficulty increases) turtle.speed(2) elif 5 < score <= 15: turtle.speed(3) elif 15 < score < 25: turtle.speed(4) else: turtle.speed(5) ''' #Line below in docstring is useful for testing - prints the 2d current position array in th4e console print(currentPos) ''' x = turtle.xcor() y = turtle.ycor() if snakeSize > score: turtle.clearstamps( 1 ) #Erases any squares in the body of the snake from the array if the body length exceeds the score (keeps the turtle at a length consistent to the score) currentPos.insert(0, [round(x), round(y)]) currentPos.pop(-1) else: currentPos.insert( 0, [round(x), round(y)] ) #if the length of the snake drawn isnt greater than the score, a new snake position is added to the array (Also to ensure the length of the snake is consistent with the score) snakeSize = snakeSize + 1
def show_sharks(self, sharks): self.update_cnt += 1 if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1: return turtle.clearstamps() draw_cnt = 0 px = {} for shark in sharks: draw_cnt += 1 shark_shape = 'classic' if shark.tracked else 'classic' if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 0: # Keep track of which positions already have something # drawn to speed up display rendering scaled_x = int(shark.x * self.one_px) scaled_y = int(shark.y * self.one_px) scaled_xy = scaled_x * 10000 + scaled_y turtle.color(shark.color) turtle.shape(shark_shape) turtle.resizemode("user") turtle.shapesize(1.5,1.5,1) if not scaled_xy in px: px[scaled_xy] = 1 turtle.setposition(*shark.xy) turtle.setheading(math.degrees(shark.h)) turtle.stamp()
def show_particles_2(self, particles): self.update_cnt += 1 if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1: return turtle.clearstamps() turtle.shape('tri') draw_cnt = 0 px = {} for i, p in enumerate(particles): draw_cnt += 1 if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 1: # Keep track of which positions already have something # drawn to speed up display rendering scaled_x = int(p[0] * self.one_px) scaled_y = int(p[1] * self.one_px) scaled_xy = scaled_x * 10000 + scaled_y if not scaled_xy in px: px[scaled_xy] = 1 turtle.setposition(p[0] * self.mapScale, p[1] * self.mapScale) turtle.setheading(90 - p[2]) # turtle.color(self.weight_to_color(weights[i])) turtle.color("#b74d2a") turtle.stamp() turtle.update()
def redraw(self): ## update graphics display by clearing all trees and redrawing ## turtle.clearstamps() # clears the board for each in self.forest: if each != None: each.draw() # draws the new forest turtle.update() # updates the screen
def redraw(self): '''redraws graphic display''' turtle.clearstamps() turtle.tracer(0, 0) for obj in self.forestList: if obj != None: obj.draw() turtle.update()
def animateScene(self, scenes): for frame in scenes: turtle.clearstamps() frame.getData() for each in frame.getData(): temporaryBall.stampBallScene(each) turtle.update() time.sleep(.05)
def redraw(self): #used to draw the update gathering list turtle.clearstamps() turtle.tracer(0, 0) for person in self.gathering: if person != None: person.draw() turtle.update()
def show_particles(self, particles): turtle.clearstamps() for p in particles: turtle.setposition(*p.xy) turtle.setheading(p.h) turtle.color(self.weight_to_color(p.w)) turtle.stamp() turtle.update()
def move(): global x, y, Vsnake, t, cherry t = t + 1 turtle.forward(Vsnake) turtle.stamp() if cherry > 0: cherry = cherry - 1 else: turtle.clearstamps(1) turtle.ontimer(move, 100)
def updateForest(self): turtle.clearstamps() for i, j in self.burningCoordinate: self.updateNeighbor(i, j) self.removeTrees(self.burningCoordinate) self.burningCoordinate = [] for i in range(40): for j in range(40): if self.trees[i][j] and self.trees[i][j].burning: self.burningCoordinate.append((i, j)) self.redraw() turtle.update()
def move(): global x, y, Vsnake, t, cherry t = t + 1 turtle.forward(Vsnake) turtle.stamp(); if cherry > 0: cherry = cherry - 1 else: turtle.clearstamps(1) turtle.ontimer(move, 100)
def move(): turtle.setheading(heading[0]) turtle.up() turtle.stamp() position.append(turtle.position()) # Turtle's stamp size is 20 # So before creating another stamp move forward 20 turtle.fd(20) # Boundary conditio to check the length of snake is not more than the score + 1 if score[0] + 1 < len(position): turtle.clearstamps(1) position.pop(0)
def showParticles(self, _loc): turtle.tracer(50000, delay=0) turtle.register_shape("dot", ((-3, -3), (-3, 3), (3, 3), (3, -3))) turtle.register_shape("tri", ((-3, -2), (0, 3), (3, -2), (0, 0))) turtle.speed(0) turtle.setworldcoordinates(0, (self.maze.resolution + 1) * 3, (self.maze.resolution + 1) * 3, 0) turtle.up() turtle.clearstamps() lines = turtle.Turtle() lines.color("black") lines.pensize(5) for i in range(len(self.maze.layout)): for j in range(len(self.maze.layout[0])): if self.maze.layout[i][j][2] == 'X': lines.penup() lines.goto(j * (self.maze.resolution) - 1, (i + 1) * self.maze.resolution - 1) lines.pendown() lines.forward(self.maze.resolution) lines.penup() if self.maze.layout[i][j][1] == 'X': lines.penup() lines.goto(j * (self.maze.resolution) - 1, i * self.maze.resolution) lines.pendown() lines.forward(self.maze.resolution) lines.penup() turtle.shape('tri') for p in self.particles: #print(p.x, p.y) turtle.setposition(p.x, p.y) heading = ((p.orientation + math.pi / 2) / (2 * math.pi)) * 360 turtle.setheading(heading) turtle.color("red") turtle.stamp() #turtle.update() turtle.shape('dot') turtle.color("blue") turtle.setposition(self.bestParticle.x, self.bestParticle.y) turtle.stamp() turtle.shape('turtle') turtle.color("green") turtle.setposition(_loc[0], _loc[1]) headingr = ((_loc[2] + math.pi / 2) / (2 * math.pi)) * 360 turtle.setheading(headingr) #heading = (self.particles[self.prWithHeighestW].orientation / (2 * math.pi)) * 360 #turtle.setheading(heading) turtle.update()
def show_particles(self, particles): self.update_cnt += 1 if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1: return turtle.clearstamps() turtle.shape('tri') draw_cnt = 0 for p in particles: draw_cnt += 1 if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 1: turtle.setposition(*p.xy) turtle.setheading(p.h) turtle.color(self.weight_to_color(p.w)) turtle.stamp()
def showParticles(self, _loc): turtle.tracer(50000, delay=0) turtle.register_shape("dot", ((-3, -3), (-3, 3), (3, 3), (3, -3))) turtle.register_shape("tri", ((-3, -2), (0, 3), (3, -2), (0, 0))) turtle.speed(0) turtle.setworldcoordinates(0,(self.maze.resolution+1)*3,(self.maze.resolution+1)*3,0) turtle.up() turtle.clearstamps() lines = turtle.Turtle() lines.color("black") lines.pensize(5) for i in range(len(self.maze.layout)): for j in range(len(self.maze.layout[0])): if self.maze.layout[i][j][2]=='X': lines.penup() lines.goto(j*(self.maze.resolution)-1,(i+1)*self.maze.resolution-1) lines.pendown() lines.forward(self.maze.resolution) lines.penup() if self.maze.layout[i][j][1] == 'X': lines.penup() lines.goto(j * (self.maze.resolution) - 1, i * self.maze.resolution) lines.pendown() lines.forward(self.maze.resolution) lines.penup() turtle.shape('tri') for p in self.particles: #print(p.x, p.y) turtle.setposition(p.x,p.y) heading = ((p.orientation +math.pi/2) / (2 * math.pi)) * 360 turtle.setheading(heading) turtle.color("red") turtle.stamp() #turtle.update() turtle.shape('dot') turtle.color("blue") turtle.setposition(self.bestParticle.x, self.bestParticle.y) turtle.stamp() turtle.shape('turtle') turtle.color("green") turtle.setposition(_loc[0], _loc[1]) headingr = ((_loc[2] +math.pi/2) / (2 * math.pi)) * 360 turtle.setheading(headingr) #heading = (self.particles[self.prWithHeighestW].orientation / (2 * math.pi)) * 360 #turtle.setheading(heading) turtle.update()
def move(): turtle.pensize(1) turtle.color('green') turtle.pu() turtle.speed(3) turtle.setheading(head[0]) turtle.shape('square') turtle.stamp() turtle.fd(10) x = turtle.xcor() y = turtle.ycor() if b[0] > a[0]: turtle.clearstamps(1) cpos.insert(0, [round(x), round(y)]) cpos.pop(-1) else: cpos.insert(0, [round(x), round(y)]) b[0] += 1
def move(): turtle.pensize(1) turtle.color("green") turtle.pu() turtle.speed(2) turtle.setheading(head[0]) turtle.shape("square") turtle.stamp() turtle.fd(20) x = turtle.xcor() y = turtle.ycor() if b[0] > a[0]: turtle.clearstamps(1) #change the body length cpos.insert(0, [round(x), round(y)]) cpos.pop(-1) else: cpos.insert(0, [round(x), round(y)]) b[0] += 1
def move(): turtle.pensize(1) turtle.color("black") turtle.pu() turtle.speed(5) turtle.setheading(h[0]) turtle.shape("square") turtle.stamp() turtle.fd(20) x = turtle.xcor() y = turtle.ycor() if b[0] > a[0]: turtle.clearstamps(1) pos.insert(0, [round(x), round(y)]) pos.pop(-1) else: pos.insert(0, [round(x), round(y)]) b[0] += 1
def move(): turtle.pensize(1) turtle.color("blue") turtle.pu() turtle.speed(2) turtle.setheading(head[0]) turtle.shape("circle") turtle.stamp() turtle.fd(20) x = turtle.xcor() y = turtle.ycor() if b[0] > a[0]: turtle.clearstamps(1) cpos.insert(0,[round(x),round(y)]) cpos.pop(-1) else: cpos.insert(0,[round(x),round(y)]) b[0] += 1
def move(): turtle.pensize(1) turtle.color("black") turtle.pu() turtle.speed(3) turtle.setheading(h[0]) turtle.shape("square") turtle.stamp() turtle.fd(20) x = turtle.xcor() y = turtle.ycor() if b[0] > a[0]: turtle.clearstamps(1) pos.insert(0,[round(x),round(y)]) pos.pop(-1) else: pos.insert(0,[round(x),round(y)]) b[0] += 1
def draw_pos(x, y): t.clearstamps() t.setpos(x, y) t.stamp() hl = -(t.window_height() / 2 - 20) tm = 0 while True: d = (9.8 * tm**2) / 2 ny = y - int(d) if ny > hl: t.goto(x, ny) t.stamp() t.write("y:%d, d:%d" % (ny, d), False) tm += 0.3 else: break
def update(self): #function that updates the screen with new graphics bounds=self.bounds t.clearstamps() wall=entities.wall() #reversed the list to start with the light for group in reversed(self.configuration): if isinstance(group, entities.creature_configuration): #do this if it's a creature group.move() group.check_wall_colision(bounds) group.draw() group.keep_space() group.find_closest_light(self.configuration[-1] , group.attract) else: #do this if it's a light group.move() group.check_random() group.check_wall_colision(bounds) group.draw()
def move(): turtle.pensize(1) turtle.color("green") turtle.pu() sped = 2 if a[0] % 5 == 0: sped = sped + 1 turtle.speed(sped) turtle.setheading(head[0]) turtle.shape("circle") turtle.stamp() turtle.fd(10) x = turtle.xcor() y = turtle.ycor() if b[0] > a[0]: turtle.clearstamps(1) pos.insert(0, [round(x), round(y)]) pos.pop(-1) else: pos.insert(0, [round(x), round(y)]) b[0] += 1
def draw_pos(x,y): v = t.numinput("입력","속력:",50,10,100) angle = math.radians(t.numinput("입력","각도:",45,0,360)) t.hideturtle() t.goto(-200, 150) t.clearstamps() t.hideturtle() t.showturtle() t.stamp() hl = -(t.window_height() / 2) ux = v * math.cos(angle) uy = v * math.sin(angle) while True: uy = uy + (-1*g)*tm dy = t.ycor() + uy - (g*tm) dx = t.xcor() + (ux*tm) if dy > hl: t.goto(dx,dy) t.stamp() else: break;
def move(): turtle.pensize(1) turtle.color("black") turtle.pu() turtle.speed(3) turtle.setheading(h[0]) turtle.shape("square") turtle.stamp() turtle.fd(20) x = turtle.xcor() y = turtle.ycor() # Normal state: b = a + 1 if b[0] > a[0]: turtle.clearstamps(1) pos.insert(0, [round(x), round(y)]) pos.pop(-1) else: # get scored in start, but onz pos.insert(0, [round(x), round(y)]) b[0] += 1
def show_particles(self, particles): self.update_cnt += 1 if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1: return turtle.clearstamps() turtle.shape('arrow') turtle.shapesize(0.1, 0.1, 0.1) draw_cnt = 0 px = {} for p in particles: draw_cnt += 1 if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 1: scaled_x = int(p.x * self.one_px) scaled_y = int(p.y * self.one_px) scaled_xy = scaled_x * 10000 + scaled_y if not scaled_xy in px: px[scaled_xy] = 1 turtle.setposition(*p.xy) turtle.setheading(90 - p.h) turtle.color(self.weight_to_color(p.w)) turtle.stamp()
def show_particles(self, particles): self.update_cnt += 1 if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1: return turtle.clearstamps() turtle.shape('tri') draw_cnt = 0 px = {} for p in particles: draw_cnt += 1 if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 1: # Keep track of which positions already have something # drawn to speed up display rendering scaled_x = int(p.x * self.one_px) scaled_y = int(p.y * self.one_px) scaled_xy = scaled_x * 10000 + scaled_y if not scaled_xy in px: px[scaled_xy] = 1 turtle.setposition(*p.xy) turtle.setheading(90 - p.h) turtle.color(self.weight_to_color(p.w)) turtle.stamp()
def reset(): turtle.clearstamps(None) gamerules.init() sel = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0] # padding , 1 ~ p1 = [] p2 = []
def clear_objects(self): turtle.clearstamps()
import turtle turtle.shape('turtle') finn = turtle.clone() finn.shape('square') finn.goto(100, 0) finn.goto(100, 100) finn.goto(0, 100) finn.goto(0, 0) charlie = turtle.clone() charlie.penup() charlie.goto(200, 0) charlie.pendown() charlie.goto(400, 0) charlie.goto(300, 100) charlie.goto(200, 0) finn.goto(300, 300) finn.stamp() finn.goto(100, 300) turtle.clearstamps() turtle.mainloop()
def walk(t): global colordict if t.data == "end": sysexit(0) elif t.data == "movement": name, number = t.children { 'ileri': turtle.fd, 'geri': turtle.bk, 'sağ': turtle.lt, 'sol': turtle.rt, }[name](int(number)) elif t.data == "change_color": colors = list() for color in t.children: colors.append(colordict[color.strip()]) try: turtle.color(colors[0], colors[1]) except IndexError: turtle.color(colors[0]) elif t.data == "repeat": count, block = t.children for i in range(int(count)): walk(block) elif t.data == "fill": turtle.begin_fill() walk(t.children[0]) turtle.end_fill() elif t.data == "code_block": for cmd in t.children: walk(cmd) elif t.data == "tsleep": sleep(int(t.children[0])) elif t.data == "backg": turtle.bgcolor(colordict[t.children[0].strip()]) elif t.data == "tup": turtle.up() elif t.data == "tdown": turtle.down() elif t.data == "tspeed": turtle.speed(int(t.children[0])) elif t.data == "treset": turtle.reset() elif t.data == "sclear": # clear screen turtle.clearscreen() elif t.data == "tsize": turtle.pensize(int(t.children[0])) elif t.data == "stitle": turtle.title(t.children[0][1:-1]) elif t.data == "sresize": turtle.setup(int(t.children[0]), int(t.children[1])) elif t.data == "comment": pass # nothing to do with comments elif t.data == "tshape": shape = { "ok": "arrow", "kare": "square", "çember": "circle", "üçgen": "triangle", "klasik": "classic" }[t.children[0].strip()] turtle.shape(shape) elif t.data == "ev": turtle.home() elif t.data == "git": turtle.goto(int(t.children[0]), int(t.children[1])) elif t.data == "tauto": turtle.resizemode("auto") elif t.data == "tcircle": turtle.circle(int(t.children[0])) elif t.data == "tstamp": turtle.stamp() elif t.data == "tclearstamps": turtle.clearstamps()
def key_10(): t.clearstamps() disp_num(10)
def clearstamps(self, ): turtle.clearstamps()
def show_mean(self, x, y, confident=False): turtle.clearstamps() turtle.color("blue") turtle.shape("circle") turtle.setposition([x * self.mapScale, y * self.mapScale]) turtle.stamp()
def clearMaze(self): turtle.clearstamps()
def clear(self): turtle.clearstamps()