def hvezdicka(): turtle = MyTurtle('hvezdicka.svg') while True: turtle.forward(200) turtle.left(170) if abs(turtle.pos()[0]) < 1 and abs(turtle.pos()[1]) < 1: break
def triangleDrawer(startx, starty, length, head='top'): coordsList = [] descrTriangle = {} if head == 'top': head = 120 t.color("black","black") elif head == 'bottom': head = 240 t.color("white","white") t.setheading(0) t.penup() t.begin_fill() t.setpos(startx, starty) t.pendown() coordsList.append(t.pos()) t.forward(length) coordsList.append(t.pos()) t.setheading(head) t.forward(length) coordsList.append(t.pos()) if head == 120: t.left(120) else: t.right(120) t.forward(length) t.end_fill() descrTriangle['length'] = length descrTriangle['coord'] = coordsList return descrTriangle
def draw(): size = randint(40, 300) angles = (144, 150, 157.5, 160, 165) angle = sample(angles, 1)[0] colors = [ ('#922B21', '#E6B0AA'), ('#76448A', '#D2B4DE'), ('#1F618D', '#AED6F1'), ('#515A5A', '#EAEDED'), ('#148F77', '#D1F2EB'), ('#B7950B', '#F7DC6F'), ('#F39C12', '#FDEBD0'), ('#BA4A00', '#F6DDCC')] color = sample(colors, 1)[0] tt.color(color[0], color[1]) x_pos = randint(-200,200) y_pos = randint(-200,200) tt.pu() tt.setpos(x_pos, y_pos) start_position = tt.pos() tt.pd() tt.begin_fill() while True: tt.forward(size) tt.left(angle) if abs(tt.pos() - start_position) < 1: break tt.end_fill()
def binary_tree(depth, length, origin = (0,0) ): turtle.setposition(origin) if length == 0: return True turtle.right(30) turtle.pendown() turtle.forward(depth) right = turtle.pos() turtle.penup() turtle.bk(depth) turtle.right(120) turtle.pendown() turtle.forward(depth) turtle.penup() left = turtle.pos() turtle.bk(depth) turtle.left(150) binary_tree(depth/2, length-1, left) binary_tree(depth/2, length-1, right) return True
def updateParams(shape): global size, lastCount, affected, personList, multipleNotShown lastCount = lastCount+1 if(shape == 'Circle'): # will add less than the actual size's radius just # so that we can erase cleanly center = turtle.pos() xLow = center[0]-size*0.95 xHigh = center[0]+size*0.95 yLow = center[1]-size*0.95 yHigh = center[1]+size*0.95 for i in range(int(xLow), int(xHigh)): for j in range(int(yLow), int(yHigh)): pixelGrid[i,j] = lastCount # now add the female to personDict adding = [Person(1, affected, False, False, -1, 'none', 'none', -1, [], multipleNotShown), center, size] personList[lastCount] = adding elif(shape == 'Square'): center = turtle.pos() xLow = center[0]-size*0.95 xHigh = center[0]+size*0.95 yLow = center[1]-size*0.95 yHigh = center[1]+size*0.95 for i in range(int(xLow), int(xHigh)): for j in range(int(yLow), int(yHigh)): pixelGrid[i,j] = lastCount # now add the male to personDict adding = [Person(0, affected, False, False, -1, 'none', 'none', -1, [], multipleNotShown), center, size] personList[lastCount] = adding elif(shape == 'Diamond'): center = turtle.pos() xLow = center[0]-size*0.95 xHigh = center[0]+size*0.95 yLow = center[1]-size*0.95 yHigh = center[1]+size*0.95 for i in range(int(xLow), int(xHigh)): for j in range(int(yLow), int(yHigh)): pixelGrid[i,j] = lastCount adding = [Person(2, affected, False, False, -1, 'none', 'none', -1, [], multipleNotShown), center, size] personList[lastCount] = adding return adding[0]
def triangle_drawer(leftCornerCoord, sideSize, deep=5): cornersCoord = [] initAngle = 60 # если достигли дна, т.е. deep=0, то закрашиваем треугольник черным if deep > 1: color = 'white' else: color = 'black' turtle.color('black', color) turtle.begin_fill() turtle.penup() turtle.setpos(leftCornerCoord[0],leftCornerCoord[1]) turtle.pendown() turtle.setheading(initAngle) cornersCoord.append(leftCornerCoord) turtle.forward(sideSize) turtle.right(initAngle*2) cornersCoord.append(turtle.pos()) turtle.forward(sideSize) turtle.right(initAngle*2) cornersCoord.append(turtle.pos()) turtle.forward(sideSize) turtle.end_fill() return cornersCoord
def draw_tree(x,y): startPosX = x startPosY = y turtle.setpos(x,y) turtle.fillcolor("green") turtle.begin_fill() for i in range(0,4): x -=40 y -=80 turtle.goto(x,y) coords.append(turtle.pos()) x += 20 turtle.goto(x,y) bottomCorner = turtle.pos() x = startPosX y = startPosY turtle.setpos(x,y) for i in range(0,4): x +=40 y -=80 turtle.goto(x,y) coords.append(turtle.pos()) x -= 20 turtle.goto(x,y) turtle.goto(bottomCorner) turtle.end_fill()
def test_zigzag(self): """ Test that a AsyncTurtle ends up in the correct position after several concurrent commands in sequence, and draws a zigzag line on the canvas. """ turtle = AsyncTurtle(loop=self.loop) tasks = [ asyncio.ensure_future(turtle.fd(10), loop=self.loop), asyncio.ensure_future(turtle.lt(90), loop=self.loop), asyncio.ensure_future(turtle.fd(10), loop=self.loop), asyncio.ensure_future(turtle.rt(90), loop=self.loop), asyncio.ensure_future(turtle.fd(10), loop=self.loop) ] self.loop.run_until_complete(asyncio.wait(tasks, loop=self.loop)) self.loop.close() self.assertEqual(turtle.pos()[0], 20) self.assertEqual(turtle.pos()[1], 10) expected_coords = [ 0.0, 0.0, 10.0, 0.0, 10.0, -10.0, 20.0, -10.0 ] # Assume the last item id on the canvas is the line # drawn by the turtle. Check if this assumption is valid. line_id = max(turtle.screen.cv.find_all()) self.assertEqual(turtle.screen.cv.coords(line_id), expected_coords)
def radar_chart(data): # Some "typical" test data #print "Hello" length=len(data) # stores the length of the data provided turtle.home() # Sets the turtle to position (0,0) division=360/length #what angle is needed for invidual lines poslist=[] #list to store current position valpos=[] #list to store position j=0 turtle.hideturtle() #hides the arrow #Draw the foundation of the Radar Chart for i in range(length): # Loop until all the given data is plotted turtle.forward(200) #move turtle forward turtle.dot(10,"black") # Draw the black dot at the end of each data nowpos=turtle.pos() # store the current position poslist.append(nowpos) #append the current position to list #turtle.hideturtle() turtle.setpos(nowpos[0]+10,nowpos[1]) #get the turtle to new postion to write data turtle.write(data[i], True, align="center") # Write the label of data turtle.setpos(nowpos[0],nowpos[1]) #return to the previous position turtle.back(200) #return home turtle.left(division) # rotate by the specific angle turtle.home() # return to turtle home #Connect the ends points of the radar chart for i in poslist: # turtle.setpos(i[0],i[1]) #turtle.setpos(i[j],i[j+1]) #turtle.forward(100) #turtle.home() #turtle.degree(division) #turtle.heading() #turtle.forward(100) turtle.setpos(poslist[0][0],poslist[0][1]) turtle.home() #Draw green Dots for i in range(length): incval=data[i] turtle.forward(incval*2) turtle.dot(15,"green") nowpos=turtle.pos() valpos.append(nowpos) turtle.back(incval*2) turtle.left(division) turtle.begin_poly() turtle.fill(True) #Fill the green Dots for i in valpos: turtle.setpos(int(i[0]),int(i[1])) turtle.setpos(valpos[0][0],valpos[0][1]) turtle.end_poly() p = turtle.get_poly() turtle.register_shape("jpt", p) turtle.color("Green", "Green") turtle.begin_fill() #turtle.p(80) turtle.end_fill() turtle.fill(False)
def forward(d): while d != 0: def clamp(v): if (v>stmax): v = stmax return v dx = clamp(d) turtle.forward(dx) emb.addStitch(stitchcode.Point(turtle.pos()[0],turtle.pos()[1])) d -= dx
def reset(goal, turtle, info) : turtle.reset() turtle.clear() goal.reset() goal.clear() while True : goalPos=setGoal(goal) pos=turtle.pos() if(goalPos[0]<=pos[0]<=goalPos[0]+100 and goalPos[1]<=pos[1]<=goalPos[1]+100) : continue else : info["goalPos"]=goalPos info["tracks"]=[turtle.pos()] break
def connectFamily(parents, children, size, offset=0, color='blue'): origPosition = turtle.pos() origHead = turtle.heading() oldColor = turtle.pencolor() turtle.pencolor(color) turtle.penup() # parents are a tuple of positions for the parents # children are a tuple of positions of the children # all positions are from the center of each shape if(len(parents) == 2): # if we have 2 parents parentA = parents[0] parentB = parents[1] # draw horizontal line between parents turtle.goto(parentA) goDown(offset) goRight(size) turtle.pendown() goRight(parentB[0]-parentA[0]-2*size) goLeft((parentB[0]-parentA[0]-2*size)/2 + offset) goDown(2*size) else: # if unaffected mate == True parentA = parents[0] turtle.goto(parentA) goDown(size) turtle.pendown() goDown(offset) currentPosition = turtle.pos() for child in children: horizDist = currentPosition[0] - child[0] verticalDist = currentPosition[1] - child[1] - size goLeft(horizDist) goDown(verticalDist) turtle.penup() turtle.goto(currentPosition) turtle.pendown() turtle.penup() turtle.goto(origPosition) turtle.setheading(origHead) turtle.pencolor(oldColor) turtle.up()
def draw_move(turtle, cell_size, offset, domino, dx, dy, move_num, step_count): shade = (move_num-1) * 1.0/step_count rgb = (0, 1-shade, shade) turtle.forward((domino.head.x-offset[0]) * cell_size) turtle.left(90) turtle.forward((domino.head.y-offset[1]) * cell_size) turtle.right(90) turtle.setheading(domino.degrees) turtle.forward(cell_size*.5) turtle.setheading(math.atan2(dy, dx) * 180/math.pi) pen = turtle.pen() turtle.pencolor(rgb) circle_pos = turtle.pos() turtle.width(4) turtle.forward(cell_size*0.05) turtle.down() turtle.forward(cell_size*0.4) turtle.up() turtle.pen(pen) turtle.setpos(circle_pos) turtle.forward(8) turtle.setheading(270) turtle.forward(8) turtle.left(90) turtle.down() turtle.pencolor(rgb) turtle.fillcolor('white') turtle.begin_fill() turtle.circle(8) turtle.end_fill() turtle.pen(pen) turtle.write(move_num, align='center') turtle.up()
def draw_arrow(turtle, cell_size, rotation=0): pos = turtle.pos() turtle.left(rotation) turtle.back(cell_size*.2) turtle.down() turtle.left(90) turtle.begin_fill() turtle.forward(cell_size*.05) turtle.right(90) turtle.forward(cell_size*.3) turtle.left(90) turtle.forward(cell_size*.1) turtle.right(120) turtle.forward(cell_size*.3) turtle.right(120) turtle.forward(cell_size*.3) turtle.right(120) turtle.forward(cell_size*.1) turtle.left(90) turtle.forward(cell_size*.3) turtle.right(90) turtle.forward(cell_size*.05) turtle.right(90) turtle.forward(cell_size*.2) turtle.end_fill() turtle.up() turtle.setpos(pos) turtle.right(rotation)
def makeSquare(size, person=None, fill=False): origPosition = turtle.pos() origHead = turtle.heading() turtle.penup() goDown(size) if(person != None or fill == True): if(fill==True or person.affected): turtle.begin_fill() turtle.pendown() goLeft(size) goUp(2*size) goRight(2*size) goDown(2*size) goLeft(size) if(person != None or fill==True): if(fill==True or person.affected): turtle.end_fill() turtle.penup() turtle.goto(origPosition) turtle.setheading(origHead) if(person != None or fill==True): if(fill==True or person.affected): turtle.color('black') if(person.multipleNotShown == 0): turtle.write(str(person.name())+"\n"+probString(person), align="center") else: turtle.write(str(person.name())+"\n"+probString(person)+"\n\n"+str(person.multipleNotShown), align="center") turtle.color('blue') turtle.penup()
def makeDiamond(size, person=None, fill=False): origPosition = turtle.pos() origHead = turtle.heading() turtle.penup() goDown(size) turtle.pendown() if(person != None or fill==True): if(fill==True or person.affected): turtle.begin_fill() goNorthEast(2*size/np.sqrt(2)) goNorthWest(2*size/np.sqrt(2)) goSouthWest(2*size/np.sqrt(2)) goSouthEast(2*size/np.sqrt(2)) if(person != None or fill==True): if(fill==True or person.affected): turtle.end_fill() turtle.penup() turtle.goto(origPosition) turtle.setheading(origHead) if(person != None or fill==True): if(fill==True or person.affected): turtle.color('black') if(person.multipleNotShown == 0): turtle.write(str(person.name())+"\n"+probString(person), align="center") else: turtle.write(str(person.name())+"\n"+probString(person)+"\n\n"+str(person.multipleNotShown), align="center") turtle.color('blue') turtle.penup()
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초후
def main2(): windows = turtle.Screen() windows.bgcolor('green') bran = turtle.Turtle() tp = turtle.pos() bran.setpos(60,30) bran.setpos((20,80))
def draw_leaf(turtle): base = turtle.pos() turtle.begin_fill() turtle.circle(120,90) turtle.goto(base) turtle.circle(-120,90) turtle.goto(base) turtle.end_fill()
def draw_flower(turtle): base = turtle.pos() turtle.begin_fill() turtle.circle(100,100) turtle.goto(base) turtle.circle(-100,100) turtle.goto(base) turtle.end_fill()
def draw_pips(turtle, pips, cell_size): PIP_PATTERNS = """\ ---+ | | | ---+ | O | | ---+ O | | O| ---+ O | O | O| ---+ O O| | O O| ---+ O O| O | O O| ---+ OOO| | OOO| ---+ """ pip_pattern = PIP_PATTERNS.splitlines()[pips*4+1:pips*4+4] pip_radius = cell_size*0.09 turtle.up() pos = turtle.pos() turtle.back(pip_radius*5) turtle.left(90) turtle.forward(pip_radius*5) turtle.right(90) for i in range(3): turtle.forward(pip_radius*2) turtle.right(90) turtle.forward(pip_radius) turtle.left(90) for j in range(3): if pip_pattern[i][j] == 'O': turtle.down() turtle.begin_fill() turtle.circle(-pip_radius) turtle.end_fill() turtle.up() turtle.forward(pip_radius*3) turtle.back(pip_radius*11) turtle.right(90) turtle.forward(pip_radius*2) turtle.left(90) turtle.setpos(pos)
def serp_triangle_drawer(leftCornerCoord, sideSize, deep=5): initAngle = 60 triagDict = {} if deep > 0: triagDict['firstTriangleCoord'] = leftCornerCoord triangle_drawer(triagDict['firstTriangleCoord'], sideSize, deep) move_pointer(initAngle,sideSize) triagDict['secTriangleCoord'] = turtle.pos() triangle_drawer(triagDict['secTriangleCoord'], sideSize, deep) move_pointer(-initAngle,sideSize) triagDict['thirdTriangleCoord'] = turtle.pos() triangle_drawer(triagDict['thirdTriangleCoord'], sideSize, deep) for key in triagDict: serp_triangle_drawer(triagDict[key], sideSize/2, deep-1)
def star2(): Base((-200,150)) turtle.color('yellow', 'white') turtle.begin_fill() for x in range (1,10): turtle.fd(10) turtle.lt(150) if abs(turtle.pos()) < 1: break turtle.end_fill()
def drawStar(): #turtle.setheading(0) turtle.color('red', 'yellow') turtle.begin_fill() while True: turtle.forward(200) turtle.left(170) if abs(turtle.pos()) < 1: break turtle.end_fill()
def LOCATE( self, row=None, col=None ): """Row and Column are -- strictly speaking -- optional. If unspecified then we're moving horizontally or vertically only. """ x, y = turtle.pos() x, y = col*8 if col is not None else x, row*8 if row is not None else y turtle.penup() turtle.goto( x, y/self.aspect_v ) self.log.debug( "GOTO %r %r", x, y/self.aspect_v )
def demo(): turtle.color('blue', 'green') turtle.begin_fill() while True: turtle.forward(200) turtle.left(170) if abs(turtle.pos()) < 1: break turtle.end_fill() turtle.hideturtle() turtle.done()
def e_branch(self): global length global NewNodeQue turtle.up() turtle.setpos(self.NodePosition) turtle.down() turtle.setheading(self.GrowAngle) d = Node('d',self.NodePosition,self.GrowAngle) dNodeQue.put(d) turtle.left(angle) turtle.forward(length) a = Node('a',turtle.pos(),turtle.heading()) NewNodeQue.put(a) turtle.up() turtle.setpos(d.NodePosition) turtle.down() turtle.setheading(d.GrowAngle) turtle.forward(length) b = Node('b',turtle.pos(),turtle.heading()) NewNodeQue.put(b)
def up() : if(len(info["tracks"])==1) : turtle.clear() turtle.fd(100) pos=turtle.pos() info["tracks"].append(pos) if(info["goalPos"][0]<=pos[0]<=info["goalPos"][0]+100 and info["goalPos"][1]<=pos[1]<=info["goalPos"][1]+100) : info["point"]+=1 turtle.write("Done. Your point is "+str(info["point"])) time.sleep(2) reset(goal, turtle, info)
def draw_star(center_x, center_y, radius): print(center_x, center_y) turtle.pencolor('black') turtle.setpos(center_x, center_y) pt1 = turtle.pos() turtle.circle(-radius, 360 / 5) pt2 = turtle.pos() turtle.circle(-radius, 360 / 5) pt3 = turtle.pos() turtle.circle(-radius, 360 / 5) pt4 = turtle.pos() turtle.circle(-radius, 360 / 5) pt5 = turtle.pos() turtle.color('yellow', 'yellow') turtle.begin_fill() turtle.goto(pt3) turtle.goto(pt1) turtle.goto(pt4) turtle.goto(pt2) turtle.goto(pt5) turtle.end_fill()
def drawO(): '''contains all instructions on how to draw an O''' turtle.up() x = turtle.pos() turtle.forward(30) turtle.right(90) turtle.forward(15) turtle.left(90) turtle.down() turtle.circle(40) turtle.up() turtle.setposition(x)
def clear(): turtle.clearscreen() while True: turtle.update() move()#move function of turtle move2()#move function of cthr #turlte collide with cthr turtle.update() x=list(turtle.pos()) y=list(cthr.pos()) if math.fabs(x[0]-y[0])<33 and math.fabs(x[1]-y[1])<33: turtle.clearscreen() turtle.hideturtle() turtle.penup() turtle.bgcolor("grey") turtle.write("GAME OVER",align="Center",font=("MS Comic Sans",35)) turtle.backward(1) turtle.right(90) turtle.forward(40) turtle.write("click anywhere to exit",True,align="right",font=(10)) turtle.exitonclick()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Техническое задание: На основе цветочка из квадратов, сделанного в первой итерации, нарисовать картину из этого цветочка и солнышка. Солнышко такое как тут, подойдет https://docs.python.org/3.7/library/turtle.html В будущем ожидаю увидеть поле из разных цветов. Может, сделать цветок красивее. """ import turtle as t t.penup() t.speed(40) t.goto(-200, 200) a = abs(t.pos()) t.pendown() t.begin_fill() t.color('yellow') while True: t.forward(150) t.left(170) b = abs(t.pos()) if (a - 1 < b < a + 1): break t.end_fill() t.penup() def draw_rainbow(start_x, color): t.goto(start_x - 200, 0)
import turtle as t t.speed(0) size = 40 count = 5 linelength = count * size def line(start, end): t.penup t.goto(*start) t.pendown() t.goto(*end) x1, y1 = t.pos() x1, y2 = x1 + linelength, y1 + linelength for i in range(count + 1): n = i * size line((x1, n), (x2, n)) line((n, y1), (n, y2)) t.exitonclick()
def move_player(): my_pos = turtle.pos() x_pos = my_pos[0] y_pos = my_pos[1] x_ok = LEFT_EDGE <= x_pos <= RIGHT_EDGE y_ok = UP_EDGE >= y_pos >= DOWN_EDGE within_bounds = x_ok and y_ok if x_pos >= RIGHT_EDGE: turtle.goto(RIGHT_EDGE - 10, y_pos) if x_pos <= LEFT_EDGE: turtle.goto(LEFT_EDGE + 10, y_pos) if y_pos >= UP_EDGE: turtle.goto(x_pos, UP_EDGE + 10) if within_bounds: if direction == RIGHT: turtle.goto(x_pos + 10, y_pos) elif direction == LEFT: turtle.goto(x_pos - 10, y_pos) elif direction == UP: turtle.goto(x_pos, y_pos + 10) global my_clone if turtle.pos == my_clone.pos(): if direction == UP: turtle.goto(x_pos, y_pos + 10) ''' else: # x checks # right edge check if x_pos >= RIGHT_EDGE: if direction == LEFT: turtle.goto(x_pos - 10,y_pos) if x_pos <= LEFT_EDGE: if direction == RIGHT: turtle.goto(x_pos + 10,y_pos) if y_pos >= UP_EDGE: if direction == RIGHT: turtle.goto(x_pos + 10,y_pos) elif direction == LEFT: turtle.goto(x_pos - 10, y_pos) elif direction == DOWN: turtle.goto(x_pos, y_pos -10) if y_pos <= DOWN_EDGE: if direction == RIGHT: turtle.goto(x_pos + 10,y_pos) elif direction == LEFT: turtle.goto(x_pos - 10, y_pos) elif direction == UP: turtle.goto(x_pos, y_pos + 10) ''' global food, score #turtle.ontimer(move_player,TIME_STEP) if turtle.pos() in good_food_pos: good_food_ind = good_food_pos.index(turtle.pos()) food.clearstamp(good_food_stamps[good_food_ind]) good_food_stamps.pop(good_food_ind) good_food_pos.pop(good_food_ind) print('EATEN GOOD FOOD!') score = score + 1 turtle2.clear() turtle2.write(str(score)) good_food() if turtle.pos() in bad_food_pos: bad_food_ind = bad_food_pos.index(turtle.pos()) bad_food.clearstamp(bad_food_stamps[bad_food_ind]) bad_food_stamps.pop(bad_food_ind) bad_food_pos.pop(bad_food_ind) print('EATEN BAD FOOD!') score = score - 1 turtle2.clear() turtle2.write(str(score)) if score == -5: print('GAME OVER!') quit() bad_food1()
def moveToThirdSquare(turtle, size): x, y = turtle.pos() destination = (x - (size / 2)), (y - (size / 2)) turtle.setpos(destination)
t.onkeypress(right, "Right") t.onkeypress(left, "Left") t.onkeypress(up, "Up") t.onkeypress(down, "Down") t.listen() t.up() play() x = True score = 0 while x: play() te.up() ang = te.towards(t.pos()) te.setheading(ang) te.forward(4) if t.distance(ts) <= 10: print("먹었다") t.write("먹었다") score = score + 1 print(score) ts_x = r.randint(-240, 240) ts_y = r.randint(-240, 240) ts.up() ts.goto(ts_x, ts_y) if t.distance(te) <= 10: x = False
def maze_maker(): #TOP for i in range(7): turtle.stamp() turtle.forward(20) x_pos=turtle.pos()[0] y_pos=turtle.pos()[1] my_pos=(round(x_pos),round(y_pos)) pos_List_L.append(my_pos) new_stamp=turtle.stamp() stamp_list.append(new_stamp) turtle.forward(60) for i in range(20): turtle.forward(20) x_pos=turtle.pos()[0] y_pos=turtle.pos()[1] my_pos=(round(x_pos),round(y_pos)) pos_List_L.append(my_pos) new_stamp=turtle.stamp() stamp_list.append(new_stamp) #Right stamp_list_R=[] new_stamp_R=[] pos_List_R=[] turtle.right(90) ############ for i in range(23): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_R=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_R) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_R) ############ turtle.forward(60) for i in range(5): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_R=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_R) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_R) #Down stamp_list_D=[] new_stamp_D=[] pos_List_D=[] turtle.right(90) for i in range(30): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_D=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_D) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_D) #Left #stamp_list_L=[] new_stamp_L=[] #pos_List_L=[] turtle.right(90) for i in range(30): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.goto(-80,300) turtle.right(180) ##################################### for i in range(3): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(90) for i in range(8): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.goto(-300,180) turtle.right(180) for i in range(17): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(90) for i in range(3): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.left(90) for i in range(3): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.left(90) for i in range(6): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.left(90) for i in range(5): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(180) for i in range(5): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(90) for i in range(6): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.left(90) for i in range(4): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.left(90) for i in range(5): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(90) for i in range(2): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(180) for i in range(2): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.left(90) for i in range(6): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.left(90) for i in range(3): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.left(90) for i in range(3): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.goto(145,300) turtle.right(180) for i in range(1): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.goto(300,180) turtle.right(90) for i in range(1): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.goto(300,-160) for i in range(3): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(90) for i in range(7): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.left(90) for i in range(6): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(90) for i in range(4): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(180) for i in range(4): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.left(90) for i in range(3): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(90) for i in range(9): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(180) for i in range(9): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.left(90) for i in range(11): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(90) for i in range(3): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(90) for i in range(3): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(180) for i in range(3): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(90) for i in range(3): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.left(90) for i in range(6): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.goto(-300,40) turtle.right(180) for i in range(7): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.goto(300,-220) turtle.right(180) for i in range(3): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.left(90) for i in range(2): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(90) for i in range(7): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.right(90) for i in range(8): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.left(90) for i in range(8): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.left(90) for i in range(6): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.goto(-40,-20) turtle.right(90) for i in range(5): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.goto(-300,-80) turtle.right(180) for i in range(6): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L) turtle.goto(-120,-20) turtle.right(90) for i in range(8): turtle.stamp() turtle.forward(20) x_pos_L=turtle.pos()[0] y_pos_L=turtle.pos()[1] my_pos_L=(round(x_pos_L),round(y_pos_L)) pos_List_L.append(my_pos_L) new_stamp_L=turtle.stamp() stamp_list_L.append(new_stamp_L)
pt3 = t.pos() t.circle(-radius, 360 / 5) pt4 = t.pos() t.circle(-radius, 360 / 5) pt5 = t.pos() t.color('yellow', 'yellow') t.begin_fill() t.goto(pt3) t.goto(pt1) t.goto(pt4) t.goto(pt2) t.goto(pt5) t.end_fill() print(t.pos()) t.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 t.setpos(center_x, center_y) # big star center t.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 t.goto(star_part_x + star_part_s * 10, star_part_y - star_part_s * 2) # go to 1st small star center
def up(): old_pos = turtle.pos() x = old_pos[0] y = old_pos[1] turtle.goto(x, y + 10) print(turtle.pos())
tt.speed(0) # 可以調整size和multi的數字 # size不要太大,盡量在300以內 # multi要是整數 size = 100 multi = 3 angle = 360 / size pos_list = [] tt.left(90 + angle / 2) for i in range(size): tt.pendown() # 記錄經過的點的位置 # pos()函數會回傳一組座標 pos_list.append(tt.pos()) tt.right(angle) tt.forward(1000 / size) tt.penup() print(pos_list) for i in range(size): tt.goto(pos_list[i]) tt.pendown() # 看影片就知道為什麼了>< # https://youtu.be/qhbuKbxJsk8 next = (i*multi) % size tt.goto(pos_list[next]) tt.penup() tt.goto(pos_list[0]) tt.done()
def rcol(): return random()/2.+0.5, random()/2.+0.5, random()/2.+0.5 if __name__ == '__main__': t.Screen() t.Screen().bgcolor("navy") t.speed(0) t.hideturtle() t.up() t.sety(-300) t.left(90) t.down() base = t.pos() for i in range(1): t.setheading(90) draw_arc(randint(100,300), randint(5,10), choice(['l', 'r']), [rcol()]) draw_arc(randint(100,300), randint(2,6), choice(['l', 'r']), [rcol()]) top = t.pos() for i in range(randint(10,15)): t.up() t.goto(top) t.setheading(randint(0,359)) t.down() draw_arc(randint(20,30), randint(10,20), choice(['l', 'r']), [rcol()])
speed=[1,2,3] turtle0=turtle.Turtle() turtle1=turtle.Turtle() turtle2=turtle.Turtle() turtle2.color(color[2]) turtle_list=[turtle0,turtle1,turtle2] for i in range(3): turtle_list[i].color(color[i]) turtle_list[i].penup() turtle_list[i].goto(-160, 100*i) turtle_list[i].pendown() for turtle in turtle_list: turtle.shape('turtle') from random import randint for movement in range(100): for turtle in turtle_list: speed=randint(1,5) turtle.forward(speed) for turtle in turtle_list: print(turtle.pos(),turtle.color()) # In[ ]:
print('тЈ│Уђ?') t.seth(40) #t.circle(-250,52) t.circle(-250, 30) infoPrt() # тЈ│Уђ│т░ќ t.begin_fill() # ти? t.circle(-250, 22) #t.fillcolor("pink") # тЈ? t.seth(227) t.circle(-270, 15) prePos = t.pos() infoPrt() # СИ? t.seth(105) t.circle(100, 32) t.end_fill() t.pu() t.setpos(prePos) t.pd() t.seth(212) t.circle(-270, 28) prePos = t.pos() t.pu() t.goto(t.xcor() + 5, t.ycor() - 2)
from sys import exit import turtle as t from random import randint, choice colors = ('blue', 'red', 'green', 'yellow') t.speed('fastest') t.pensize(20) while True: t.color(choice(colors)) t.fd(randint(20, 200)) t.rt(randint(-45, 45)) if abs(t.pos()[0]) > 500 or abs(t.pos()[1]) > 500: t.setpos((randint(-100, 100), (randint(-100, 100))))
def infoPrt(): print('coordinate: ' + str(t.pos())) print('angle: ' + str(t.heading()))
#绘制五角星 import turtle import time turtle.fillcolor("red") turtle.begin_fill() while True: turtle.forward(200) turtle.right(144) if abs(turtle.pos()) < 1: break turtle.end_fill()
def draw(): for letter in TEXT: if letter == 'C': draw_C(turtle.pos()[0], turtle.pos()[1]) elif letter == 'e': draw_e(turtle.pos()[0], turtle.pos()[1]) elif letter == 'g': draw_g(turtle.pos()[0], turtle.pos()[1]) elif letter == 'h': draw_h(turtle.pos()[0], turtle.pos()[1]) elif letter == 'i': draw_i(turtle.pos()[0], turtle.pos()[1]) elif letter == 'J': draw_J(turtle.pos()[0], turtle.pos()[1]) elif letter == 'n': draw_n(turtle.pos()[0], turtle.pos()[1]) elif letter == 'o': draw_o(turtle.pos()[0], turtle.pos()[1]) elif letter == 't': draw_t(turtle.pos()[0], turtle.pos()[1]) elif letter == ' ': draw_space(turtle.pos()[0], turtle.pos()[1])
screen.bgcolor('light blue') # initial vars turtle.goto(0, -200) good_food_pos = [] bad_food_pos = [] good_food_stamps = [] bad_food_stamps = [] box_stamps = [] box_pos = [] turtles_list = [] SIZE_X = 500 SIZE_Y = 500 turtle.setup(500, 500) player_size = 10 my_pos = turtle.pos() x_pos = my_pos[0] y_pos = my_pos[1] UP_EDGE = 200 DOWN_EDGE = -200 RIGHT_EDGE = 200 LEFT_EDGE = -200 UP_ARROW = 'Up' LEFT_ARROW = 'Left' DOWN_ARROW = 'Down' RIGHT_ARROW = 'Right' TIME_STEP = 100 TIME_STEP2 = 10000 SPACEBAR = 'space'
import turtle as t t.color("red", "yellow") t.begin_fill() while True: t.forward(200) t.left(170) if abs(t.pos()) < 1: break t.end_fill() t.done()
def move_player(): my_pos = turtle.pos() x_pos = my_pos[0] y_pos = my_pos[1] # check boundaries x_ok = LEFT_EDGE <= x_pos <= RIGHT_EDGE y_ok = UP_EDGE >= y_pos >= DOWN_EDGE within_bounds = x_ok and y_ok # pseudo bounce back on edges ## if x_pos >= RIGHT_EDGE: ## turtle.goto(RIGHT_EDGE -20, y_pos) ## if x_pos <= LEFT_EDGE: ## turtle.goto(LEFT_EDGE + 20, y_pos) ## if y_pos >= UP_EDGE: ## turtle.goto(x_pos, UP_EDGE - 20) ## if y_pos >= DOWN_EDGE: ## turtle.goto(x_pos, DOWN_EDGE +20) ## if turtle.pos()[0] == RIGHT_EDGE: ## turtle.goto(RIGHT_EDGE -10,y_pos) ## if turtle.pos()[0] == LEFT_EDGE: ## turtle.goto(LEFT_EDGE + 10,y_pos) if within_bounds: if direction == RIGHT: turtle.goto(x_pos + 10, y_pos) elif direction == LEFT: turtle.goto(x_pos - 10, y_pos) elif direction == UP: turtle.goto(x_pos, y_pos + 10) elif direction == DOWN: turtle.goto(x_pos, y_pos - 10) global my_clone if turtle.pos == my_clone.pos(): if direction == UP: turtle.goto(x_pos, y_pos + 10) #if turtle.pos() == my_clone.pos(): global food, score #turtle.ontimer(move_player,TIME_STEP) if turtle.pos() in good_food_pos: good_food_ind = good_food_pos.index(turtle.pos()) food.clearstamp(good_food_stamps[good_food_ind]) good_food_stamps.pop(good_food_ind) good_food_pos.pop(good_food_ind) print('EATEN GOOD FOOD!') score = score + 1 turtle2.clear() turtle2.write(str(score), font=("Aerial", 24, "normal")) good_food() if turtle.pos() in bad_food_pos: bad_food_ind = bad_food_pos.index(turtle.pos()) bad_food.clearstamp(bad_food_stamps[bad_food_ind]) bad_food_stamps.pop(bad_food_ind) bad_food_pos.pop(bad_food_ind) print('EATEN BAD FOOD!') score = score - 1 turtle2.clear() turtle2.write(str(score), font=("Aerial", 24, "normal")) if score == -5: print('GAME OVER!') quit() bad_food1()
q = [] def restore(): pos, angl = q.pop() turtle.up() turtle.setposition(pos) turtle.seth(angl) turtle.down() methods = { 'F': lambda: turtle.fd(3), '-': lambda: turtle.left(25), '+': lambda: turtle.right(25), '[': lambda: q.append((turtle.pos(), turtle.heading())), ']': restore, } turtle.screensize(800, 1200) turtle.ht() turtle.pencolor('green') turtle.delay(0) turtle.seth(75) for c in plantL[6]: try: methods[c]() except KeyError: pass ts = turtle.getscreen()
turtle.hideturtle() #Draw a snake at the start of the game with a for loop #for loop should use range() and count up to the number of pieces #in the snake (i.e. START_LENGTH) for i in range(START_LENGTH): x_pos=snake.pos()[0] #Get x-position with snake.pos()[0] y_pos=snake.pos()[1] #Add SQUARE_SIZE to x_pos. Where does x_pos point to now? # You're RIGHT! x_pos+=SQUARE_SIZE my_pos=(x_pos,y_pos) #Store position variables in a tuple snake.goto(my_pos) #Move snake to new (x,y) #Append the new position tuple to pos_list pos_list.append(turtle.pos()) #Save the stamp ID! You'll need to erase it later. Then append # it to stamp_list. stamp_id= snake.stamp() stamp_list.append(stamp_id) ############################################################### # PART 2 -- READ INSTRUCTIONS!! ############################################################### UP_ARROW = "Up" #Make sure you pay attention to upper and lower #case LEFT_ARROW = "Left" #Pay attention to upper and lower case DOWN_ARROW = "Down" #Pay attention to upper and lower case RIGHT_ARROW = "Right" #Pay attention to upper and lower case
a1a = turtle.Turtle() a2a = turtle.Turtle() a3a = turtle.Turtle() #import turtles color = ['blue', 'green', 'red'] #colors turtle_list = [a1a, a2a, a3a] for i in range(3): turtle_list[i].color(color[i]) turtle_list[i].penup() turtle_list[i].goto(-160, 100 * i) turtle_list[i].pendown() #setup raceand setup list pos = turtle_list[0].pos() print(pos) #show start pos from random import randint for movement in range(100): for turtle in turtle_list: speed = randint(1, 5) turtle.forward(speed) for turtle in turtle_list: print(turtle.pos()) #race starting and end pos
## [turtle] import turtle turtle.shape( 'turtle') # задать форму черепашки (arrow, turtle, circle, square) turtle.pensize(5) # задтать толщину линии turtle.pencolor('blue') # цвет линии turtle.bgcolor('yellow') # цвет фона turtle.speed(1) turtle.delay(100) turtle.forward(100) # перемещение вперед на 100 пикселей turtle.penup() # поднять перо turtle.forward(50) pos = turtle.pos() # получить текущие координаты x = pos[0] y = pos[1] print('x =', x, ' y =', y) turtle.pendown() # опустить перо turtle.forward(100) turtle.left(90) # поворот влево на 90 град turtle.forward(100) turtle.right(45) # поворот вправо на 90 град turtle.backward(100) # двигаться назад на 100 пикселей turtle.home() # переместиться в точку с координатами (0, 0) turtle.goto(-100,
def make_bodice_box(full_bust): box_len = (full_bust / 2) # top_right corner turtle.up() turtle.goto((-box_len), (nape_to_waist + cm)) back_line_top = turtle.pos() turtle.down() # top_left corner turtle.goto(box_len, (nape_to_waist + cm)) front_line_top = turtle.pos() turtle.up() # bottom_right corner turtle.goto((-box_len), waistline) turtle.down() waistline_front = turtle.pos() # bottom_left corner turtle.goto(box_len, waistline) waistline_back = turtle.pos() # top left to bottom left turtle.goto(waistline_back) turtle.goto(front_line_top) turtle.up() # top rt to bottom rt turtle.goto(back_line_top) turtle.down() turtle.goto(waistline_front) # neckline on backline turtle.goto(back_line_top) turtle.color("red") turtle.goto((-box_len), nape_to_waist) backline_neckline = turtle.pos() backline_x = turtle.xcor() # from backline, sq off 1/5 neck_cir on top turtle.up() turtle.goto(back_line_top) turtle.seth(east) turtle.down() turtle.forward(neck_cir / 5) back_shoulder_neckline = turtle.pos() # from back_shoulder_neckline, measure out 10cm to make the back_shoulder_slope turtle.up() turtle.forward(shoulder_len) turtle.seth(south) turtle.forward(cm) back_shoulder_slope_point = turtle.pos() back_shoulder_slope = turtle.heading() turtle.down() turtle.color("blue") # draw shoulder slope, line may need to be extended to match shoulder measurement turtle.goto(back_shoulder_neckline) # draw back neckline turtle.color("red") turtle.up() turtle.goto(backline_neckline) turtle.down() turtle.seth(east) this_far = (neck_cir / 6) turtle.forward(this_far) turtle.circle(20, 55) # mark out center_front_neckline turtle.up() turtle.goto(front_line_top) turtle.seth(south) turtle.down() turtle.forward((neck_cir / 5)) # shoulder_front_neckline turtle.up() turtle.goto(front_line_top) turtle.seth(west) turtle.down() turtle.forward((neck_cir / 5)) shoulder_front_neckline = turtle.pos() # draw in front neck line turtle.goto(shoulder_front_neckline) turtle.seth(south) turtle.circle((neck_cir / 5), 90) # front_shoulder_dart turtle.up() turtle.goto(shoulder_front_neckline) shoulder_dart = ((full_bust - front_width - back_width) / 3) turtle.color("yellow") turtle.seth(east) turtle.forward(shoulder_dart) outer_leg_shoulder_dart = turtle.pos() turtle.backward(shoulder_dart / 2) midpoint_shoulder_dart = turtle.pos() turtle.color("blue") turtle.up() turtle.goto(midpoint_shoulder_dart) turtle.seth(south) turtle.down() turtle.forward((nape_to_waist + cm)) turtle.color("green") turtle.bk(bust_height) shoulder_dart_bustline = turtle.pos() turtle.color("orange") shoulder_dart_point = turtle.pos() turtle.goto(shoulder_front_neckline) turtle.up() turtle.goto(outer_leg_shoulder_dart) turtle.down() turtle.goto(shoulder_dart_point) turtle.forward(cm) front_dart_point = turtle.pos() front_dart_point_x = turtle.xcor() turtle.goto(front_dart_point_x, waistline) front_dart_midpoint = turtle.pos() # front shoulder turtle.up() turtle.goto(back_shoulder_slope_point) turtle.seth(south) turtle.forward(cm) # turtle.down() turtle.color("grey") # guide @ back shoulder - grey_line = guide from back shoulder to front shoulder grey_line_start = turtle.pos() grey_line_start_x = turtle.xcor() grey_line_start_y = turtle.ycor() # guide @ front shoulder front_shoulder_slope = turtle.heading() turtle.goto(outer_leg_shoulder_dart) grey_line_end = turtle.pos() grey_line_end_x = turtle.xcor() grey_line_end_y = turtle.ycor() turtle.seth(west) turtle.up() turtle.forward(shoulder_len) turtle.seth(south) turtle.forward(30) # blue line = front shoulder guide blue_line_pt = turtle.pos() blue_line_pt_x = turtle.xcor() blue_line_pt_y = turtle.ycor() front_shoulder_intersect = ( (grey_line_end_y - grey_line_start_y) * (blue_line_pt_x - grey_line_start_x) / (grey_line_end_x - grey_line_start_x)) + (grey_line_start_y) round(front_shoulder_intersect) turtle.goto(blue_line_pt_x, front_shoulder_intersect) turtle.down() turtle.goto(outer_leg_shoulder_dart) turtle.color("green") # sq off front armhole @ shoulder turtle.up() turtle.goto(blue_line_pt_x, front_shoulder_intersect) turtle.down() turtle.forward(15) front_shoulder_sq_down = turtle.pos() # sq off back armhole @ shoulder turtle.up() turtle.goto(back_shoulder_slope_point) turtle.setheading(south) turtle.down() turtle.forward(15) back_shoulder_sq_down = turtle.pos() # on bustline, mark out 1/2 front_width + 1/2 dart turtle.up() turtle.goto(front_line_top) turtle.seth(west) turtle.forward(((front_width / 2) + (front_waist_dart / 2))) # front_side_guide front_side_guide_x = turtle.xcor() front_side_guide_y = turtle.ycor() turtle.seth(south) turtle.down() turtle.forward((nape_to_waist + cm)) # on bustline, mark out 1/2 back_width turtle.up() turtle.goto(back_line_top) turtle.seth(east) turtle.forward((back_width / 2)) back_side_guide_x = turtle.xcor() back_side_guide_y = turtle.ycor() turtle.seth(south) turtle.down() turtle.forward((nape_to_waist + cm)) # find and mark midpoint of front_side_guide and back_side_guide at bust_height- doesnt work as a function turtle.up() side_seam_guide = (((front_side_guide_x + back_side_guide_x) / 2), ((armhole_height + armhole_height) / 2)) turtle.goto(side_seam_guide) side_dart_point = turtle.pos() turtle.seth(south) turtle.down() turtle.forward(armhole_height) side_dart_midpoint = turtle.pos() # divide back section in half, mark from bust_height to waistline turtle.up() turtle.goto(backline_x, bust_height) backline_y = turtle.ycor() back_dart_guide = (((back_side_guide_x + backline_x) / 2), ((backline_y + backline_y) / 2)) turtle.goto(back_dart_guide) back_dart_point = turtle.pos() turtle.seth(south) turtle.down() turtle.forward(bust_height) back_dart_midpoint = turtle.pos() # back armhole_height/3 at back_side_guide_x turtle.up() # changed from bust height to armhole turtle.goto(back_side_guide_x, armhole_height) back_armhole_ref = turtle.pos() turtle.seth(north) turtle.down() turtle.color("red") # turtle.forward((armhole_height/3)) turtle.forward((armhole_height / 4)) back_armhole_notch = turtle.pos() # front armhole_height/4 front_side_guide_x turtle.up() # changed from bust height to armhole turtle.goto(front_side_guide_x, armhole_height) front_armhole_ref = turtle.pos() turtle.seth(north) turtle.down() # turtle.forward((armhole_height/4)) turtle.forward((armhole_height / 5)) front_armhole_notch = turtle.pos() # from back_armhole_ref draw a 2.5 cm diagonal line turtle.up() turtle.goto(back_armhole_ref) turtle.seth(((north + east) / 2)) turtle.down() turtle.forward(an_inch) back_armpit_notch = turtle.pos() # front_armhole_ref draw a 2 cm diagonal line turtle.up() turtle.goto(front_armhole_ref) turtle.seth(((north + west) / 2)) turtle.down() turtle.forward(two_cm) front_armpit_notch = turtle.pos() # connecting back armhole turtle.color("grey") turtle.up() turtle.goto(back_shoulder_sq_down) turtle.down() turtle.goto(back_armhole_notch) turtle.goto(back_armpit_notch) turtle.goto(side_dart_point) # connecting front armhole turtle.up() turtle.goto(front_shoulder_sq_down) turtle.down() turtle.goto(front_armhole_notch) turtle.goto(front_armpit_notch) turtle.goto(side_dart_point) # difference = (full_bust/2) - (waist_cir/2) # back_waist_dart = (difference/3) turtle.up() turtle.color("gold") turtle.goto(back_dart_midpoint) turtle.seth(west) turtle.forward(back_waist_dart / 2) turtle.down() turtle.goto(back_dart_point) turtle.goto(back_dart_midpoint) turtle.seth(east) turtle.forward(back_waist_dart / 2) turtle.goto(back_dart_point) # front_waist_dart = (back_waist_dart - cm) turtle.up() turtle.goto(front_dart_midpoint) turtle.seth(west) turtle.forward(front_waist_dart / 2) turtle.down() turtle.goto(front_dart_point) turtle.goto(front_dart_midpoint) turtle.seth(east) turtle.forward(front_waist_dart / 2) turtle.goto(front_dart_point) # side_waist_dart = (back_waist_dart + cm) turtle.up() turtle.goto(side_dart_midpoint) turtle.seth(west) turtle.forward(side_waist_dart / 2) turtle.down() turtle.goto(side_dart_point) turtle.goto(side_dart_midpoint) turtle.seth(east) turtle.forward(side_waist_dart / 2) turtle.goto(side_dart_point)
ime = input('we welcome you to the trustless_truth_foundation') ime = input('would you like to learn more about our project?:') ime = input('decentralize the parent\nchild relationship') ime = input('draconian interference produces tomorrows terrorists') import turtle t = turtle tp = turtle.pos() turtle.setpos(11, 15) t.home() t.dot() t.fd(06.03) t.dot(14, 'blue') t.fd(80) t.color('pink') t.stamp() t.fd(111.5) t.left(80) t.fd(31.4) t.left(80) t.fd(111.5) t.goto(0, 0) t.pen(fillcolor='blue', pencolor='blue', pensize=11) sorted(t.pen().items()) [('fillcolor', 'blue'), ('outline', 1), ('pencolor', 'purple'), ('pendown', True), ('pensize', 14), ('resizemode', 'noresize'), ('shearfactor', 0.0), ('shown', True), ('speed', 9), ('stretchfactor', (1.0, 1.0)), ('tilt', 0.0)] penstate = turtle.pen() t.color('blue', '') t.penup()
# sets a tuple of possible colors colors = ("#ffffff", "#80dfff", "#ffffff", "#ffffff", "#ffffff", "#ffa366", "#ffffff", "#ffffff", "#ff6666", "#ffff66", "#ffffff", "#ffffff") # set speed to maximum t.speed(0) # hide turtle to increase speed of draw t.ht() # starts random star generation with preference towards the middle for i in range(450): t.up() # lifts the pen # checks if the curser has wandered too far from the middle if t.pos()[0] > 350 or t.pos()[0] < -350 or t.pos()[1] > 335 or t.pos( )[1] < -335: t.home() t.right(random.randint(-360, 360)) # resets move distance for each iteration move = 0 # checks if move distance is too small so the random move is a nice distance while move < 45 and move > -45: move = random.randint(-120, 120) t.forward(move) t.down() # puts the pen down to draw the dot # randomizes the color of the star t.pencolor(colors[random.randint(0, 11)])
def play(): t.fd(10) ang = te.towards(t.pos()) te.seth(ang) te.fd(9)
Python 3.6.8 (default, Jan 14 2019, 11:02:34) [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux Type "help", "copyright", "credits" or "license()" for more information. >>> Python 3.6.8 (default, Jan 14 2019, 11:02:34) [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux Type "help", "copyright", "credits" or "license()" for more information. >>> import turtle >>> print(turtle.pos()) (0.00,0.00) >>> print(type(turtle.pos())) <class 'turtle.Vec2D'> >>> one = [1,2,3,4] >>> two = [7,6,5,4] >>> one.reverse() >>> print(one) [4, 3, 2, 1] >>> one.sort() >>> print(one) [1, 2, 3, 4] >>> one.remove(4) >>> print(one) [1, 2, 3] >>> three = [3] >>> four = three*3 >>> print(four) [3, 3, 3] >>> five = one.copy() >>> one.sort() >>> print(one) [1, 2, 3] >>> print(five)
def save(): pos.append(t.pos()) angle.append(t.heading())