def erase_block(): """ Erases the block placed by stamp_block(). """ ## HINT global STAMP_ID t.clearstamp(STAMP_ID)
def erase_rectangle(): """ Erases big_rectangle. """ global STAMP_IDs for stamp in STAMP_IDs: t.clearstamp(stamp)
def initalizeShape(): # Shape preferences: gui.shape("circle") gui.shapesize(1, 1) gui.color("black") # Create a temporary stamp to assign proceding stamps the shape of a circle: tStamp = gui.stamp() gui.clearstamp(tStamp)
def flashing_block(): global STAMP_ID global BLOCK_POS t.clearstamp(STAMP_ID) nx,ny = BLOCK_POS t.setpos(nx,ny) STAMP_ID = t.stamp() t.ontimer(flashing_block,100)
def drawPlayerAt(col, row, Player, stampID): turtle.clearstamp(stampID) if Player == "A": jumpto(OX + col*BOX_X+5, OY + row*BOX_Y + BOX_Y - 5) turtle.color("red") return turtle.stamp() else: jumpto(OX + col*BOX_X+BOX_X-5, OY + row*BOX_Y + BOX_Y - 5) turtle.color("blue") return turtle.stamp()
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 draw_player(): global player_stamp, score font.clear() font.ht() font.setpos(-70, 220) font.color("white") font.write("Score: " + str(score), font=("Terminal", 16, "normal")) turtle.clearstamp(player_stamp) turtle.setpos(player_pos) turtle.shape('square') turtle.color('red') player_stamp = turtle.stamp()
def reset(): global tracks, track_stamps, player_pos, player_stamp, score, game_over turtle.clearstamp(player_stamp) clear_track() game_over = False score = 0 player_pos = [0, 0] player_stamp = -1 tracks = [] track_stamps = [] for i in range(21): tracks.append({'position': [0, 200 - i * 20], 'width': 150})
def left_block(): ''' Makes a block move to the left, until it disappears off the screen ''' global STAMP_ID global BLOCK_POS t.clearstamp(STAMP_ID) BLOCK_POS = (BLOCK_POS[0] - 10,BLOCK_POS[1]) nx,ny = BLOCK_POS t.setpos(nx,ny) STAMP_ID = t.stamp() t.ontimer(left_block,100)
def main(): turtle.bgcolor("black") turtle.color("white") steps = 0 while True: print( "1. Move forward\n2. Move back\n3. Move right\n4. Move left\n5. Set position\n6. Make circle\ \n7. Make stamp\n8. Delete stamp\n9. Get current positon\n10. Clear\n11. Exit" ) ch = input("Enter your choice ") if ch == 1: steps = input("Enter steps to go forward ") turtle.forward(steps) elif ch == 2: steps = input("Enter steps to go back ") turtle.backward(steps) elif ch == 3: angle = input("Enter angle to turn right ") turtle.right(steps) elif ch == 4: angle = input("Enter angle to turn left ") turtle.left(steps) elif ch == 5: x, y = input("Enter co-ordinates(x,y) to move the turtle to ") turtle.goto(x, y) elif ch == 6: radius = input("Enter radius for circle ") turtle.circle(radius) elif ch == 7: s_id = turtle.stamp() print s_id elif ch == 8: s_id = input("Enter the stamp id to delete ") turtle.clearstamp(s_id) elif ch == 9: x, y = turtle.pos() print(x, y) elif ch == 10: turtle.clear() elif ch == 11: break else: print("Invalid choice")
def draw_player(): global player_stamp, score font.clear() font.ht() font.setpos(-70, -300) font.color("Red") font.write("Score: " + str(score), font=("Terminal", 16, "normal")) font.setpos(-70, -320) font.write("Level: " + str(int(math.log10(score) * int(difficulty))), font=("Terminal", 16, "normal")) turtle.clearstamp(player_stamp) turtle.setpos(player_pos) turtle.shape('square') turtle.color('yellow') player_stamp = turtle.stamp()
def main(): windows = turtle.Screen() windows.bgcolor('orange') bran = turtle.Turtle() bran.shape('turtle') bran.color('blue') astamp = turtle.stamp() turtle.fd(50) bran.speed(1) bran.circle(120,720) for i in range(1,10): bran.forward(100) bran.right(90) bran.forward(150) bran.right(90) bran.forward(150) bran.right(90) turtle.clearstamp(astamp)
def controlled_block(DIRECTION): ''' Moves a block directly left, right, up, or down from where it was before, depending on DIRECTION ''' global STAMP_ID global BLOCK_POS t.clearstamp(STAMP_ID) if DIRECTION == 0: #move up BLOCK_POS = (BLOCK_POS[0],BLOCK_POS[1]+20) elif DIRECTION == 1: #move down BLOCK_POS = (BLOCK_POS[0],BLOCK_POS[1]-20) elif DIRECTION == 2: #move left BLOCK_POS = (BLOCK_POS[0] - 20,BLOCK_POS[1]) elif DIRECTION == 3: #move right BLOCK_POS = (BLOCK_POS[0]+20,BLOCK_POS[1]) nx,ny = BLOCK_POS t.setpos(nx,ny) STAMP_ID = t.stamp()
def clear_track(): global track_stamps for track in track_stamps: turtle.clearstamp(track) track_stamps = []
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: botmove(j[0], j[1]) v = j if (k % 2 == 0): tr.clearstamp(stamps[v]) e = v elif (k % 2 == 1): u = tr.stamp() tr.ht() tr.color('brown', 'brown') tr.shape('square') tr.shapesize(1.7, 1.7, 1.7) goto(p4[e][0], p4[e][1]) tr.stamp() goto(v[0], v[1]) #tr.clearstamp(u) k += 1
steps = 5 turtle.circle(radius, extent, steps) # Draws a circular dat with a specified diameter using a specified color # If the size is not given, the maximum of pensize+4 and 2*pensize is used (pensize default is 1) # The diameter has to be greater than or equal to 1 # The color can be a string or a numeric color tuple turtle.dot(10, "green") # Stamps a copy of the turtle's shape onto the picutre/canvas as the turtle's current position # It returns a stamp ID for that specific stamp, which can be used to delete it turtle.stamp() # Deletes a specified stamp using it's attributed stamp ID stampID = 5 turtle.clearstamp(stampID) # Deletes all turtle stamps # If there is no parameter (a number), then it deletes all stamps # If there is a positive parameter, it deletes the first 'n' stamps # If there is a negative parameter, it deltes the last 'n' stamps turtle.clearstamps() # Undoes the the turtle's last action turtle.undo() # Set's the turtle's speed between 0 and 10 # If the speed is 0, then there is no drawing animation # If the inputed speed is greater than 10 or less than .5, then speed is set to 0 # If there is no inputed speed, then it returns the current speed value # You can also use speed strings: fastest = 0, fast = 10, normal = 6, slow = 3, slowest = 1
import turtle window = turtle.Screen() window.bgcolor("red") def draw_helena(): turtle.color("blue") astamp = turtle.stamp() turtle.fd(50) turtle.position() (200.00,-0.00) turtle.clearstamp(astamp) turtle.position() (200.00,-0.00) for i in range(1,38): for i in range(1,5): turtle.forward(100) turtle.right(90) for i in range(1,2): turtle.right(10) window.exitonclick() draw_helena()
def handle_click(x, y): # handle the click functions global tree global bird_clone if(x >= -10.0 and x<= 10.0 and y >= 360.0 and y<= 386.0): # check whether tree radio button clicked print('inside tree click') turtle.clearstamp(bird_clone[0]) # delete the top left corner bird tree = True turtle.stamp() turtle.shape('arrow') turtle.penup() turtle.home() turtle.pendown() draw_circle(0, 370, 10, 0, 'green') # draw radio button draw_circle(100, 370, 10, 0, 'white') # draw radio button if (x >= 90.0 and x <= 110.0 and y >= 360.0 and y <= 386.0): # check whether bird radio button clicked print('inside bird click') draw_circle(0, 370, 10, 0, 'white') # draw radio button draw_circle(100, 370, 10, 0, 'green') # draw radio button turtle.penup() pos_x = -340 pos_y = 370 turtle.setpos(pos_x, pos_y) turtle.pendown() tree = False turtle.register_shape('bird', ((-22, -39), (-20, -7), (-7, 3), (-11, 7), (-12, 9), (-11, 10), (-9, 10), (-3, 7), (10, 24), (30, 16), (13, 18), (4, 0), (14, -6), (6, -13), (0, -4), (-14, -13), (-22, -39))) # Register a new turtle shape turtle.shape('bird') turtle.fillcolor("brown") bird_clone = [] astamp = turtle.stamp() turtle.penup() pos_x = -600 pos_y = 600 turtle.setpos(pos_x, pos_y) turtle.pendown() bird_clone.append(astamp) if tree is True: if (x >= -340.0 and y <= 349.0 and y >= -349.0 and x <= 360.0): # check the clicke position is within the valid boundry triangle_one = y + 25 triangle_overlap_one = triangle_one + (50 * 60 / 100.0) triangle_overlap_two = triangle_overlap_one + (50 * 60 / 100.0) draw_triangle(x, triangle_one, 100, 50, 'green', 'green') # draw first triangle draw_triangle(x, triangle_overlap_one, 100, 50, 'green', 'green') # draw second triangle draw_triangle(x, triangle_overlap_two, 100, 50, 'green', 'green') # draw third triangle rectangle_one = y - 40 draw_rectangle(x, rectangle_one, 15, 80, 'brown', 'brown') # draw rectangle else : if (x >= -340.0 and y <= 349.0 and y >= -349.0 and x <= 360.0): # check the clicke position is within the valid boundry if (x >= 90.0 and x <= 110.0 and y >= 360.0 and y <= 386.0): # check whether tree radio button clicked print('do nothing') else: astamp = turtle.stamp() bird_clone.append(astamp) turtle.penup() pos_x = x pos_y = y turtle.setpos(pos_x, pos_y) turtle.pendown() tree = False print('detected a click at', x, y)
#Draw the pyramid of nodes draw_pyramid(pyramid_example) #Set the cursor position to the first node, 1, which is at 0,0 turtle.setpos(0, 0) current_pos = turtle.stamp() #Continue rolling the die and traversing the pyramid until all #nodes in the pyramid have been visited. while pyramid_example.visited_nodes < EXAMPLE_NODES: #Draw a dot at the current node, and set the yellow to red intensity color #at this node based on how many dots it has set_dot_intensity(pyramid_example) #Remove the old cursor turtle.clearstamp(current_pos) #Set the color of the stamp turtle.color(CURRENT_NODE_COLOR) #Update the cursor to the new node current_pos = turtle.stamp() #Roll the die and traverse the pyramid; in the rollDice() method, #the total number of dots and total number of moves are incremented #regardless if the move results in a new Node, SO the last move #before the game ends is recorded. pyramid_example.rollDice(output_file) #Remove the old cursor turtle.clearstamp(current_pos) #Draw the dot to the last node
def playGame(): # Frame variable initialization: rollList = [] inputList = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # Parent for-loop runs the total amount of frames in a bowling game: for frame in range(10): # Subframe initalization: gui.clear() drawGame(frame) frameReference = stampReference(frame) # Variable reset: toppledStamps = 0 pinIterator = 0 # User-input call: userInput = userInputCall(toppledStamps) # Child for-loop (sub-frames) runs a total of 1-2 rolls per frame # depending on the roller's score: for subFrame in range(2): # Special Condition for index 0: if frame == 0: # Strike Condition -- Bypass subframe 1: if int(userInput) == 10 and subFrame == 0: toppledPins = int(userInput) while toppledStamps < toppledPins: r.shuffle(frameReference) gui.clearstamp(frameReference[0]) del (frameReference[0]) time.sleep(0.1) toppledStamps += 1 frameResult = "Strike" drawResult(frameResult) rollList.append(10) rollList.append(0) print("Roll List as of frame ", frame + 1, ": ", rollList) # Non-Strike Condition - SubFrame 0: elif int(userInput) < 10 and subFrame == 0: if int(userInput) >= 0 and int(userInput) <= 10: toppledPins = userInput while toppledStamps < toppledPins: r.shuffle(frameReference) gui.clearstamp(frameReference[0]) del (frameReference[0]) time.sleep(0.1) toppledStamps += 1 rollList.append(toppledPins) print("Roll List as of frame ", frame + 1, ": ", rollList) # Get User Input for SubFrame 1: toppledPins += userInputCall(toppledStamps) rollList.append(toppledPins - toppledStamps) # SubFrame 2: while toppledStamps < toppledPins: r.shuffle(frameReference) gui.clearstamp(frameReference[0]) del (frameReference[0]) time.sleep(0.1) toppledStamps += 1 print("Roll List as of frame ", frame + 1, ": ", rollList) # Draw Frame Result: if toppledPins == 10: frameResult = "Spare" drawResult(frameResult) else: frameResult = "Open Frame" drawResult(frameResult) time.sleep(0.5) elif frame > 0 and frame < 9: if int(userInput) == 10 and subFrame == 0: toppledPins = int(userInput) while toppledStamps < toppledPins: r.shuffle(frameReference) gui.clearstamp(frameReference[0]) del (frameReference[0]) time.sleep(0.1) toppledStamps += 1 frameResult = "Strike" drawResult(frameResult) rollList.append(10) rollList.append(0) print("Roll List as of frame ", frame + 1, ": ", rollList) elif frame != 0 and int(userInput) != 10 and subFrame == 0: if int(userInput) >= 0 and int(userInput) <= 10: toppledPins = userInput while toppledStamps < toppledPins: r.shuffle(frameReference) gui.clearstamp(frameReference[0]) del (frameReference[0]) time.sleep(0.1) toppledStamps += 1 rollList.append(toppledPins) print("Roll List as of frame ", frame + 1, ": ", rollList) toppledPins += userInputCall(toppledStamps) rollList.append(toppledPins - toppledStamps) while toppledStamps < toppledPins: r.shuffle(frameReference) gui.clearstamp(frameReference[0]) del (frameReference[0]) time.sleep(0.1) toppledStamps += 1 print("Roll List as of frame ", frame + 1, ": ", rollList) if toppledPins == 10: frameResult = "Spare" drawResult(frameResult) else: frameResult = "Open Frame" drawResult(frameResult) time.sleep(0.5) elif frame == 9: if int(userInput) == 10 and subFrame == 0: toppledPins = int(userInput) while toppledStamps < toppledPins: r.shuffle(frameReference) gui.clearstamp(frameReference[0]) del (frameReference[0]) time.sleep(0.1) toppledStamps += 1 frameResult = "Strike" drawResult(frameResult) rollList.append(10) rollList.append(0) print("Roll List as of frame ", frame + 1, ": ", rollList) time.sleep(0.5) elif frame != 0 and int(userInput) != 10 and subFrame == 0: if int(userInput) >= 0 and int(userInput) <= 10: toppledPins = userInput while toppledStamps < toppledPins: r.shuffle(frameReference) gui.clearstamp(frameReference[0]) del (frameReference[0]) time.sleep(0.1) toppledStamps += 1 rollList.append(toppledPins) print("Roll List as of frame ", frame + 1, ": ", rollList) toppledPins += userInputCall(toppledStamps) rollList.append(toppledPins - toppledStamps) while toppledStamps < toppledPins: r.shuffle(frameReference) gui.clearstamp(frameReference[0]) del (frameReference[0]) time.sleep(0.1) toppledStamps += 1 if toppledPins == 10: frameResult = "Spare" drawResult(frameResult) else: frameResult = "Open Frame" drawResult(frameResult) time.sleep(0.5) print("Roll List as of frame ", frame + 1, ": ", rollList) if rollList[18] + rollList[19] == 10 and len(rollList) < 21: gui.clear() drawGame(frame) frameReference = stampReference(frame + 1) toppledStamps = 0 pinIterator = 0 rollList.append("") toppledPins = userInputCall(toppledStamps) while toppledStamps < toppledPins: r.shuffle(frameReference) gui.clearstamp(frameReference[0]) del (frameReference[0]) time.sleep(0.1) toppledStamps += 1 rollList[-1] = toppledStamps if toppledPins == 10: frameResult = "Strike" drawResult(frameResult) else: frameResult = "Open Frame" drawResult(frameResult) print("Roll List as of frame ", frame + 1, ": ", rollList) time.sleep(0.5) userFinalScore = finalScore(rollList) gui.goto(230, 150) gui.write("Final Score: ", move=False, align="center", font=("Arial", 36, "normal")) gui.goto(320, 150) gui.write(userFinalScore, move=False, align="center", font=("Arial", 36, "normal")) gui.exitonclick()
def deleteCue(self): turtle.clearstamp(self.stampId) self.stampId = ""
def deleteBall(self): turtle.clearstamp(self.stampId)
for i in tree1: l.append(i) l=sorted(l) for i in l: print(i,'->',tree1[i],end=' ') print('') #print(tree1) ''' #break try: tr.clearstamp(clr[current]) # print("*",len(opened),opened) except KeyError: pass #print("neighbours",current,"-",neighbours(current)) #time.sleep(1) for neighbour in neighbours(current): if neighbour not in closed: temp_g = g[current] + 1 l_temp=path(current)
turtle.fd(100) turtle.right(-90) turtle.color('black') turtle.speed(1) turtle.color('blue') b = turtle.stamp() turtle.fd(100) turtle.right(90) turtle.color('red') r = turtle.stamp() turtle.fd(100) turtle.right(90) turtle.color('green') g = turtle.stamp() turtle.fd(100) turtle.right(90) turtle.color('yellow') y = turtle.stamp() turtle.fd(100) turtle.right(90) turtle.color('black') turtle.clearstamp(y) turtle.clearstamp(g) turtle.clearstamp(r) turtle.clearstamp(b) turtle.undo() turtle.exitonclick()
turtle.right(-90) turtle.color('black') turtle.speed(1) turtle.color('blue') b=turtle.stamp() turtle.fd(100) turtle.right(90) turtle.color('red') r=turtle.stamp() turtle.fd(100) turtle.right(90) turtle.color('green') g=turtle.stamp() turtle.fd(100) turtle.right(90) turtle.color('yellow') y=turtle.stamp() turtle.fd(100) turtle.right(90) turtle.color('black') turtle.clearstamp(y) turtle.clearstamp(g) turtle.clearstamp(r) turtle.clearstamp(b) turtle.undo() turtle.exitonclick()
def erase(self): ''' Removes the object's image on screen. ''' turtle.clearstamp(self.id) self.id = None
import turtle turtle = turtle.Turtle() # turtle. clearstamp(stampid) # stampid – an integer, must be return value of previous stamp() call # Delete stamp with given stampid. turtle.position() #gives the position of the turtle turtle.color("blue") #storing the stamp id in stamp stamp = turtle.stamp() turtle.fd(50) turtle.position() #gives the position of the turtle turtle.clearstamp(stamp) # Delete stamp with given stampid. turtle.position() #gives the position of the turtle