def generate_map(self, surface, color_liste, list_box): """Generate Map, create Pawns objects and Box objects""" #iterate our board for line in range(self.rows): for item in range(self.columns): x = BOARD_TOPLEFT[0] + item * (CELL_SIZE[0] + CELL_SPACING[0]) y = BOARD_TOPLEFT[1] + line * (CELL_SIZE[1] + CELL_SPACING[1]) if self.list_name[line][ item] != 'nothing': # if name is not 'nothing' if self.list_box_owner[line][ item] == "player_one" or self.list_box_owner[line][ item] == "player_one_fix": owner_pawn = "player_one" #whatever box is fix or not, the owner would be same else: owner_pawn = "player_two" #use specific class to create pawns if self.list_name[line][item] == "pharaoh": pawn = Pharaoh(self.list_name[line][item], owner_pawn, self.list_direction[line][item]) elif self.list_name[line][item] == "anubis": pawn = Anubis(self.list_name[line][item], owner_pawn, self.list_direction[line][item]) elif self.list_name[line][item] == "scarab": pawn = Scarab(self.list_name[line][item], owner_pawn, self.list_direction[line][item]) elif self.list_name[line][item] == "pyramid": pawn = Pyramid(self.list_name[line][item], owner_pawn, self.list_direction[line][item]) elif self.list_name[line][item] == "sphinx": pawn = Sphinx(self.list_name[line][item], owner_pawn, self.list_direction[line][item]) else: print("ERROR Pawn does not exit !") #set position of pawns pawn._set_pos_X(x) pawn._set_pos_Y(y) self.list_pawn.append( pawn ) #append pawns into a list to stock them and be able to use them later # set settings of box as pawns box = Box(self.list_box_owner[line][item], False) box._set_pos_X(x) box._set_pos_Y(y) box._set_box_color(int(9)) self.list_box.append(box) else: #if there are no pawns on box : box = Box(self.list_box_owner[line][item], True) #True means the box is empty box._set_pos_X(x) box._set_pos_Y(y) box._set_box_color(int(9)) self.list_box.append(box)
def genBoxes(self, ppfunction): # Preprocessing processed = ppfunction() # Edge Highlightning edged = processed.copy() edged = cv2.Canny( processed, 10, 200 ) # canny: first parameter -> greater, # canny: second parameter -> greater, less contours # Contours Detection cnts, hierarchy = cv2.findContours(edged, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) # Boxing making factory = DPFactory.DPFactory('configuration.ini') dp = factory.generate() boxes = list(cnts) boxes = map(lambda x: Box.Box(x, dp, self.img, self.pcm), boxes) # Filtering # [Area] Is the area in the valid range? boxes = filter(lambda x: x.checkArea(), boxes) # [Black] Is the area "totally" black? boxes = filter(lambda x: x.isNotBlack(), boxes) # [Canvas] Is the area in the legal area (the canvas)? boxes = filter(lambda x: x.inCanvas(), boxes) # [Inside] Is the area inside another one? boxes = filter(lambda x: not x.insider(boxes), boxes) return boxes
def builMatrixBoxes(self): boxesMatrix = [] for i in range(self.Row): aux=[] for j in range(self.Column): aux.append(Box(i,j,0)) boxesMatrix.append(aux) return boxesMatrix
def redrawAll(self, screen): for i in range(20): for j in range(20): X = j * self.sizex Y = i * self.sizey if self.board[i][j] == 1: obs = Box.Box(X, Y, self.sizex, self.sizey) Box.Box.draw(obs, screen)
def create_boxes(): boxes = [] for i in range(grid_size[0]): boxes.append([]) for i in range(grid_size[0]): for j in range(grid_size[1]): boxes[i].append(Box((i, j), grid_param)) return boxes
def openNodeContend(self): print "me abriste" horizontalEdge = [ [1,1,0], [0,0,0], [0,0,0], [1,1,1] ] verticalEdge = [ [1,0,0,0], [1,0,0,0], [0,0,0,0] ] boxes = [[Box(0,0, 2), Box(0,1, 1), Box(0,2, 0)], [Box(1,0, 1), Box(1,1, 0), Box(1,2, 0)], [Box(2,0, 0), Box(2,1, 0), Box(2,2, 0)]] self.w = GraphicNodeContend(self.rows,self.columns,self.node.verticalEdge,self.node.horizontalEdge,self.node.boxes) self.w.show() print "se abrio"
def top(): one = Box.Box(37.5, 150, 100, 100, 64, 224, 208) Box.Box.draw(one, main_screen) one.drawimg("Toppings/t1.jpg", main_screen) two = Box.Box(170, 150, 100, 100, 64, 224, 208) Box.Box.draw(two, main_screen) two.drawimg("Toppings/t2.jpg", main_screen) three = Box.Box(302.5, 150, 100, 100, 64, 224, 208) Box.Box.draw(three, main_screen) three.drawimg("Toppings/t3.jpg", main_screen) four = Box.Box(37.5, 337.5, 100, 100, 64, 224, 208) Box.Box.draw(four, main_screen) four.drawimg("Toppings/t4.jpg", main_screen) five = Box.Box(170, 337.5, 100, 100, 64, 224, 208) Box.Box.draw(five, main_screen) five.drawimg("Toppings/cs.jpg", main_screen) six = Box.Box(302.5, 337.5, 100, 100, 64, 224, 208) Box.Box.draw(six, main_screen) six.drawimg("Toppings/cs.jpg", main_screen) global pg pg = 2
def fro(): one = Box.Box(37.5, 150, 100, 100, 64, 224, 208) Box.Box.draw(one, main_screen) one.drawimg("Frostings/frosting1.jpg", main_screen) two = Box.Box(170, 150, 100, 100, 64, 224, 208) Box.Box.draw(two, main_screen) two.drawimg("Frostings/frosting2.jpg", main_screen) three = Box.Box(302.5, 150, 100, 100, 64, 224, 208) Box.Box.draw(three, main_screen) three.drawimg("Frostings/frosting3.jpg", main_screen) four = Box.Box(37.5, 337.5, 100, 100, 64, 224, 208) Box.Box.draw(four, main_screen) four.drawimg("Frostings/frosting4.jpg", main_screen) five = Box.Box(170, 337.5, 100, 100, 64, 224, 208) Box.Box.draw(five, main_screen) five.drawimg("Frostings/cs.jpg", main_screen) six = Box.Box(302.5, 337.5, 100, 100, 64, 224, 208) Box.Box.draw(six, main_screen) six.drawimg("Frostings/cs.jpg", main_screen) global pg pg = 1
def redrawAll(self, screen): for i in range(20): for j in range(20): X = j * self.sizex + self.xOffset Y = i * self.sizey + self.yOffset if self.board[i][j] == 1: obs = Box.Box(X, Y, self.sizex, self.sizey) Box.Box.draw(obs, screen) self.display = screen self.enemy.updateRect(screen) for sprite in self.entities: sprite.draw(screen)
def _createSweptBoxList(self, world, speed): sweptList = [] self.specialSwept = None for entity in world.dynamicEntities: rb = entity.getComponent('RigidBody') colliders = entity.getComponent('ColliderList') if rb and colliders: c = colliders[0] collider = Box(entity.position - c.position, Vector2f(abs(c.size.x), abs(c.size.y))) swept = PhysicsSweptBox(collider, speed * rb.velocity, entity) sweptList.append(swept) world.addPhysicsEntity(swept) world.removeEntity(entity) if entity == self.specialEntity: self.specialSwept = swept return sweptList
def readbox(filename): #read a 21cmfast output file and return a Box object with data #parse filename to (1) check its a 21cmFast box (2) get box parameters # (3) identify what sort of box it is param_dict = parse_filename(filename) print param_dict #open box and read in data dim = param_dict['HIIdim'] box_data = open_box(filename, dim) #tidy data to ensure its in optimal form i.e. trim padding box_data = trim_box(box_data) #push data into Box class box = Box() box.setBox(box_data, param_dict) return box
def main(stdscr): curses.noecho() curses.curs_set(0) stdscr.keypad(True) mapReader = MapReader.MapReader('map') if mapReader.verifyMap() == False: curses.endwin() exit() player = Player.Player() box = Box.Box() mapReader.displayMap(stdscr) while True: entry = stdscr.getch() stdscr.clear() if entry == 27 or entry == 113: curses.endwin() exit() if entry == curses.KEY_UP: player.moveUp() mapReader.displayMap(stdscr) stdscr.refresh() if entry == curses.KEY_DOWN: player.moveDown() mapReader.displayMap(stdscr) stdscr.refresh() if entry == curses.KEY_LEFT: player.moveLeft() mapReader.displayMap(stdscr) stdscr.refresh() if entry == curses.KEY_RIGHT: player.moveRight() mapReader.displayMap(stdscr) stdscr.refresh()
def read_sudoku_in_line(self, txtPath, sudokuNumber):#Method that read a file where each line is a sudoku and save them in a list #open sudoku txt file file = open(txtPath, "r") #Read all lines of this file self.sudokuList = file.readlines() #Get the desired sudoku sudokuInLine = self.sudokuList[sudokuNumber] i = 0 while(i < len(sudokuInLine)-1): sudokuTmp = [] for j in range(0, 9): if(sudokuInLine[i+j] != ""): box = Box(((int)(sudokuInLine[i+j]))) #box.val sudokuTmp.append(box) self.sudokuToSolve.append(sudokuTmp) i = i + 9 file.close() return self.sudokuToSolve
def redrawAll(self, screen): self.display = screen pygame.draw.rect( screen, (0, 0, 0), (self.xOffset, self.yOffset, self.width * 2, self.height * 2), 4) for i in range(20): for j in range(20): X = j * self.sizex + self.xOffset Y = i * self.sizey + self.yOffset if self.board[i][j] == 1: obs = Box.Box(X, Y, self.sizex, self.sizey) Box.Box.draw(obs, screen) self.obstacles.add(obs) self.display = screen self.enemy.updateRect(screen) for sprite in self.entities: if sprite.alive: sprite.draw(screen)
def __init__(self): pygame.init() self.screen = pygame.display.set_mode( [SCREENWIDTH, SCREENHEIGHT + TILESIZE]) self.allSprites = pygame.sprite.Group() self.population = 4000 self.seaLevel = 0 self.seaIncrement = 1 self.resource = 2700 self.carryingCapacity = 4100 self.emotion = Emotion.NORMAL self.currentTurn = 0 # counter of Sprites self.startTreeCount = 0 self.treeCount = 0 self.houseCount = 0 self.factoryCount = 0 self.allSea = pygame.sprite.Group() self.allFactories = pygame.sprite.Group() self.allTrees = pygame.sprite.Group() self.allHouses = pygame.sprite.Group() self.allWaves = pygame.sprite.Group() self.spriteDict = {} self.constructionList = [] self.running = True pygame.key.set_repeat(300, 100) # self.initializeTerrain() self.box = Box(self, self.screen) self.seaX = 0 self.seaY = 0 self.clock = pygame.time.Clock()
clip1 = Clip("Sifap", "Mediano") eraser1 = Eraser("Milan", "Grande") eraser2 = Eraser("Pelikan", "Pequeño") pen1 = Pen("Bic", "2HB") pen2 = Pen("Bic", "4HB") pen3 = Pen("Stabilo", "4HB") pen4 = Pen("Studio", "4HB") marker1 = Marker("Sharpie", "Permanente") marker2 = Marker("Bic", "Permanente") reamOfPaper1 = ReamOfPaper("Chamex", "Hoja carta", "200") folder1 = Folder("Econofile", "grande", "200") tape1 = Tape("Tesa", "Transparente") stapler1 = Stapler("King", "200", "Grande") #creando caja1 box1 = Box() #Agregando objetos a la caja1 box1.add(clip1) box1.add(pen1) box1.add(pen2) box1.add(pen3) box1.add(folder1) box1.showContent() #imprimir el contenido de la caja #creando caja2 box2 = Box() #Agregando objetos a la caja2 box2.add(eraser1)
import Box import Pyramid import Sphere shape = input( "Choose which shape you want to calculate: Box, Sphere, or Pyramid ") if shape == 'Box': l = int(input("Type the Length of your Box ")) w = int(input("Type the Width of your Box ")) h = int(input("Type the Height of your Box ")) b = Box.Box(l, w, h) print('This is the Surface Area of your Box | ', b.getSurfaceArea()) print('This is the Volume of your Box | ', b.getVolume()) elif shape == 'Pyramid': l = int(input("Type the Length of your Pyramid ")) w = int(input("Type the Width of your Pyramid ")) h = int(input("Type the Height of your Pyramid ")) p = Pyramid.Pyramid(l, w, h) print('This is the Surface Area of your Pyramid | ', p.getSurfaceArea()) print('This is the Volume of your Pyramid | ', p.getVolume()) elif shape == 'Sphere': r = int(input("Type the Radius of your Sphere ")) s = Sphere.Sphere(r) print('This is the Surface Area of your Sphere | ', s.getSurfaceArea()) print('This is the Volume of your Sphere | ', s.getVolume())
def main(): # Read parameter and output file names from sys.argv parameters, outfile, cpp = get_arguments() # Create simulation Box. See design document for details. Simba = Box(parameters[0], parameters[2], parameters[1], parameters[3], cpp) # Performs simulation and saves positions and timelist. position_list, timelist = Simba.simulate(outfile, parameters[5], parameters[4]) # If you only want to load data to test the observable use the following # command and comment the one directly above. In that case specify the outfile: #outfile = "vmdoutput.xyz" #position_list = np.array(get_output(outfile, parameters[0])) #timelist = parameters[4]*np.arange(parameters[5]) # Define MSD and RDF parameters msd_start = 7000 # Need something >= 1 msd_end = 9999 # Need something > msd_start and < n_steps rdf_bins = np.arange(0, int(Simba.boxdim), 0.1) # Creates RDF bins rdf_start = 9500 # Need > 0 rdf_end = 9999 # Need < n_steps # The code below will create and save a MSD plot from time msd_start to msd_end. print("Calculating the Mean Square Displacement function\n") MSD_arr = MSD(position_list, msd_start, msd_end, Simba.boxdim) #fig = plt.figure(figsize=(3, 6)) write_output("MSD_output.txt", timelist[msd_start - 1:msd_end] - timelist[msd_start - 1], MSD_arr) plt.figure(1) plt.plot(timelist[msd_start - 1:msd_end], MSD_arr) #plt.title("Mean Square Displacement") plt.xlabel("Time $\\rightarrow$", fontsize=12, fontstyle="italic") plt.ylabel("MSD(t)/$\\sigma^{2}$ $\\rightarrow$", fontsize=12, fontstyle="italic") #plt.show() plt.savefig('Plots/MSD_gas.png') # The code below will create and save an RDF plot from time msd_start to msd_end. print("Calculating the Radial Distribution function\n") rdf_arr, rdf_bins = RDF(position_list, rdf_start, rdf_end, rdf_bins, Simba.boxdim) rdf_arr /= parameters[1] write_output("RDF_output.txt", rdf_bins, rdf_arr) plt.figure(2) plt.plot(rdf_bins, rdf_arr) #plt.title("Radial Distribution Function") plt.xlabel("Distance/$\\sigma$ $\\rightarrow$", fontsize=12, fontstyle="italic") plt.ylabel("g(r) $\\rightarrow$", fontsize=12, fontstyle="italic") #plt.show() plt.savefig('Plots/RDF_gas.png') # The code below will create and save an energy plot, displaying the potential # kinetic and total energies throughout the simulation. print("Plotting energy functions\n") timelist, PE, KE, TE = np.loadtxt('energyfile.txt', usecols=[0, 1, 2, 3], unpack=True) #,dtype=float) plt.figure(3) plt.plot(timelist, KE) plt.plot(timelist, PE) plt.plot(timelist, TE) #plt.title("Energy as a function of time") plt.xlabel("Time $\\rightarrow$", fontsize=12, fontstyle="italic") plt.ylabel("Energy $\\rightarrow$", fontsize=12, fontstyle="italic") plt.legend(['KE', 'PE', 'TE']) plt.savefig('Plots/E.png') plt.show() print("Post Simulation Fitted Temperature: ", np.mean(KE) / (1.5 * len(Simba.particles))) print("All plots saved in directory. Simulation has been successful.")
""" horizontalEdge = [ [1,1,0], [0,0,0], [0,0,0], [1,1,1] ] verticalEdge = [ [1,0,0,0], [1,0,0,0], [0,0,0,0] ] boxes = [[Box(0,0, 2), Box(0,1, 1), Box(0,2, 0)], [Box(1,0, 1), Box(1,1, 0), Box(1,2, 0)], [Box(2,0, 0), Box(2,1, 0), Box(2,2, 0)]] sequenceEdge = [] if __name__ == "__main__": node = Node(horizontalEdge, verticalEdge, boxes, sequenceEdge ) obj=pc.pcPlayer(None, 2,None,None)
import Box import Pyramid import Sphere #User Input selection = input("Would you like to do a box, pyramid, or sphere: ") selection = selection.lower() #Box if selection == 'box': length = int(input("What is the length of your box: ")) width = int(input("What is the width of your box: ")) height = int(input("What is the height of your box: ")) box = Box.Box(length, width, height) box.volume() box.surArea() #Pyramid elif selection == 'pyramid': length = int(input("What is the length of your pyramid: ")) width = int(input("What is the width of your pyramid: ")) height = int(input("What is the height of your pyramid: ")) pyramid = Pyramid.Pyramid(length, width, height) pyramid.volume() pyramid.surArea() #Sphere elif selection == 'sphere': length = int(input("What is the length of your sphere: ")) width = int(input("What is the width of your sphere: ")) height = int(input("What is the height of your sphere: ")) sphere = Sphere.Sphere(length, width, height)
def init_obstacles(self): obstacles = [] # obstacles.append(Box(self.TRACK_LENGHT, -30, 30, -60)) obstacles.append(Box(self.TRACK_LENGHT, -30, 30, -30)) return obstacles
if Npart <= i: break x[i, :] = np.array(p) * L / n3 i += 1 return x def energia_cinetica(v): return 0.5 * sum(sum(v**2)) if (sys.argv[1] == "e"): # Inicializo parametros # Caja L = 2 bx = Box.Box([0, 0, 0], [L, L, L], "Fixed") # Particulas Npart = sys.argv[2] N = sys.argv[3] part = Particles.PointParticles(Npart) pos = particulas(Npart, L) part.x = pos part.mass = np.zeros((Npart, 1), dtype=np.float32) + 1 # Interaccion morse = morse.Morse(1.1, 1, 0.2, 0.25) # Integrador verlet = Integrator.VelVerlet(0.01) # Vecinos vecinos = Neighbour.Neighbour() pares = vecinos.build_list(part.x, "None")
global pg pg = 2 def end(): erase((64, 224, 208)) if __name__ == "__main__": #start pygame pygame.init() main_screen = pygame.display.set_mode((450, 600)) main_screen.fill((255, 255, 224)) start = Box.Box(135, 500, 180, 50, 64, 224, 208) Box.Box.draw(start, main_screen) pg = 0 while True: ev = pygame.event.poll() if ev.type == pygame.MOUSEBUTTONDOWN: x, y = ev.pos if start.rec.collidepoint(x, y): erase((255, 255, 224)) one = Box.Box(37.5, 150, 100, 100, 64, 224, 208) Box.Box.draw(one, main_screen) one.drawimg("Actual/a1.jpg", main_screen)
import Interaction import Box import Neighbour #import pexmd # Inicializo parametros # Particulas part = Particles.PointParticles(8) pos = np.array([.5, .5, .5]) + np.array([[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]) part.x = pos part.mass = np.zeros((8, 1), dtype=np.float32) + 1 # Caja bx = Box.Box([0, 0, 0], [2, 2, 2], 'Fixed') # Interaccion LJ = Interaction.LennardJones(1.2, 1, 0.2) # Integrador verlet = Integrator.VelVerlet(0.01) # Vecinos vecinos = Neighbour.Neighbour() pares = vecinos.build_list(part.x, "None") def energia_cinetica(v): return 0.5 * sum(sum(v**2)) # Termalizamos N = 2000
import ccxt import market_lister import calculator import time import Box #Initialize objects mar = market_lister.market_lister() symbols = mar.get_symbols() calc = calculator.calculator() symbol = 'BTC/USDT' depth = 100 lim = calc.usd_to_btc(200) #get $X and return XBTC, use this to limit mar.limit_book = False #if False, the order book will not be limited, you will recieve all values # A = ccxt.binance({ # # B = ccxt.kraken({'enableRateLimit': True}) box = Box.Box() box.run()
def generateBoxes(): for i in range(0, 7, 3): for j in range(0, 7, 3): boxes.append(Box(i, j))
def gameLoop(): #startSound.play(-1) global levelNo global pause global red red=[] #while True: notCompleteLevel=True gameDisplay.fill(LBLUE) if(levelNo==1): red.append(Box(100,0,30,400,0,0)) red.append(Box(300,0,30,400,0,0)) red.append(Box(500,0,30,400,0,0)) red.append(Box(200,200,30,400,1,0)) red.append(Box(400,200,30,400,1,0)) red.append(Box(600,200,30,400,1,0)) green=[750,300,50,50,0,0] brick=[0,0,30,30,0,0] # for b in red: # pygame.draw.rect(gameDisplay,RED,(b.x,b.y,b.width,b.height)) # print(b.x) elif(levelNo==2): red.append(Box(100,0,30,400,0,5)) red.append(Box(300,0,30,400,0,5)) red.append(Box(500,0,30,400,0,5)) red.append(Box(200,200,30,400,1,5)) red.append(Box(400,200,30,400,1,5)) red.append(Box(600,200,30,400,1,5)) green=[750,300,50,50,0,0] brick=[0,0,30,30,0,0] elif(levelNo==3): red.append(Box(100,0,30,400,0,5)) red.append(Box(300,0,30,400,0,5)) red.append(Box(500,0,30,400,0,5)) red.append(Box(200,200,30,400,1,5)) red.append(Box(400,200,30,400,1,5)) red.append(Box(600,200,30,400,1,5)) green=[750,300,50,50,0,0] brick=[0,0,30,30,0,0] elif(levelNo==4): red.append(Box(100,0,30,400,0,5)) red.append(Box(300,0,30,400,0,5)) red.append(Box(500,0,30,400,0,5)) red.append(Box(200,200,30,400,1,5)) red.append(Box(400,200,30,400,1,5)) red.append(Box(600,200,30,400,1,5)) green=[750,300,50,50,0,0] brick=[0,0,30,30,0,0] elif(levelNo==5): red.append(Box(100,0,30,400,0,5)) red.append(Box(300,0,30,400,0,5)) red.append(Box(500,0,30,400,0,5)) red.append(Box(200,200,30,400,1,5)) red.append(Box(400,200,30,400,1,5)) red.append(Box(600,200,30,400,1,5)) green=[750,300,50,50,0,0] brick=[0,0,30,30,0,0] xChange=0 yChange=0 while notCompleteLevel: gameDisplay.fill(LBLUE) for b in red: if(b.direction==0): #moving down b.y=b.y+b.speed if(b.y+b.height>HEIGHT): b.direction=1 else: #moving down b.y-=b.speed if(b.y<0): b.direction=0 pygame.draw.rect(gameDisplay,RED,(b.x,b.y,b.width,b.height)) pygame.draw.rect(gameDisplay,BLACK,(brick[0],brick[1],brick[2],brick[3])) pygame.draw.rect(gameDisplay,GREEN,(green[0],green[1],green[2],green[3])) for b in red: if(doesCollide((brick[0],brick[1],brick[2],brick[3]),(b.x,b.y,b.width,b.height))): crash() if(doesCollide((brick[0],brick[1],brick[2],brick[3]),(green[0],green[1],green[2],green[3]))): levelNo+=1 notCompleteLevel=False for event in pygame.event.get(): if event.type==pygame.QUIT: pygame.quit() quit() if event.type==pygame.KEYDOWN: if event.key==pygame.K_LEFT: xChange=-5 elif event.key==pygame.K_RIGHT: xChange=5 elif event.key==273: yChange=-5 elif event.key==274: yChange=5 if event.key==pygame.K_p: pause=True paused() if event.type==pygame.KEYUP: if event.key==pygame.K_LEFT: xChange=0 elif event.key==pygame.K_RIGHT: xChange=0 elif event.key==273: yChange=0 elif event.key==274: yChange=0 if msg == 'UP': # pygame.draw.rect(DISPLAYSURF, AQUA, (startX, startY, BOXWIDTH, BOXHEIGHT)) yChange -= 5 # pygame.draw.rect(DISPLAYSURF, MAROON, (startX, startY, BOXWIDTH, BOXHEIGHT)) # UP = True # DOWN if msg == 'DOWN': # pygame.draw.rect(DISPLAYSURF, AQUA, (startX, startY, BOXWIDTH, BOXHEIGHT)) yChange += 5 # pygame.draw.rect(DISPLAYSURF, MAROON, (startX, startY, BOXWIDTH, BOXHEIGHT)) #DOWN = True # RIGHT if msg == 'RIGHT': # pygame.draw.rect(DISPLAYSURF, AQUA, (startX, startY, BOXWIDTH, BOXHEIGHT)) xChange += 5 # pygame.draw.rect(DISPLAYSURF, MAROON, (startX, startY, BOXWIDTH, BOXHEIGHT)) # RIGHT = True # LEFT if msg == 'LEFT': xChange-=5 # pygame.draw.rect(DISPLAYSURF, AQUA, (startX, startY, BOXWIDTH, BOXHEIGHT)) # -=5 # pygame.draw.rect(DISPLAYSURF, MAROON, (startX, startY, BOXWIDTH, BOXHEIGHT)) # LEFT = True if(0<brick[0]+xChange<WIDTH): brick[0]+=xChange if(0<brick[1]+yChange<HEIGHT): brick[1]+=yChange pygame.display.flip() clock.tick(50) #levelNo=levelNo+1 if(levelNo==5): youWin() gameLoop()
import Pyramid, Sphere, Box m1 = input( "If you would like to test for a rectangular prism, enter B. If you would like to test for a rectangular pyramid, enter P. If you would like to test for an ellipsoid, enter S." ) #m1 = upper(m1) l = float(input("Enter the length of your object:")) w = float(input("Enter the width of your object:")) h = float(input("Enter the height of your object:")) if m1 == "B": myShape = Box.Box(l, w, h) elif m1 == "P": myShape = Pyramid.Pyramid(l, w, h) elif m1 == "S": myShape = Sphere.Sphere(l, w, h) else: print("Invalid mode.") print("Volume: ", str(myShape.getVolume())) print("Surface area: ", str(myShape.getSurfaceArea()))
from Square import * from Rectangle import * from Cube import * from Box import * shapes = list() shapes.append(Square("Square 1", 10)) shapes.append(Rectangle("Rectangle 1", 20, 10)) shapes.append(Cube("Cube 1", 10)) shapes.append(Box("Box 1", 20, 10, 5)) print("Number of shapes: ", Shape.count) print("-" * 50) for current in shapes: print(current) print("-" * 50)
import Box, Sphere, Pyramid shape = input("What shape would you like to perform calculations on today? Box - b, Pyramid - p, Sphere - s:") if (shape == "b"): b1 = Box.Box() boxLength = int(input("Enter the length of the box:")) boxHeight = int(input("Enter the height of the box:")) boxWidth = int(input("Enter the width of the box:")) print(b1.boxVol())