def init(data): data.start = False data.message = "None" # for login data.drawn = 0 data.temp = 0 data.mode = "start" data.timeLimit = 20000 # 30 seconds loadImages(data) data.time = 0 data.level = 1 data.numPlayers = -1 data.numPlayerClicks = 0 data.myClicks = 0 data.highScore = 0 data.play = False data.nextClicks = 0 data.minTotalScrollX, data.minTotalScrollY = 0, 0 # for last player data.maxTotalScrollX, data.maxTotalScrollY = 0, 0 # for first player createObjects(data) # all objects of the game (except the characters) data.scrollX = data.width//50 # speed of horizontal scrolling data.scrollY = data.scrollX # speed of vertical scrolling data.jump, data.speed = data.height//5, data.width//20 data.jumpStep = data.jump//15 data.platforms = set() Platforms(0, 0, data) data.platforms.clear() data.me = FlyingCharacter("Lonely", data) Patronus(0, 0, data) data.bullets.clear() data.others = dict() # other players
def init(data): data.controller = Leap.Controller() data.frame = data.controller.frame() data.fingerNames = ['Thumb', 'Index', 'Middle', 'Ring', 'Pinky'] data.boneNames = ['Metacarpal', 'Proximal', 'Intermediate', 'Distal'] data.mode = "splashScreen" loadImages.loadImages(data) data.color = 'gray' data.outlineX = 0 data.outlineY = 0 data.BGoutlineX = 0 data.BGoutlineY = 0 data.propOutlineX = 0 data.propOutlineY = 0 data.background = None data.prop = None data.ballCenterX = data.width / 2 data.ballCenterY = 50 data.down = True data.accessory = None data.accOutlineX = 0 data.accOutlineY = 0 data.sock2 = False data.color2 = 'gray' data.accessory2 = None data.appleState = 0 data.appleStates = [ data.apple, data.apple1, data.apple2, data.apple3, data.apple4, None ] data.appleCenterX = data.width - 100 data.appleCenterY = data.height / 2 + 25 data.energy = 6000 data.carCenterX = data.width / 2 data.velocity = 0 data.linePoints = [] data.linePoints2 = [] data.b1 = 'up' data.xold, data.yold = None, None data.wrongShape = False # Music from http://www.orangefreesounds.com data.music = None data.playMusic = False data.music1 = 'Music/Fur-elise-music-box.wav' data.music2 = 'Music/Happy-electronic-music.wav' data.music3 = 'Music/Magical-path-melodic-upbeat-electronic-music.wav' data.music4 = 'Music/Short-electronic-background-music.wav' data.musicOutlineX = 0 data.musicOutlineY = 0
def __init__(self, topSurface, pos, dir, spd, owner, actType='bullet'): """Constructor""" imageListIn = loadImages.loadImages(r'./art/bullet/', 'png', (16, 16)) super(Projectle, self).__init__(topSurface, pos, imageListIn, actType) print 'spawned:', self #self.pos = pos self.imageList= loadImages.loadImages(r'./art/bullet/', 'png', (16, 16)) #size #self.width = constants.unit * 2 #self.height = constants.unit * 2 self.width = 16 self.height = 16 #rect of the size of the image to be self.rect = pygame.rect.Rect(0, 0, self.width, self.height) #set the rects center to the anythings pos self.rect.center = pos #direction self.direction = dir self.facing = (1, 0) #degrees sprite is rotated self.currentRotation = 0 #speed self.speed = spd #drawable surface self.surface = self.imageList #self.surface.fill(constants.BLUE) self.topSurface = topSurface #who fired it self.owner = owner #bounding boxes, the perimiter of the rects, in a list self.bboxsList = self.getBboxes() self.point = (0, 0) self.point2 = (0, 0), (0, 0)
def preprocessing(): # ------------------------------------------------ # YOUR CODE HERE img73, img87 = loadImages() featLearn = 0 # Redimensionnement img73 = img73[120:820, 180:800, :] img87 = img87[120:820, 180:800, :] # Affichage des images plt.figure(1); plt.imshow(img73); plt.show() plt.figure(2); plt.imshow(img87); plt.show() # Echantillonnage featLearn, nbPix, nbFeat = selectFeatureVectors(img73, 500) print('nb pix:', nbPix, '\r') print('nb feat:', nbFeat, '\r') # print('featLearn:', featLearn, '\r') # Affichage 2D et 3D displayFeatures2d(featLearn) displayFeatures3d(featLearn) # ------------------------------------------------ # ------------------------------------------------ #%% sortie return featLearn,img73,img87
def part1(): loadI = loadImages() leung_malik = loadmat(os.path.join(loadI.filters, "leung_malik_filter.mat"))["F"] if not os.path.exists("part1_plots"): os.mkdir("part1_plots") myImages = [] for i in loadI.imagesVector: img = cv2.imread(os.path.join(loadI.imagesPath, i), 0) img = cv2.resize(img, (100, 100)) myImages.append(img) for i in range(48): fig, axs = plt.subplots(2, 4) axs[0, 1].axis("off") axs[0, 0].imshow(leung_malik[:, :, i]) axs[0, 0].set_title("Filter") axs[0, 2].imshow(ndimage.convolve(myImages[0], leung_malik[:, :, i])) axs[0, 2].set_title(loadI.imagesVector[0]) axs[0, 3].imshow(ndimage.convolve(myImages[1], leung_malik[:, :, i])) axs[0, 3].set_title(loadI.imagesVector[1]) axs[1, 0].imshow(ndimage.convolve(myImages[2], leung_malik[:, :, i])) axs[1, 0].set_title(loadI.imagesVector[2]) axs[1, 1].imshow(ndimage.convolve(myImages[3], leung_malik[:, :, i])) axs[1, 1].set_title(loadI.imagesVector[3]) axs[1, 2].imshow(ndimage.convolve(myImages[4], leung_malik[:, :, i])) axs[1, 2].set_title(loadI.imagesVector[4]) axs[1, 3].imshow(ndimage.convolve(myImages[5], leung_malik[:, :, i])) axs[1, 3].set_title(loadI.imagesVector[5]) name = 'plot_filter_' + str(i) + '.png' fig.savefig(os.path.abspath(os.path.join("part1_plots", name))) plt.close(fig)
def init(): '''initializes screen''' global screen, background_surface #initializes pygame PG.init() #starts the screen screen = PG.display.set_mode((constants.WIDTH, constants.HEIGHT)) #set Icon, may not work off windows icon = loadImages.loadImages(r'./art/man/', 'png') icon = icon[7] PG.display.set_icon(icon) #fills the screen with a color screen.fill(constants.BACKGROUND) #loads the background image background_surface = loadImages.loadImages(r'./art/backgrounds/', r'pond.png', (screen.get_rect().w, screen.get_rect().h)) background_surface = background_surface.convert() screen.blit(background_surface, (0, 0)) #loads joyticks to gamePad list controls.initJoysticks() global imageList imageList = loadImages.loadImages(r'./art/man/', 'png') #create a first Anything actors.spawnAnything(screen, imageList, (400, 400)) actors.Shooter(lists.ANYTHINGs[0]) PG.display.flip() return screen
def debugControls(action, surface): """handles debug controls. Ex: createActor""" if action == 'createAnything': try: tile = random.choice(lists.all_tiles) pos_chosen = random.choice(tile.coords) actors.spawnAnything(surface, loadImages.loadImages( r'./art/man/', 'png'), pos=pos_chosen) except IndexError as e: print str(e).upper(), 'grid\'s probably not made, right click and try again'
def assLimbs(self): """assembles the jets, weapons, mods on top of the body surface""" #right now it's just flames, but there'll be more later #load flames and make that the list of surfaces to use self.surfaceLimbsList = loadImages.loadImages(r'./art/flames/', r'png', (16, 16)) #load the right flame based on the limbsNum self.surfaceLimbsPart = self.surfaceLimbsList[self.limbsNum] #print 'self.limbsNum', self.limbsNum #finalize the surface will all the limbs on it self.surfaceLimbs = self.surfaceLimbsPart self.surfaceLimbs.set_colorkey(constants.TRANS)
def assemble2(self, images, index): """takes all the images and deals with them, returning the right one""" self.spriteList = images #main body surface try: self.bodySurface = self.spriteList[index] except TypeError: print 'error, only one surface' self.bodySurface = self.spriteList #etc stuff, flames, turrets etc self.etc = {} if self.actType == 'ship': flames = loadImages.loadImages(r'./art/flames/', 'png', (16, 16)) self.etc['flames'] = flames
def preprocessing(): img73, img87 = loadImages() featLearn = selectFeatureVectors(img73, 500) return featLearn, img73, img87
def keyHandler(e, surface): """handles only keyboard""" #letter keys #try: #if chr(e.key) in range(256): #isLetter = 1 #else: #isLetter = 0 if e.type == PG.KEYDOWN and e.key in xrange(256): print 'caught the "', chr(e.key), '" key' #save the keydown key lists.keysDown.append(chr(e.key)) #print 'added', e.key #movement if chr(e.key) in movementCtrlsDict.keys(): print 'start movement controls' movementControls(movementCtrlsDict[chr(e.key)], surface) print 'end movement controls' #shooter elif chr(e.key) in shooterCtrlsDict.keys(): print 'start shooter controls' shooterControls(shooterCtrlsDict[chr(e.key)]) print 'end shooter controls' #debug elif chr(e.key) in debugCtrlsDict.keys(): print 'start debug controls' debugControls(debugCtrlsDict[chr(e.key)], surface) print 'end debug controls' #other else: print e.key, 'is not assigned to a list' if isKey(e.key,'l'): flames = loadImages.loadImages(r'./art/flames/', 'png', (16, 16)) lists.flames = flames constants.FLAMES = True elif isKey(e.key,'z'): plr = lists.ANYTHINGs[0] #create a random anything instance lists.ANYTHINGs[0].point2 = toolsV2.vectors.rectPerimeter( lists.ANYTHINGs[0].rect, lists.ANYTHINGs[0].direction) #new way lists.ANYTHINGs[0].point2 = toolsV2.vectors.intersect_perimeter( plr.direction[0], plr.direction[1], plr.rect.w, plr.rect.h, ) plr.point2 = toolsV2.vectors.add(plr.point2, plr.rect.center) elif isKey(e.key,'m'): x, y = lists.ANYTHINGs[0].pos() PG.mouse.set_pos(x, y) elif isKey(e.key, 'q'): print 'facing', lists.ANYTHINGs[0].facing print 'direction', lists.ANYTHINGs[0].direction print 'pos', lists.ANYTHINGs[0].pos() print 'mouse', PG.mouse.get_pos() elif isKey(e.key, 'h'): #loads the image of a house and counts the points that are transparent house = loadImages.loadImages(r'./art/house/', 'house1.png', 'orig') trans_points = [] colorkey = house.get_colorkey() for x in xrange(house.get_rect().w-1): for y in xrange(house.get_rect().h-1): color = house.get_at((x, y)) if color == colorkey: trans_points.append((x, y)) pass #adds the transparent points to the list lists.DEBUGs['house'] = house, trans_points print 'number of transparent points in house', len(trans_points) elif isKey(e.key, 'p'): global path_found path_found = pathing.AStar(lists.TILEs[0][0], lists.TILEs[10][22]) elif e.type == PG.KEYUP and e.key in xrange(256): lists.keysDown.remove(chr(e.key)) #print 'removed', e.key, lists.keysDown mixedList = [k for k in lists.keysDown if k in movementCtrlsDict.keys()] #print 'mixed', len(mixedList) if len(mixedList) == 0: lists.ANYTHINGs[0].moving = False
np.linalg.norm( texture_repr_concat_vector[class1] - texture_repr_concat_vector[class2], 2, 0)) texture_repr_mean_between.append( np.linalg.norm( texture_repr_mean_vector[class1] - texture_repr_mean_vector[class2], 2, 0)) print("Bag of words ratio: ", np.average(bow_repr_within) / np.average(bow_repr_between)) print( "Texture concatenated ratio: ", np.average(texture_repr_concat_within) / np.average(texture_repr_concat_between)) print( "Texture mean ratio: ", np.average(texture_repr_mean_within) / np.average(texture_repr_mean_between)) if __name__ == "__main__": i = loadImages() # computeTextureReprs(cv2.imread(os.path.abspath(os.path.join(i.imagesPath, i.imagesVector[0]))), loadmat( # os.path.abspath(os.path.join(i.filters, 'leung_malik_filter.mat')))['F']) # location_points, scores, Ixx, Iyy = extract_keypoints(cv2.imread( # os.path.abspath(os.path.join(i.imagesPath, i.imagesVector[5])))) # part3(os.path.abspath(os.path.join(i.imagesHybridazation, i.imagesHybridazationVector[0])), os.path.abspath( # os.path.join(i.imagesHybridazation, i.imagesHybridazationVector[1]))) # part7(i)
def explode(self): """changes the drawable surface to an explosion""" self.surface = loadImages.loadImages(r'./art/explosion/', 'png', (16, 16))