import os import random import time # Import the Turtle module import turtle # Required by MacOSX to show the window turtle.fd(0) # Set the animation speed to the maximum turtle.speed(0) # Change the background color turtle.bgcolor("black") # Change the window title turtle.title("Space War") # Change background image turtle.bgpic("stars.gif") # Hide the default turtle turtle.ht() # This saves memory turtle.setundobuffer(1) # This speeds up drawing turtle.tracer(0) class Sprite(turtle.Turtle): def __init__(self, spriteshape, color, startx, starty): turtle.Turtle.__init__(self, shape = spriteshape) self.speed(0) self.penup() self.color(color) self.fd(0)
# -*- coding: utf-8 -*- """ Created on Mon Oct 19 10:51:27 2015 @author: usuario """ import turtle turtle.bgpic('img/maze_77_.gif') t = turtle.Turtle() t.shape('turtle') t.penup() t.color('brown') def move(x, y): t.goto(x, y) def move_right(): w = turtle.window_width() if t.xcor() < w/2 - 10: t.seth(0) t.forward(10) def move_left():
import os import random import time #Import the Turtle module import turtle #Required by MacOSX to show the window turtle.fd(0) #Set the animations speed to the maximum turtle.speed(0) #Change the background color turtle.bgcolor("black") #Change the window title turtle.title("SpaceWar") #Change the background image turtle.bgpic("space_invaders_background.png") #Hide the default turtle turtle.ht() #This saves memory turtle.setundobuffer(1) #This speeds up drawing turtle.tracer(0) class Sprite(turtle.Turtle): def __init__(self, spriteshape, color, startx, starty): turtle.Turtle.__init__(self, shape=spriteshape) self.speed(0) self.penup() self.color(color) self.fd(0)
import turtle, time import random import winsound t1 = turtle.Turtle() t2 = turtle.Turtle() turtle.bgpic('stars.gif') turtle.tracer(17) clr1 = [ 'red', 'brown', 'blue', 'pink', 'gold', 'violet', 'navy', 'green', 'firebrick', 'purple' ] clr2 = [ 'orange red', 'blue', 'pink', 'gold', 'violet', 'brown', 'navy', 'green', 'firebrick', 'purple' ] winsound.PlaySound('music1.wav', winsound.SND_ASYNC) while True: k1 = random.randint(56, 168) i1 = 1 t1.color('red') t1.up() #t1.clear() t1.goto(random.randint(-400, 400), random.randint(-400, 400)) t1.down() t1.pensize(3) k2 = random.randint(56, 168) i2 = 1 t2.color('red')
update() while running: for car in CARS: car.move() update() if collide(car, character): turtle.clone() running = False turtle.clearscreen() turtle.register_shape('gameover1.gif') turtle.shape("gameover1.gif") update() '''rSPEED = 25 ======= turtle.bgpic("road.gif") #comment turtle.setup(screen_width *2, screen_height*2) rSPEED = 25 >>>>>>> 7bb0e11dbb768d8202cfeed7a6b85c78104076bf rCOLOR = (random.random(),random.random(),random.random()) rPOSITION = (3,8) rWIDTH = 11 class Car(Turtle): def __init__(self,speed,color,pos,width): Turtle.__init__(self) self.penup() self.speed(speed) self.car_speed = speed
import turtle turtle.setup(950, 600) prozor = turtle.Screen() prozor.title("Hangman.") turtle.bgpic("slika.gif") strelica = turtle.getturtle() strelica.penup() turtle.hideturtle() turtle.setposition(-50, 300) turtle.write("Hangman", align="left", font=("Arial", 30)) turtle.setposition(100, 200) turtle.write("Dobrodošli!", align="left", font=("Arial", 15)) turtle.setposition(100, 180) turtle.write("Ovo je igrica Hangman.Odaberi slovo i pogodi riječ.", font=("Arial", 15)) turtle.setposition(100, 160) turtle.write("Sretno! :)", font=("Arial", 15)) import random rijec_iz_liste = "false" Rijeci = [ "telefon", "majmun", "tigar", "medvjed", "vjeverica", "gepard", "laptop", "torba", "slika", "farmaceut", "cvijet", "zeko", "kalendar", "radijator", "zgrada", "priroda", "odmor", "planina", "dukserica", "garderoba", "klavir", "orkestar", "doktor", "fakultet", "automobil", "helikopter", "diploma" ] duzinaRijeci = len(Rijeci) pozicija_rijeci = random.randint(0, duzinaRijeci)
import winsound # Import the Random module import random # Import the Time module import time # Import the Turtle module import turtle # Set the animation speed to the maximum turtle.speed(0) # Change the window title turtle.title("Space Bound") # Change the background color turtle.bgcolor('black') # Change the background image #turtle.bgpic("universe.gif") turtle.bgpic("rosette_nebula.gif") # Hide the default turtle turtle.ht() # This saves memory in the program turtle.setundobuffer(1) # This speeds up the drawing turtle.tracer(0) # Create Sprite class as a child class of the Turtle class class Sprite(turtle.Turtle): # Set the shape, color, and starting point as arguments of the object def __init__(self, spriteshape, color, startx, starty): turtle.Turtle.__init__(self, shape=spriteshape) self.speed(0) self.penup()
import random import winsound import time # Import the turtle module import turtle # For keeping the game open main_screen = turtle.Screen() # Set the animation speed to maximum turtle.speed(0) # Change the background color turtle.bgcolor("black") # Change the window title turtle.title("SpaceWar") # Change the background image turtle.bgpic("starfield.gif") # Hide the default turtle.ht() # This saves memory turtle.setundobuffer(1) # This speeds up drawing turtle.tracer(0) # Register the shapes turtle.register_shape("enemy.gif") turtle.register_shape("ally.gif") class Sprite(turtle.Turtle): def __init__(self, spriteshape, color, startx, starty): turtle.Turtle.__init__(self, shape = spriteshape)
if clickCount == 100: # if clickCount reaches 100 then make fun of the user more turtle.write("You are still going? lol", font = ("Terminal", 12, "bold", "normal")) print (clickCount,"shots") # print clickcount in shell print("Shot Accuracy:", calcRatio(kill,clickCount)) # print shot accuracy calling the func #series of print messages for the start of the program. print("Use your mouse to chase this little guy down.") print("Try to be as accurate as possible.") print("The more kills you get, the harder it will get.") print("Kills are shown on the screen as well as in the shell.") turtle.penup() # penup to eliminate lines turtle.setup(MAX_X,MAX_Y) # size for the window turtle.bgpic("background.gif") # background picture turtle.color("White") # turtle color for writing name and title. turtle.goto(-MAX_X/3,MAX_Y/2.25) # go to this location for writing title turtle.write(TITLE, font = ("Terminal", 18, "bold", "normal")) turtle.goto(MAX_X/7,-MAX_Y/4) # go to this location for writing name turtle.write(NAME, font = ("Terminal", 18, "bold", "normal")) mutalisk = turtle.Turtle() # defining mutalisk mutalisk2 = turtle.Turtle()# defining mutalisk2 mutalisk3 = turtle.Turtle()# defining mutalisk3 mutalisk4 = turtle.Turtle()# defining mutalisk4 explode = turtle.Turtle() # define explode explode.hideturtle() # explode hideturtle mutalisk.penup() # pen up for elimination of drag mutalisk2.penup()# pen up for elimination of drag mutalisk3.penup()# pen up for elimination of drag mutalisk4.penup()# pen up for elimination of drag
import pygame # The following width and height match the GIF used by the program screen_width, screen_height = 900, 564 firework_radius = 100 # The maximum radius a firework can have firework_count = 40 # The number of fireworks to shoot # A list of colours to choose from for a firework firework_colours = ["red", "orange", "yellow", "green", "cyan", "blue", "violet"] ##### Initialize the turtle module turtle.setup(screen_width, screen_height) turtle.bgpic("hong_kong.gif") turtle.width(2) turtle.speed(6) turtle.hideturtle() pygame.mixer.init() ##### For loop to shoot individual firework for i in range(firework_count): turtle.speed(3) pygame.mixer.music.load("firework_launch.mp3") # Clear the sky (screen) for every five fireworks if i > 0 and i % 5 == 0: time.sleep(1) turtle.clear()
def main(board_filepath): board_objects = [ ] # List to store output of board -- DO NOT CHANGE VARIABLE NAME output_list = [ ] # List to store final output -- DO NOT CHANGE VARIABLE NAME def sort_grid(l=[]): k = sorted(l) h = 0 li = [] for i in k: li.append(tuple(i)) for i in range(int(m.sqrt(len(l)))): for j in range(int(m.sqrt(len(l)))): k[h][0] = i + 1 k[h][1] = j + 1 h += 1 return (k) def find_shape(c): peri = cv2.arcLength(c, True) approx = cv2.approxPolyDP(c, 0.04 * peri, True) if len(approx) == 3: shape = "Triangle" elif len(approx) == 4: shape = "4-sided" else: shape = "Circle" return shape def detect_color(px): if px[0] > 240 and px[1] < 10 and px[2] < 10: return "blue" elif px[0] < 10 and px[1] < 10 and px[2] > 240: return "red" elif px[0] < 10 and px[1] > 240 and px[2] < 10: return "green" elif px[0] < 10 and px[1] > 240 and px[2] > 240: return "yellow" elif px[0] < 10 and px[1] < 10 and px[2] < 10: return "black" image_board = cv2.imread(board_filepath) image_board_gray = cv2.cvtColor(image_board, cv2.COLOR_BGR2GRAY) #cv2.imshow("gray",image_board_gray) image_board_inrange = cv2.inRange(image_board_gray, 200, 255) #cv2.imshow("board",image_board_inrange) cnts_b = cv2.findContours(image_board_inrange.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) cnts_b = cnts_b[0] cnts_b1, heirarchy_b = cv2.findContours(image_board_inrange.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) cv2.drawContours(image_board, cnts_b, -1, (206, 255, 39), 1) cnts_b1 = cnts_b1[0] shape = None l_board = [] for j in range(0, len(heirarchy_b[0])): if heirarchy_b[0][j][3] == -1: c = cnts_b[j] M = cv2.moments(c) cX = int((M['m10'] / M['m00'])) cY = int((M['m01'] / M['m00'])) if heirarchy_b[0][j][2] != -1: #cv2.putText(image_board,str(j), (cX, cY), cv2.FONT_ITALIC,0.5, (0,0,0), 2) shape = find_shape(cnts_b[heirarchy_b[0][j][2]]) M1 = cv2.moments(cnts_b[heirarchy_b[0][j][2]]) cX_object = int((M1['m10'] / M1['m00'])) cY_object = int((M1['m01'] / M1['m00'])) px = image_board[cY_object, cX_object] color = detect_color(px) area = int(M1['m00']) else: shape = None color = None area = None l_board.append([cX, cY, heirarchy_b[0][j][2], shape, color, area]) l_board_sorted = sort_grid(l_board) #print("^^",l_board_sorted) u = dict() path_board = {} def stopExists(start): for j in l_board_sorted: if (tuple([start[0], start[1]]) != tuple([j[0], j[1]]) and j[3] == start[3] and j[4] == start[4] and abs(j[5] - start[5]) <= 10): return (True) break else: return (False) return (stop) for start_object in l_board_sorted: if (start_object[2] != -1 and start_object[4] != "black" and stopExists(start_object)): for object in l_board_sorted: if object[2] == -1: path_board[tuple([object[0], object[1]])] = ["0"] elif l_board_sorted.index( start_object) != l_board_sorted.index( object) and object[3] == start_object[ 3] and object[4] == start_object[4] and object[ 5] == start_object[5]: path_board[tuple([object[0], object[1]])] = ["*"] elif l_board_sorted.index( start_object) == l_board_sorted.index(object): path_board[tuple([object[0], object[1]])] = ["#"] else: path_board[tuple([object[0], object[1]])] = ["1"] #print "" #print path_board #print "" ########################################################################################################################################################## for i in path_board: j = 0 for j in range(4): path_board[i].append([0, 0]) closed = set() opened = set() parent = {} g = {} gtemp = {} def lookup(x, y): if (x <= 0) or (y <= 0) or (x > (10)) or ( y > (10)) or path_board[(x, y)][0] == '1': return 0 else: return [x, y] def link(t): x = t[0] y = t[1] if path_board[t][0] == '1': return path_board[t][1] = lookup(x, y - 1) #north path_board[t][2] = lookup(x - 1, y) #west path_board[t][3] = lookup(x, y + 1) #south path_board[t][4] = lookup(x + 1, y) #east start = tuple([start_object[0], start_object[1]]) stop = set() for j in path_board: if (path_board[j][0] == "*"): stop.add(j) #break ''' print(start) print(stop) ''' for i in path_board: link(i) #for i in range(1,11): # for j in range(1,11): # print(i,j,path_board[(i,j)]) g[start] = 0 gtemp[start] = g[start] opened.add(start) def neighbours(t): """ Generate a set of neighbouring nodes """ neighbour = set() if path_board[t][1] != 0: neighbour.add(tuple(path_board[t][1])) if path_board[t][2] != 0: neighbour.add(tuple(path_board[t][2])) if path_board[t][3] != 0: neighbour.add(tuple(path_board[t][3])) if path_board[t][4] != 0: neighbour.add(tuple(path_board[t][4])) return neighbour def path(current_node): try: p = path(parent[current_node]) return_path = [] return_path.extend(p) return_path.append(current_node) return return_path except KeyError: # we have reached the start node return [current_node] while ((len(opened) > 0) and stop.isdisjoint(closed)): gsort = sorted(gtemp, key=lambda t: g[t]) i = 0 for i in range(len(gsort) - 1): if (gsort[i] not in closed): break current = gsort[i] for w in stop: if current == w: s = path(w) #print(path(w)) end = w try: opened.remove(current) gtemp.pop(current) # print("*",len(opened),opened) except KeyError: pass closed.add(current) for neighbour in neighbours(current): if neighbour not in closed: temp_g = g[current] + 1 if (neighbour not in opened) or (temp_g < g[neighbour]): # if the neighbour node has not yet been evaluated yet, then we evaluate it # or, if we have just found a shorter way to reach neighbour from the start node, # then we replace the previous route to get to neighbour, with this new quicker route parent[neighbour] = current g[neighbour] = temp_g gtemp[neighbour] = temp_g if neighbour not in opened: opened.add(neighbour) #print(len(opened),opened) u[(start, end)] = s path_board = {} ##################################################################################################################################################################### output_object = [] for j in range(0, len(l_board_sorted)): if l_board_sorted[j][2] != -1: output_object.append((l_board_sorted[j][0], l_board_sorted[j][1])) #print len(output_object) print "%", output_object #this is the output of task 1 - coordinates of occupied grid #cv2.imshow("contour",image_board) #for k in u: # print "$",k," ",u[k] print "" v = sorted(u) print v print "" for i in v: print i, "--->", u[i] import turtle as t r = 60 b = 5.5 * r t.bgpic("test_image" + str(fyl) + ".gif") t.ht() t.pensize(10) t.penup() for p in u: t.penup() t.clear() for i in u[p]: t.color("violet", "violet") t.setpos(i[0] * r - b, (11 - i[1]) * r - b) t.pendown() t.exitonclick()
SCREEN_HEIGHT = getcanvas().winfo_height() / 2 turtle.register_shape("player.gif") turtle.register_shape("target.gif") turtle.register_shape("bullet.gif") turtle.register_shape("fat.gif") turtle.register_shape("fast.gif") bullet_sound = pygame.mixer.Sound("bullet_sound.ogg") lose = pygame.mixer.Sound("lose.ogg") turtle.shape("target.gif") turtle.pu() turtle.bgcolor("black") turtle.bgpic("MainMenu.png") turtle.color("red") turtle.goto(0, 0) turtle.clear() turtle.write(str(3), align="center", font=("Arial", 40, "normal")) time.sleep(1) turtle.clear() turtle.write(str(2), align="center", font=("Arial", 40, "normal")) time.sleep(1) turtle.clear() turtle.write(str(1), align="center", font=("Arial", 40, "normal")) time.sleep(1) turtle.clear() def movearound(event):
class Labürint(turtle.Turtle): def __init__(self): turtle.Turtle.__init__(self) self.shape("kuul.gif") self.color("black") self.penup() self.speed(50) self.setposition(300, -300) levels = [""] levels.append(level_1) turtle.bgpic("taust.gif") käsi = turtle.Turtle() käsi.color("#C1E4FC") käsi.shape("turtle") käsi.penup() käsi.speed(10) käsi.setheading(270) def koostamine(level): for y in range(len(level)): for x in range(len(level[y])): karakter = level[y][x] screen_x = -288 + (x * 24) screen_y = 288 - (y * 24)
pen.write(text, move=False, align="center", font=("AR BLANCA", size, "bold")) port = random.randint(10000,65535) # Reserve a port for your service. Write(str(" AGARIO Game Pin: "+str(port)),24,0,0)#gmae port printing s.bind((host, port)) # Bind to the port window = turtle.Screen() #game screen set up in the begining window.setup(1280,800) #USE FOR FULLSCREEN window.screensize() window.setup(width = 1.0, height = 1.0) turtle.bgpic("blue-graph.gif") turtle.colormode(1) turtle.tracer(0) turtle.ht() running=True screen_width = turtle.getcanvas().winfo_width()//2 screen_height = turtle.getcanvas().winfo_height()//2 my_ball=Ball(100,300,6,6,"blue",30) #players set up player_2=Ball(100,300,6,6,"red",30) #bots set up number_of_balls=6
def Hangman(Word): # takes in the word t = 0 # used to spread out the letters in turtle y = 0 # also used to spread letters turtle.bgpic('CBBG.gif') # creates the actual hangman turtle.setup(1024, 682) turtle.title("Hangman Game") turtle.tracer(0) turtle.up() turtle.setposition(-150, 20) turtle.down() turtle.forward(300) turtle.up() turtle.setposition(0, 20) turtle.down() turtle.setposition(0, 300) turtle.forward(100) turtle.setposition(100, 250) WWL = Word Fails = 0 AG = [] Blank = "" LOW = len(Word) # creates blank marks for turtle for i in range(0, LOW): # takes in the range of length Blank += str('_') # to give me exact number of blanks Blank = list(Blank) i = 0 x = -100 turtle.up() turtle.setposition(-100, -100) turtle.down() while i < len(Blank) + 1: turtle.write("__", font=('Arial', 16, "normal")) turtle.up() turtle.setposition(x, -100) turtle.down() i += 1 x += 40 print(Blank) while len(WWL) > 0: # creates the guess a letter format letter = turtle.textinput("Hangman", "Guess a Letter") if letter in WWL: # checks to see if letter is in word x = -100 print("There is a(n) " + letter) for i, c in enumerate(Word): # if yes, rights the letter in if letter == c: # appropriate spot Blank[i] = letter y = i * 40 x = x + y turtle.up() turtle.setposition(x, -100) turtle.write(letter, font=('Arial', 30, "normal")) print(''.join(Blank)) WWL = WWL.replace(letter, '') AG.append(letter) else: if letter in AG: # checks to see if letter is already in print("Already Guessed!") else: turtle.up() # writes letter below if wrong turtle.setposition(t, -200) turtle.down() turtle.write(letter, font=('Arial', 30, "normal")) t += 50 AG.append(letter) Fails = Fails + 1 if Fails == 1: # draws the hangman figure dependent on fails turtle.up() turtle.setposition(100, 200) turtle.down() turtle.circle(25) elif Fails == 2: turtle.up() turtle.setposition(100, 200) turtle.down() turtle.setposition(100, 75) turtle.setposition(100, 200) elif Fails == 3: turtle.up() turtle.setposition(100, 75) turtle.down() turtle.setposition(60, 35) elif Fails == 4: turtle.up() turtle.setposition(100, 75) turtle.down() turtle.setposition(140, 45) elif Fails == 5: turtle.up() turtle.setposition(100, 175) turtle.down() turtle.setposition(50, 175) elif Fails == 6: turtle.up() turtle.setposition(50, 175) turtle.down() turtle.setposition(0, 175) turtle.write("YOU LOSE!!", font=('Arial', 40, "normal")) if len(WWL) == 0: # displays WIN turtle.up() turtle.setposition(-200, -200) turtle.down() turtle.write("YOU WIN!!", font=('Arial', 40, "normal")) turtle.done() again = turtle.textinput("Play Again?") # if they want to play again return
import math from functions import * from tkinter import * from characters import * #higher tracer = faster characters spawning from the left turtle.tracer(125,1) #main character is Abed abed = Player (20) abed.shape("circle") abed.shapesize(1) abed.penup() turtle.bgpic("tapperbg.gif") #life is how many times Life = 3 #controls for the player UP = 0 DOWN = 1 LEFT = 2 RIGHT = 3 direction = UP #creating the tables to place food on foods=[burger,pizza,sushi] FOODCOLLISION= False
ctdwn = Turtle() ctdwn.hideturtle() ctdwn.clear() ctdwn.color("white") ctdwn.write("3", move=False, align="center", font=("Arial", 200, "bold")) time.sleep(1) ctdwn.clear() ctdwn.write("2", move=False, align="center", font=("Arial", 200, "bold")) time.sleep(1) ctdwn.clear() ctdwn.write("1", move=False, align="center", font=("Arial", 200, "bold")) time.sleep(1) ctdwn.clear() turtle.bgpic("Agario.png") def options(): def Replay(): pass def MainMenu(): turtle.clearscreen() import mainMenu def Quit(): quit() turtle.onkey(Replay, "r") turtle.onkey(MainMenu, "m")
import time images = [ "rock.gif", "tree.gif", "health.gif", "ghost.gif", "fire1.gif", "background.gif", "diamond.gif" ] for image in images: turtle.register_shape(image) #Hide the default turtle turtle.ht() turtle.setup(950, 950) turtle.title("Tank Battle at Ghost Forest") turtle.bgcolor("black") turtle.bgpic("background.gif") #This saves memory turtle.setundobuffer(0) #This speeds up drawing turtle.tracer(0) class Pen(turtle.Turtle): def __init__(self): super().__init__() def blue_win(self): self.ht() self.up() self.goto(-170, 450) self.color("white")
return t def GIFTurtle(fname): t = Turtle(fname + ".gif") t.speed(0) t.up() return t score_txt = TextTurtle(0, 130, "white") best_txt = TextTurtle(90, 180, "white") pycon_apac_txt = TextTurtle(0, -270, "white") # Set background image or return name of current backgroundimage. tt.bgpic("bg1.gif") tubes = [(GIFTurtle("tube1"), GIFTurtle("tube2")) for i in range(3)] grounds = [GIFTurtle("ground") for i in range(3)] bird = GIFTurtle("bird1") PYCON_APAC_AD = """\ More Fun at PyCon APAC 2014/TW """ class Game: state = "end" score = best = 0
import turtle import random turtle.bgpic('sky.gif') turtle.tracer(1,0) SIZE_X=1000 SIZE_Y=700 turtle.setup(SIZE_X,SIZE_Y) turtle.penup() SQUARE_SIZE=20 START_LENGTH=7 player=turtle.clone() turtle.register_shape("player.gif") player.shape("player.gif") #put the player gif in the row above .don't forget to define it turtle.hideturtle() pos_list=[] lava_hight=40 turtle.register_shape("lava.gif") <<<<<<< HEAD lava=turtle.clone() lava.shape("lava.gif") lava.showturtle() lava.goto(0,-SIZE_Y/2+lava_hight) #turtle.pendown() ##turtle.goto(SIZE_X/2,-SIZE_Y/2+lava_hight) player.goto(-SIZE_X/2+25,-SIZE_Y/2+lava_hight+55) ======= turtle.shape("lava.gif") turtle.goto(-SIZE_X/2,-SIZE_Y/2+lava_hight)
###CHARACTER###:\ import turtle import time SIZE_X = 1000 SIZE_Y = 500 up_edge = 250 down_edge = -250 height = 30 length = 100 turtle.setup(SIZE_X, SIZE_Y) turtle.tracer(1, 0) pos_list = [] turtle.bgpic('bg.gif') pos_list = [] eatenfood = [] #REGISTERING SHIT turtle.penup() turtle.register_shape('pleasework.gif') turtle.register_shape("characterleft.gif") turtle.register_shape("characterright.gif") turtle.register_shape('work.gif') character = turtle.clone() character.shape("characterright.gif") character.penup() character.goto(-450, 10) turtle.hideturtle() #NEW CODE BEWARE!!! turtle.goto(300, 200)
frame += 1 #change the value in frame/x to control how often players spawn if frame / 2000 == 1: frame = 0 spawn_player() move_players() move_desires() check_food_desire_player_collision() check_if_player_reached_table() slide_food() turtle.update() if score_count // 25 == 1000000: abed.hideturtle() hearts.hideturtle() for a in players: a.hideturtle() for d in desires: d.hideturtle() turtle.bgpic("okhand.gif") #this section plays whenever you lose while Life == 0: hearts.shape("hearts0.gif") gameover.showturtle() abed.hideturtle() for a in players: a.hideturtle() for d in desires: d.hideturtle() turtle.mainloop()
turtle.bgpic("zombies.gif") score = 0 RUNNING = True sleep = 0.0099 SCREEN_WIDTH = turtle.getcanvas().winfo_width()/2 SCREEN_HEIGHT =turtle.getcanvas().winfo_height()/2 MY_BALL = Ball(0,0,30,30,30,"green") NUMBER_OF_BALLS = 5 MINIMUM_BALL_RADIUS = 10 MAXIMUM_BALL_RADIUS = 100 MINIMUM_BALL_DY = -5 MAXIMUM_BALL_DY = 5
elif op==4: salida() raw_input() else: os.system("cls") print """ingrese un numero valido plox""" raw_input() menuprin() ############################################################### turtle.title("La Constelacion de Santa Maria") turtle.setup(880, 880, 0, 0) turtle.bgpic("bg.gif") turtle.color("white") turtle.hideturtle() turtle.speed("100") #SE GRAFICAN LAS CIRCUNFERENCIAS turtle.up() turtle.setpos(440, 0) turtle.down() turtle.left(90) turtle.circle(440) #SEGUNDA CIRCUNFERENCIA turtle.setpos(220, 0) turtle.circle(220)
#Final project! #8.1.19,30.1.19 #yay! from turtle import Turtle import math import turtle import time import random import ball from ball import Ball import tkinter as tk from tkinter import simpledialog turtle.listen() turtle.tracer(0, 0) turtle.hideturtle() turtle.bgpic("sea.gif") colors = [ "blue", "red", "green", "yellow", "black", "white", "orange", "purple", "hot pink", "aquamarine", "crimson" ] Running = True Sleep = 0.0077 score = 0 h_scor = 0 screen_w = turtle.getcanvas().winfo_width() // 2 screen_h = turtle.getcanvas().winfo_height() // 2 turtle.penup() turtle.goto(screen_w, screen_h) turtle.pensize(5) for i in range(4): turtle.right(90)
# title("Turtle Keys") # def k1(): # ghost.forward(10) # def k2(): # ghost.left(90) # def k3(): # ghost.right(90) # onkey(k1, "Up") # onkey(k2, "Left") # onkey(k3, "Right") turtle.bgpic("heavenxhell.png") play = turtle.Turtle() def level1(x, y): #this function is the first level so its whats going to delete everything from the first page and make the game appear. story.clear() story1.clear() story2.clear() story3.clear() story4.clear() play.hideturtle() turtle.bgpic("hellbg.png") first_game() # ghost.goto(0,300)
def gamestart(x, y): start_button.clear() start_button.hideturtle() labels.clear() enemy_number_text.clear() left_arrow.hideturtle() right_arrow.hideturtle() difficulty_text.clear() left_arrow_2.hideturtle() right_arrow_2.hideturtle() turtle.bgpic("ust2.gif") # Use the global variables here because we will change them inside this # function global player, laser, score, score_label, score_display # Score display initialization score_label.up() score_label.goto(-260, 275) score_label.color("Red") score_label.write("Score:", font=("System", 12, "bold"), align = "center") # Value display score_display.up() score_display.goto(-220, 275) score_display.color("Red") score_display.write(str(score), font=("System", 12, "bold"), align = "center") ### Player turtle ### # Add the spaceship picture turtle.addshape("redbird.gif") # Create the player turtle and move it to the initial position player = turtle.Turtle() player.shape("redbird.gif") player.up() player.goto(player_init_x, player_init_y) # Map player movement handlers to key press events turtle.onkeypress(playermoveleft, "Left") turtle.onkeypress(playermoveright, "Right") turtle.listen() ### Enemy turtles ### # Add the enemy picture turtle.addshape("closedbook.gif") turtle.addshape("openbook.gif") for i in range(enemy_number): # Create the turtle for the enemy enemy = turtle.Turtle() enemy.shape("closedbook.gif") enemy.up() # Move to a proper position counting from the top left corner enemy.goto(enemy_init_x + enemy_size * (i % 6), enemy_init_y - enemy_size * (i // 6)) # Add the enemy to the end of the enemies list enemies.append(enemy) turtle.onkeypress(stopkeypressed, 's') ### Laser turtle ### turtle.addshape("pen.gif") # Create the laser turtle laser = turtle.Turtle() laser.up() laser.shape("pen.gif") # Hide the laser turtle laser.hideturtle() turtle.onkeypress(shoot, "space") turtle.update() # Start the game by running updatescreen() turtle.ontimer(updatescreen, update_interval)
import turtle from turtle import Turtle import random import math import time turtle.tracer(0) #turtle.speed(1000) turtle.bgpic("forest.gif") turtle.hideturtle() #turtle.tracer(3,500) SCREEN_WIDTH = turtle.getcanvas().winfo_width()/4 SCREEN_HEIGHT = turtle.getcanvas().winfo_height()/2 OBSTICLES_LIST = [] COINS_LIST = [] SPIKES_LIST = [] OBSTICLES_MAX_NUMBER = 3 #MAX_COINS_NUMBER: 3 MAX_SPIKES_NUMBER = 10 direction = 0 player_lost = False f_2 = True flag_1 = False flag_2 = False flag_3 = False flag_4 = False count = 0 SCORE = 0
''' ######################################## box_color_list = ["box1.gif", "box2.gif", "box3.gif", "box4.gif", "box5.gif"] background_list = [ "background1.gif", "background2.gif", "background3.gif", "background4.gif" ] background = random.randint(0, 4) screen = turtle.Screen() randbackground = random.randint(0, len(background_list) - 1) this_background = background_list[randbackground] turtle.register_shape(this_background) turtle.bgpic(this_background) ########################################################### turtle2 = turtle.clone() score = 0 turtle2.write(str(score)) turtle2.ht() turtle.penup() #bird = turtle.clone() #turtle.addshape('bird.gif') #bird.shape('bird.gif') turtle.shape('circle') #turtle.hideturtle() turtle.Screen() turtle.fillcolor('white')
'''Use Keyboard left and right to turn those directions respectively. Use Arrow Key up to increase speed Use arrow key down to reduce speed Use space bar to fire missile''' import os import random import turtle import time turtle.fd(0) # Animation speed set to max turtle.title("Galaxy Wars") turtle.speed(0) # Background image turtle.bgpic("bg_.gif") turtle.bgcolor("black") # Hide default turtle turtle.ht() # Save memory turtle.setundobuffer(1) turtle.tracer(0) # Registering the shapes turtle.register_shape("enemy.gif") turtle.register_shape("friendly.gif") turtle.register_shape("bullet.gif") # setting up a class for sprites class Sprite(turtle.Turtle):
def visualize(hightlighted=200): ks, vs = readkvp() name_to_highlight = ks[hightlighted - 1] highlight_neighbor = '' ks, colors = coor2color(ks, vs) jplan = {} with open(os.path.join(BASE, 'plan.json'), 'r') as in_f: jplan = json.load(in_f) plan = [] for i, row in enumerate(jplan[0]): plan.append((jplan[0][row]['Aisle'], jplan[0][row]['Window'])) if jplan[0][row]['Aisle'] == name_to_highlight or jplan[0][row][ 'Window'] == name_to_highlight: draw = random.randint(0, max(0, min(i - 1, 15))) temp = plan[draw] plan[draw] = plan[i] plan[i] = temp if jplan[0][row]['Aisle'] == name_to_highlight: highlight_neighbor = jplan[0][row]['Window'] else: highlight_neighbor = jplan[0][row]['Aisle'] name2id = dict(zip(ks, (i for i in range(len(ks))))) # turtle!!! DISTANCE = 27 WIDTH = 1080 HEIGHT = 675 BGPIC = os.path.join(BASE, 'background.png') turtle.setup(WIDTH, HEIGHT) turtle.bgpic(BGPIC) turtle.pencolor('grey') turtle.shape("square") turtle.colormode(255) turtle.shapesize(1.3) turtle.width(0) turtle.tracer(False) turtle.up() turtle.goto(-(WIDTH / 2) + 108, (HEIGHT / 2) - 100) for _, row in enumerate(jplan[0]): plan.append((jplan[0][row]['Aisle'], jplan[0][row]['Window'])) for i in range(7): for j in range(2): p = name2id[plan[i][j]] turtle.fillcolor(colors[p][0], colors[p][1], colors[p][2]) turtle.stamp() if plan[i][j] == name_to_highlight: turtle.shape('circle') turtle.fillcolor(255, 255, 255) turtle.stamp() turtle.shape('square') turtle.right(90) turtle.forward(int(DISTANCE * 1.07)) turtle.left(90) turtle.forward(int(DISTANCE * 1.545)) turtle.left(90) turtle.forward(2 * int(DISTANCE * 1.07)) turtle.right(90) turtle.forward(215) for i2 in range(9): i = i2 + 9 for j in range(2): p = name2id[plan[i][j]] turtle.fillcolor(colors[p][0], colors[p][1], colors[p][2]) turtle.stamp() turtle.right(90) turtle.forward(int(DISTANCE * 1.07)) turtle.left(90) turtle.forward(int(DISTANCE * 1.6)) turtle.left(90) turtle.forward(2 * int(DISTANCE * 1.07)) turtle.right(90) turtle.hideturtle() ts = turtle.getscreen() ts.getcanvas().postscript(file=os.path.join(BASE, 'plan.eps')) im = Image.open(os.path.join(BASE, 'plan.eps')) im.show() #im.save(os.path.join(BASE, 'plan.jpeg'), "JPEG") #ts = turtle.getscreen().getcanvas() #canvasvg.saveall(os.path.join(BASE, 'plan.svg'), ts) #return 0 # return he's data, color, as well as his neighbor's # or visualize it and return the result? ret = json.dumps([{ 'Name': name_to_highlight, 'Preferences': { 'Window': vs[hightlighted - 1][0], 'Sleep': vs[hightlighted - 1][1], 'Networking': vs[hightlighted - 1][2], 'WindowShading': vs[hightlighted - 1][3], }, 'Color': { 'R': colors[hightlighted - 1][0], 'G': colors[hightlighted - 1][1], 'B': colors[hightlighted - 1][2], } }, { 'Name': highlight_neighbor, 'Preferences': { 'Window': vs[name2id[highlight_neighbor]][0], 'Sleep': vs[name2id[highlight_neighbor]][1], 'Networking': vs[name2id[highlight_neighbor]][2], 'WindowShading': vs[name2id[highlight_neighbor]][3], }, 'Color': { 'R': colors[name2id[highlight_neighbor]][0], 'G': colors[name2id[highlight_neighbor]][1], 'B': colors[name2id[highlight_neighbor]][2], } }]) return ret #if __name__ == '__main__': #visualize()
import turtle import os import random import time from tkinter.messagebox import * turtle.speed(1) turtle.bgcolor("black") turtle.ht() turtle.setundobuffer(1)#this save memory turtle.tracer(0) #turtle.bgpic("background.gif") turtle.title("SPACE WAR") turtle.bgpic("spacebackground.gif") turtle.register_shape("spaceunit.gif") turtle.register_shape("spacestone.gif") turtle.register_shape("bullet.gif") turtle.register_shape("red_bullet.gif") turtle.register_shape("type_A.gif") class Sprite(turtle.Turtle): def __init__(self,spriteshape,color,startx,starty): turtle.Turtle.__init__(self,shape=spriteshape) self.speed(0) self.penup() self.color(color) self.goto(startx,starty) self.speed = 1
#!/usr/local/bin/python __author__ = 'Andrea Vicari' import turtle planets_inf = {'Mercury':[88, 57.9, 2440], 'Venus':[224, 108.2, 6100], 'Earth':[365, 149.6, 6378], 'Mars':[687, 227.9, 3380], 'Jupiter':[4328, 778.3, 71350], 'Saturn':[10752, 1429, 60400], 'Uranus':[30663, 2875, 23800], 'Neptune':[60152, 4496, 22200]} #Background screen = turtle.Screen() turtle.setworldcoordinates(-30000, -30000, 30000, 30000) screen.title("Solar System") turtle.bgpic('planet_textures/universe.gif') screen.setup (width=1500, height=1000, startx=0, starty=0) #Import images in the register of the shapes turtle.register_shape('planet_textures/sole.gif') turtle.register_shape('planet_textures/mercurio.gif') turtle.register_shape('planet_textures/venere.gif') turtle.register_shape('planet_textures/terra.gif') turtle.register_shape('planet_textures/marte.gif') turtle.register_shape('planet_textures/giove.gif') turtle.register_shape('planet_textures/saturno.gif') turtle.register_shape('planet_textures/urano.gif') turtle.register_shape('planet_textures/nettuno.gif') #Create one different turtle for each Planet
stamp_list = [] food_pos = [] food_stamps = [] textturtle.write(int(len(stamp_list)),align="center",font=("times",33,"bold")) #Set up positions (x,y) of boxes that make up the snake snake = turtle.clone() turtle.addshape("Calebb.gif") snake.shape("Calebb.gif") snake.color("black") turtle.register_shape("599e10b2a05d6.image.gif") turtle.register_shape("trash.gif") #Add trash picture # Make sure you have downloaded this shape # from the Google Drive folder and saved it # in the same folder as this Python script turtle.bgpic("599e10b2a05d6.image.gif") food = turtle.clone() food.shape("Calebb.gif") food.ht() #Hide the turtle object (it's an arrow - we don't need to see it) 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!
############################################################################################################################################# ############################################################# TANK WAR V 1.0 ################################################################ from turtle import bgpic from turtle import title from turtle import screensize from turtle import bgcolor import turtle as t from math import* from random import* ####################### registers shapes for turtle ############################################################################ t.speed('fastest') title('Tank-War v 1.0 ') screensize(1024,700) bgpic('bg.gif') bgcolor('black') t.ht() t.register_shape('30016.gif') t.register_shape('tankr.gif') t.register_shape('target1.gif') ##################################### Title and Screen ####################################################################################### splash=t.Turtle() splash.shape('30016.gif') ww=t.Turtle() ww.color('yellow') ww.ht() ww.up() ww.goto(-150,0) ww.down() ww.write('TANK WAR v 1.0 ',font=('Arial',36,'bold'))
def s(): t.bgpic("looserscreen.gif")
def s3(): t.bgpic("looserscreen4.gif")
def s2(): t.bgpic("looserscreen3.gif")
def s1(): t.bgpic("looserscreen2.gif")
def __setScreen(self): """set the screen/window depending on view static attributes.""" turtle.resizemode('noresize') self.width = self.GRID_MARGINLEFT + 2 * self.gridWidth + self.GAP_BETWEEN_GRIDS + self.GRID_MARGINRIGHT self.height = self.GRID_MARGINTOP + self.gridWidth + self.GRID_MARGINBOTTOM turtle.setup(width=self.width + 10, height=self.height + 10) turtle.screensize(self.width, self.height) turtle.bgpic("Ressources/fire_ocean.gif") turtle.reset()
def visualizeQuakes(k, r): """(int, int) -> None Top level function for accessing and analyzing earthquake data from USGS website. Calls readeqf, createCentroids, and createClusters, using parameter k number of clusters and r number of repetitions to run the k-means cluster analysis algorithm. Uses turtle module to graphically plot the M5 or greater earthquakes within the past month on a world map. Different queries can be plotted by altering the url in readeqf as per the USGS API. Color list currently permits only k values less than or equal to 30. Note 2: Map supplied in the original spec is a Mercator and plots incorrectly. Use the included Equirectangular Projection instead. Returns None. > visualizeQuakes(6, 50) <Draws Turtle Graphics map with 6 clusters.> """ eq_dict = readeqf() centroids = createCentroids(k, eq_dict) clusters = createClusters(k, centroids, eq_dict, r) w = 1800 #Window width. h = 900 #Window height. bg_pic = "better_worldmap1800_900.gif" t.setup(width=w, height=h) t.bgpic(bg_pic) t.speed("fastest") t.hideturtle() t.up() w_factor = ((w / 2) / 180) h_factor = ((h / 2) / 90) color_list = ["dark red", "dark green", "dark blue", "dark orange", "dark orchid", "dark goldenrod", "dark violet", "pink", "magenta", "sky blue", "plum", "dark salmon", "goldenrod", "chartreuse", "dark sea green", "cornsilk", "dark olive green", "bisque", "blanched almond", "dark cyan", "royal blue", "papaya whip", "peach puff", "misty rose", "mint cream", "lavender blush", "hot pink", "dark khaki", "cornflower blue", "chocolate"] for cluster_index in range(k): t.color(color_list[cluster_index]) for akey in clusters[cluster_index]: lon = (eq_dict[akey][0]) * w_factor lat = (eq_dict[akey][1]) * h_factor t.goto(lon, lat) t.dot() return None
def setup(col, x, y, w, s, shape): turtle.up() turtle.goto(x,y) turtle.width(w) turtle.turtlesize(s) turtle.color(col) turtle.shape(shape) turtle.bgpic("assets/dancing-banana.gif") turtle.down() wn.listen() turtle.getscreen()._root.bind_all('<Key>', key_pressed) turtle.getscreen()._root.mainloop()
def __init__(self,pseudo,adv,*,x=600,y=400): super().__init__(pseudo,adversaire = adv) turtle.Screen().onkey(self.pleindre,'p') turtle.Screen().onkey(self.rule,'j') self.coord1 = None self.coord2 = None turtle.ht() turtle.penup() turtle.bgpic("interface.gif") #charge le fond d'écran turtle.setup (width=x, height=y, startx=0, starty=0) turtle.Screen().onkey(self.help,'m') turtle.goto(-170,115) turtle.write(self.adv,align="center",font=("Arial",25, "normal")) turtle.goto(140,115) turtle.write(pseudo,align="center", font=("Arial",25, "normal"))
def gameover(message): # Part 5.3 - Improving the gameover() function goturtle = turtle.Turtle() goturtle.hideturtle() goturtle.pencolor("yellow") goturtle.write(message, align="center", font=("System", 30, "bold")) turtle.update() """ Set up main Turtle parameters """ # Set up the turtle window turtle.setup(window_width, window_height) turtle.bgpic("ust.gif") turtle.up() turtle.hideturtle() turtle.tracer(False) # Spinner control initialization labels = turtle.Turtle() labels.hideturtle() labels.pencolor("Yellow") labels.up() # Write the text labels.goto(-100, -155) # Next to the spinner control labels.write("Number of Enemies:", font=("System", 12, "bold")) labels.goto(-100, -130) labels.write("Game Difficulty:", font=("System", 12, "bold")) labels.pencolor("Red")
def beginguide(): #command.logo+instructions+level, ends with clear background global level global whoseturn t.bgpic("logo.gif") input("Chopsticks - Press enter to start") t.bgpic("instructions.gif") #instructions screen input("Instructions - Press enter to continue") t.bgpic("levels.gif") while True: level = str(input("What level do you wanna play? Type 'h' for hard, 'm' for medium and 'e' for easy: ")) if level == "h" or level =="m" or level == "e": break t.bgpic(level+".gif") while True: begin = input("Who should start? Computer 'c', you 'y' or flip a coin 'f'") if begin == "c" or begin == "y" or begin == "f": break if begin == "c": whoseturn = "c" elif begin == "y": whoseturn = "y" else: t.bgpic("flipcoin.gif") if random.randint(0,1) == 1: print("You start!") whoseturn = "y" else: print("Computer starts!") whoseturn = "c" time.sleep(1) t.bgpic("clearscreen.gif")
def setBackgroundPic(image): turtle.bgpic(str(image))
def w(): t.bgpic("winnerscreen.gif")
def w3(): t.bgpic("winnerscreen3.gif")
def w2(): t.bgpic("winnerscreen2.gif")