def __init__(self, metaData): self.metaData = metaData self.size = 10 self.posx = random.randint(self.size, self.metaData.width - self.size) self.posy = random.randint(self.size, self.metaData.height - self.size) self.color = colors.Colors().YELLOW self.life = random.randint(120, 360)
def convert_lasagne_to_pytorch(lasagne_weight_file, path_to_save_pytorch_model): COLORS = col.Colors() pytorch_model = build_pytorch_model() lasagne_model = build_lasagne_model(height=720, width=1280) lasagne_load_weights(lasagne_model, lasagne_weight_file) pytorch_model_dict = pytorch_model.state_dict() lasagne_params = lasagne.layers.get_all_params(lasagne_model['fuse3']) lasagne_names = [ par.name for par in lasagne_params ] for (lasagne_name, lasagne_param, pytorch_key) in zip(lasagne_names, lasagne_params, pytorch_model_dict): pytorch_shape = () for each_dim in range(pytorch_model_dict[pytorch_key].dim()): # this is length of tensor pytorch_shape = pytorch_shape +(pytorch_model_dict[pytorch_key].size(each_dim),) # print pytorch_key, pytorch_shape if lasagne_param.get_value().shape == pytorch_shape: print "lasagne {:>12} {:>15} <===> pytorch {:>12} {:>12}".format(lasagne_name, lasagne_param.get_value().shape,\ pytorch_key, pytorch_shape) pytorch_model_dict[pytorch_key] = torch.from_numpy(lasagne_param.get_value()).float() else: # last convlayer in pytroch is (2,64,3,3) instead of (64,2,3,3) print COLORS.RED, "ERROR at ", "lasagne_name", lasagne_name, lasagne_param.get_value().shape, \ " :::: pytorch", pytorch_key, pytorch_shape, COLORS.ENDC print COLORS.BLUE, "I am reshaping lasagne weight from {} to {}".\ format(lasagne_param.get_value().shape, pytorch_shape), COLORS.ENDC lasagne_weight = lasagne_param.get_value() pytorch_model_dict[pytorch_key] = torch.from_numpy(lasagne_weight.reshape(pytorch_shape)).float() # print lasagne_param.get_value() # print pytorch_model_dict[pytorch_key] # print "\n\n\n\n\n\n" # pdb.set_trace() pytorch_model.load_state_dict(pytorch_model_dict) # assign weights to the model's state dict torch.save(pytorch_model.state_dict(), path_to_save_pytorch_model)
def __init__(self, posx, posy, width, height, text=None, backGroundColor=(0, 0, 0), onClickEvent=None, border=0, txtColor=None): self.posx = posx self.posy = posy self.width = width self.height = height self.text = text self.backGroundColor = backGroundColor self.defaultColor = (109, 232, 102) self.button = pygame.Rect(self.posx - self.width // 2, self.posy - self.height // 2, self.width, self.height) self.border = border if onClickEvent != None: self.onClickEvent = onClickEvent if txtColor == None: self.txtColor = colors.Colors().WHITE # default to white else: self.txtColor = txtColor
def draw(self): if not self.isDead: # update the current color self.color = colors.Colors().addTwoColors( self.colorOffset, self.metaData.gameData.instantColor) pygame.draw.circle(self.metaData.screen, self.color, (int(self.posx), int(self.posy)), int(self.size))
def draw(self): # update the color self.color = colors.Colors().addTwoColors( self.metaData.gameData.instantColor, self.colorOffset) # draw the box self.rect = pygame.Rect(self.posx, self.posy, self.size, self.length) self.rect.centerx = self.posx self.rect.centery = self.posy pygame.draw.rect(self.metaData.screen, self.color, self.rect, 0)
def __init__(self, metaData, size=None, speed=None): super().__init__(metaData, size=size, speed=speed) self.spawnRate = 4 self.rect = pygame.Rect(self.posx, self.posy, self.size, self.size) self.colorOffset = (0, 10, 0) self.color = colors.Colors().addTwoColors( self.metaData.gameData.instantColor, self.colorOffset) self.minSize = self.size self.maxSize = self.minSize * 1.5 self.growFactor = 1
def __init__(self, metaData): self.metaData = metaData self.posx = self.metaData.width // 2 self.posy = self.metaData.height // 2 self.textColor = (0, 0, 0) # black self.size = 50 self.colors = colors.Colors() self.cursorPos = pygame.mouse.get_pos() self.rect = pygame.Rect(self.cursorPos, (self.size, self.size)) self.color = self.colors.GREEN
def __init__(self, metaData, size=None, speed=None): super().__init__(metaData, size=size, speed=speed) self.spawnRate = 0.25 self.size = 30 self.rotationSpeed = self.speed self.currRotation = 0 # in degreed self.gunBarrelWidth = 20 self.colorOffset = (0, 0, 50) self.color = colors.Colors().addTwoColors( self.colorOffset, self.metaData.gameData.instantColor) self.gunDistanceFromCenter = self.size // 2 self.gunSize = self.size // 4
def draw(self): self.calculateCenterCoordinates() # update the color self.color = colors.Colors().addTwoColors( self.colorOffset, self.metaData.gameData.instantColor) # the shooty spinny enemy is made up of two pieces - the circle, and the rectangle gun = self.getGunData() pygame.draw.circle(self.metaData.screen, self.color, gun, self.gunDistanceFromCenter // 2) # draw the circle pygame.draw.circle(self.metaData.screen, self.color, (self.centerx, self.centery), self.size // 2)
def __init__(self): super().__init__(command_prefix='?', description='Self-service role and color assignment.', help_command=formatter.FancyFormatter()) self._help_text = 'say ?help in #bot-' # This is scary but it seems to be needed to get a cog-less command. self.command(name="adminhelp")(adminhelp) self.add_check(self.is_allowed) self.add_cog(admintools.AdminTools(self)) self.add_cog(autoroles.AutoRoles(self)) self.add_cog(colors.Colors(self)) self.add_cog(optroles.OptRoles(self))
def parse_obj_par(line): """Take object characteristis from string. Input string format: X_coord Y_coord Velocity_X Velocity_Y Mass Radius Color Parametrs: **line** — string with object characteristics. """ color = cl.Colors() obj = Object() obj.coords[0] = float(line.split()[0]) obj.coords[1] = float(line.split()[1]) obj.vel[0] = float(line.split()[2]) obj.vel[1] = float(line.split()[3]) obj.mass = float(line.split()[4]) obj.rad = float(line.split()[5]) obj.color = color.COLORS[int(line.split()[6])] return obj
def __init__(self, metaData, posx, posy, rotation, size, speed=None, color=None): super().__init__(metaData) self.posx = posx self.posy = posy self.speed = 4 self.rotation = rotation self.size = size self.colorOffset = (0, 100, 0) self.color = colors.Colors().addTwoColors( self.colorOffset, self.metaData.gameData.instantColor) self.isDead = False
def __init__(self): pygame.init() self.epsilon = 0 self.pieces = ['I', 'L', 'J', 'O', 'T', 'Z', 'S'] self.color = colors.Colors() self.matrixTetris = [[[1, self.color.GREY] for i in xrange(0, 10)] for j in xrange(0, 20)] self.currentPiece = None self.nextPiece = None self.nextNextPiece = None self.nextP = None self.currentP = None self.size = [580, 600] self.sizeSq = self.size[1] / 22 self.centerX = None self.centerY = None self.fontSize = 15 self.screen = pygame.display.set_mode(self.size) self.timer = 0 self.pause = False #stats self.gamesPlayed = 0 self.piecesPlaced = -2 self.single_piecesPlaced = 0 self.single_lines_1x = 0 self.single_lines_2x = 0 self.single_lines_3x = 0 self.single_lines_4x = 0 self.all_lines_1x = 0 self.all_lines_2x = 0 self.all_lines_3x = 0 self.all_lines_4x = 0 self.highestScore = 0 self.scoreSum = 0 self.averageScore = 0 self.averagePieces = 0 self.singleScore = 0 self.setTetris()
def getMatrix(file='matrix.txt'): color = colors.Colors() newState = [[[1, color.GREY] for i in xrange(0, 10)] for j in xrange(0, 20)] i = 0 j = 0 try: with open(file) as f: while True: c = f.read(1) if not c: break if j == 10: j = 0 i += 1 else: if c.upper() == 'X': newState[i][j][0] = 0 j += 1 return newState except Exception: return
def draw(self): self.calculateCenterCoordinates() # update the color self.color = colors.Colors().addTwoColors( self.colorOffset, self.metaData.gameData.instantColor) # the shooty spinny enemy is made up of two pieces - the circle, and the rectangle tgunx, tguny, lgunx, lguny, rgunx, rguny, bgunx, bguny = self.calculateLeftRightBottomGunsData( self.getGunData()) # draw top gun pygame.draw.circle(self.metaData.screen, self.color, (tgunx, tguny), self.gunDistanceFromCenter // 2) # draw left gun pygame.draw.circle(self.metaData.screen, self.color, (lgunx, lguny), self.gunDistanceFromCenter // 2) # draw right gun pygame.draw.circle(self.metaData.screen, self.color, (rgunx, rguny), self.gunDistanceFromCenter // 2) # draw bottom gun pygame.draw.circle(self.metaData.screen, self.color, (bgunx, bguny), self.gunDistanceFromCenter // 2) # draw the middle circle pygame.draw.circle(self.metaData.screen, self.color, (self.centerx, self.centery), self.size // 2)
def new_team(): """ sert la page de creation d'equipe """ return render_template('new_team.html', colors=colors.Colors())
magtag.set_text(activities.button_text("ABCs", "Songs", "Colors", "Shapes"), index=1, auto_refresh=False) magtag.set_text("Select an Activity", index=4, auto_refresh=True) current_activity = None while current_activity is None: for i, b in enumerate(magtag.peripherals.buttons): if not b.value: if i == 0: current_activity = abc.ABC() elif i == 1: current_activity = songs.Songs() elif i == 2: current_activity = colors.Colors() elif i == 3: current_activity = shapes.Shapes() ################# ################# # Activity runs indefinitely current_activity.clear_text_boxes(magtag, num_text_boxes) current_activity.main_menu(magtag) while True: for i, b in enumerate(magtag.peripherals.buttons): if not b.value: current_activity.action(magtag, i, num_text_boxes, pwm) #################
import colors import urllib import pathlib import json import controlsRenderer import sliderRenderer import devices_renderer import recentSongsRenderer if sys.platform == 'win32': import win32gui import win32con import win32api config = None color_file = colors.Colors() renderer = lyricRenderer.LyricRenderer(color_file) smallFont = None basicFont = None filePath = pathlib.Path(__file__).parent.absolute() def loadConfig(): config = None path = filePath.joinpath('config.json') if path.exists(): with path.open(mode='r') as settingsFile: config = json.load(settingsFile) else: print("No config.json exists. Creating a default one at ." + str(path))
import pygame import colors import random class Game(object): def __init__(self): pygame.init() gameDisplay = pygame.display.set_mode((800, 600)) pygame.display.set_caption('Game') pygame.display.update() Colors = colors.Colors() clock = pygame.time.Clock() def draw(color, rect): gameDisplay.fill(color, rect=rect) def main(): xPos = 300 yPos = 300 width = 3 height = 1 snake = [xPos, yPos, width * 50, height * 50] block = [random.randint(0, 15) * 50, random.randint(0, 15) * 50, 50, 50] direction = 'R' gameExit = False gameDisplay.fill(Colors.white)
def draw(self): # update the color self.color = colors.Colors().addTwoColors( self.metaData.gameData.instantColor, self.colorOffset) # draw the box pygame.draw.rect(self.metaData.screen, self.color, self.rect, 0)
def __init__(self, metaData): super().__init__(metaData) self.color = colors.Colors().WHITE self.size = 1
def getTxtColor(self): if self.metaData.gameDifficulty == self.targDifficulty: self.txtColor = colors.Colors().GREEN else: self.txtColor = colors.Colors().WHITE
''' database.py This file contains a simple JSON storage class. ''' import json import os import classifier import soundfiles import fingerprint import colors c = colors.Colors() class Database: '''A simple JSON storage system.''' DBPREFIX = 'databases/' def __init__(self, name, replace=False, read=True): ''' Database initializer. Reads database if exists. Args: name: name of database. replace: whether to replace or append database. read: whether to load the databse from disk on init. '''
pygame.init() def drawMainMenu(screen, data): data.mainMenu.run(screen) def drawGame(screen, data): data.gameData.runGame() def drawDisplay(screen, data): if data.currScreen == 'menu': drawMainMenu(screen, data) elif data.currScreen == 'game': drawGame(screen, data) colo = colors.Colors() while 1: # run the pygame window for event in pygame.event.get(): if event.type == pygame.QUIT: metaData.CLOSE_GAME = True if metaData.gameData != None: metaData.gameData.musicThread.join() sys.exit() metaData.screen.fill((0, 0, 0)) drawDisplay(metaData.screen, metaData) pygame.display.flip()