def setUp(self): self.programa = Program("FirstProgram", 5) self.programaB = Program("SecondProgram") self.instruccionA = Instruccion("Accion 1") self.instruccionB = Instruccion("Accion 2") self.instruccionC = Instruccion("Accion 3") self.instruccionD = IOInstruccion("Imprimir Pagina. ", "Printer") self.instruccionE = IOInstruccion("Leer CD. ", "CDROM")
def preprocess(self, program: Program) -> None: # print(f"PREPROCESSING { program.sourceFile }") lines = program.source.replace("\t", " ").split("\n") program.preprocessed.clear() program.preprocessed.append(f"__source__ { program.sourceFile }") program.preprocessed.append(f"__line__ {1}") for ix, line in enumerate(lines): parts = line.split(" ") if parts[0] == "IMPORT": if len(parts) == 2: sourceFile = os.path.join(program.sourceFolder, parts[1]) include = Program(sourceFile) preproc = Preprocessor() preproc.preprocess(include) program.preprocessed = program.preprocessed + include.preprocessed program.preprocessed.append( f"__source__ { program.sourceFile }") program.preprocessed.append(f"__line__ {ix + 2}") else: raise PreprocessorError("SYNTAX ERROR", ix, program.sourceFile) else: program.preprocessed.append(line)
def __init__(self, x, y, z, Width, Height, Depth, life, speed, name, centered=False): self.name = name self.pos = vec3(x, y, z) self.scale = vec3(Width, Height, Depth) self.rotation = 0 self.worldMatrix = None self.setWorldMatrix() self.Width = Width self.Height = Height self.Depth = Depth self.life = life self.speed = speed #self.hitBox = BoundingBox(self.pos, vec3(x+Width, y+Height, z+Depth)) self.deathFadeT = globs.bulletLife self.State = globs.ALIVE self.fadeTime = 0 self.centered = centered if Entity.vao == None: vbuff = array.array("f") centerVbuff = array.array("f") tbuff = array.array("f") centerTBuff = array.array("f") ibuff = array.array("I") centerIBuff = array.array("I") Shapes.createSquare( vbuff, 1, 1, 0, 0) #create vbuff of square that is 1 by 1 at center of screen Shapes.createSquare(centerVbuff, 1, 1, 0, 0, True) Shapes.createSquareIndexArray(ibuff) Shapes.createSquareIndexArray(centerIBuff, True) Shapes.createSquareTextureArray(tbuff) Shapes.createSquareTextureArray(centerTBuff, 1, True) Entity.vao = glCommands.setup(vbuff, tbuff, ibuff) Entity.centerVao = glCommands.setup(centerVbuff, centerTBuff, centerIBuff) Entity.ibuffSize = len(ibuff) Entity.ibuffCenterSize = len(centerIBuff) Entity.ibuffStart = 0 Entity.prog = Program("vs.txt", "fs.txt")
def __init__(self, x, y, direction, Width, Height, life, speed): self.pos = math3d.vec2(x, y) self.scale = math3d.vec2(Width, Height) self.Width = Width self.Height = Height self.dir = direction self.life = life self.speed = speed self.hitBox = BoundingBox(self.pos, math3d.vec2(x + Width, y + Height)) self.deathFadeT = globs.bulletLife self.State = globs.ALIVE self.fadeTime = 0 if Entity.vao == None: vbuff = array.array("f") tbuff = array.array("f") ibuff = array.array("I") Entity.ibuffSize = len(ibuff) Entity.ibuffStart = 0 Shapes.createSquare( vbuff, 1, 1, 0, 0) #create vbuff of square that is 1 by 1 at center of screen Shapes.createSquareIndexArray(ibuff) Shapes.createSquareTextureArray(tbuff) Entity.vao = glCommands.setup(vbuff, tbuff, ibuff) Entity.ibuffSize = len(ibuff) Entity.ibuffStart = 0 Entity.prog = Program("vs.txt", "fs.txt")
def mutate(self, mother): child = Program.Program('Mutant', self.config) child.assignments['preloop'] = [] for assignment in mother.assignments['preloop']: new_assignment = Program.Assignment( self.config, assignment.variable, False, np.random.normal( assignment.lhs, self.config.CONST_MATING_DRIFT * abs(assignment.lhs))) child.assignments['preloop'].append(new_assignment) if ('const' in assignment.variable): child.consts['loop'].append(assignment.variable) child.consts['global'].append(assignment.variable) tree_mother = copy.deepcopy(mother.loop_tree) crossover_mother = rec_select_random_tree_node(tree_mother) crossover_direction = random.choice(['LEFT', 'RIGHT']) if (crossover_direction == 'LEFT'): crossover_mother.left_child = rec_create_random_tree( self.config, child.consts['loop']) else: crossover_mother.right_child = rec_create_random_tree( self.config, child.consts['loop']) child.loop_tree = tree_mother child.rec_reduce() return child
def setup(): globs.camera = Camera(vec3(0, 0, 1), vec3(0, 0, 0), vec3(0, 1, 0), 3.14 / 4, 0.1, 1000) globs.pewSound = Mix_LoadWAV(os.path.join("assets", "pew.ogg").encode()) glEnable(GL_MULTISAMPLE) glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LEQUAL) glClearColor(0, 0, 0, 0) globs.starProg = Program("starvs.txt", "starfs.txt") globs.mainProg = Program("vs.txt", "fs.txt") globs.shipProg = Program("shipvs.txt", "shipfs.txt") globs.boss = Mesh(os.path.join("assets", "toothyjaws.obj.mesh")) globs.boss.pos = vec3(3.5, 0, 0) globs.starVao = makeStars() glEnable(GL_PROGRAM_POINT_SIZE) globs.player = Ship() globs.enemyShips.append(EnemyShip()) globs.enemySins.append(EnemySin()) #drawBackground() glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) Program.setUniform("screenSize", globs.screenSize) Program.updateUniforms() globs.charge = Text("Roboto-Black.ttf", 26) globs.chargeCount = 0 global lightPositions #change x*4 to suit num lights lightPositions = array.array("f", [0] * 1 * 4) lightColors = array.array("f", [0] * 1 * 4) idx = 0 lightPositions[idx] = 0 #x lightPositions[idx + 1] = 1 #y lightPositions[idx + 2] = 1 #z lightPositions[idx + 3] = 0 #w, 0-directional or 1-positional lightColors[idx] = 1.5 lightColors[idx + 1] = 0 lightColors[idx + 2] = 0 Program.setUniform("lightPositions[0]", lightPositions) Program.setUniform("lightColors[0]", lightColors)
def setup(self, vertexBuff, indexBuff=None): glEnable(GL_MULTISAMPLE) glClearColor(0, 0, 0, 1.0) self.bindVao(vertexBuff) prog = Program("vs.txt", "fs.txt") prog.use()
def __init__(self, pos, meshName): self.pos = pos.xyz self.worldMatrix = translation3(self.pos) self.mesh = None if MapRoom.prog == None: MapRoom.prog = Program("vs.txt", "fs.txt") self.setMesh(meshName)
def main(): """The main function""" url = "https://www.dane.gov.pl/media/resources/20190520/Liczba_os%C3%B3b_kt%C3%B3re_" \ "przystapi%C5%82y_lub_zda%C5%82y_egzamin_maturalny.csv" # url with csv file program = Program.Program(url) # make an instance of Program class interface = Interface.Interface() # make an instance of Interface class interface.draw_interface() # drawing an interface interface.main_loop(program) # main loop of the program
def setup(vertexBuff, textureBuff, indexBuff=None): glEnable(GL_MULTISAMPLE) glClearColor(0, 0, 0, 1.0) vao = bindVao(vertexBuff, textureBuff, indexBuff) prog = Program("vs.txt", "fs.txt") prog.use() return vao
def __init__(self, x, y): self.pos = math3d.vec2(x, y) if StarBackground.vbuff == None: StarBackground.vbuff = array.array("f") StarBackground.tbuff = array.array("f") Shapes.createRandPoints(StarBackground.vbuff, globs.numStars) Shapes.createSquareTextureArray(self.tbuff) StarBackground.vao = glCommands.setup(StarBackground.vbuff, StarBackground.tbuff) StarBackground.tex = ImageTexture2DArray(*globs.starTextures) StarBackground.prog = Program("vs.txt", "fs.txt")
def __init__(self, pos, meshName, shininess): self.pos = pos.xyz self.worldMatrix = translation3(self.pos) self.mesh = None self.Light = LightObj(vec3(0, .5, 1), vec3(1, 1, 1)) self.alpha = 1 self.shininess = shininess if MapRoom.prog == None: MapRoom.prog = Program("vs.txt", "fs.txt") self.setMesh(meshName)
def parse_input(input): lexer = PiLexer(input) stream = CommonTokenStream(lexer) parser = PiParser(stream) tree = parser.program() listener = Listener() walker = ParseTreeWalker() walker.walk(listener, tree) assert len(listener.state) == 0 program = Program(listener.definitions, listener.limit, listener.helpers) return program
def __init__(self, x, y, size): self.pos = math3d.vec2(x, y) self.size = size if mapSquare.vbuff == None or mapSquare.tbuff == None or mapSquare.ibuff == None: mapSquare.vbuff = array.array("f") mapSquare.tbuff = array.array("f") mapSquare.ibuff = array.array("I") mapSquare.tex = ImageTexture2DArray(globs.mapTextures) Shapes.createSquare(mapSquare.vbuff, self.size, self.pox.x, self.pos.y) Shapes.createSquareIndexArray(mapSquare.ibuff) glCommands.setup(mapSquare.vbuff, mapSquare.ibuff, mapSquare.tbuff) mapSquare.prog = Program("vs.txt", "fs.txt")
def processData(rawData): main = processFunction(rawData['main'], 'main') program = Program(main) if 'fun1' in rawData: f1 = processFunction(rawData['fun1'], 'fun1') program.addFunction(f1) if 'fun2' in rawData: f2 = processFunction(rawData['fun2'], 'fun2') program.addFunction(f2) return program
def __init__(self,bt): QtGui.QMainWindow.__init__(self) self.bt = bt # Set up the user interface from Designer. self.ui = uic.loadUi(UI_FILE) self.ui.show() sc = TehFigure(self.ui.plotlayout) self.HLT = XTun(self.ui, bt, "h", self.ui.HLTSet, self.ui.HLTTemp, self.ui.toggleHLT, self.ui.HLTdial,self.ui.HLTPower) self.MLT = XTun(self.ui, bt, "m", self.ui.MLTSet, self.ui.MLTTemp, self.ui.toggleMLT, self.ui.MLTdial,self.ui.MLTPower) self.programstatus = Program(self.ui, bt,sc,self.ui.tableView)
def setup(): glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_MULTISAMPLE) samp = Sampler() samp.bind(0) glClearColor(0.2,0.4,0.6,0) prog = Program("vs.txt","fs.txt") prog.use() globs.car = Car()
def parse(self): tok = self.lex.get_next_token() self.match(tok, TokenType.FUNC_KW_TOK) id_var = self.get_id() tok = self.lex.get_next_token() self.match(tok, TokenType.OPEN_PAREN_TOK) tok = self.lex.get_next_token() self.match(tok, TokenType.CLOSE_PAREN_TOK) block = self.get_block() tok = self.lex.get_next_token() self.match(tok, TokenType.END_KW_TOK) tok = self.lex.get_next_token() self.match(tok, TokenType.EOS_TOK) return Program.Program(block)
def AddProgramIfThereIsntOne(self): # check if there is already a program in the document doc = cad.GetApp() object = doc.GetFirstChild() while object != None: if object.GetType() == Program.type: self.program = object return object = doc.GetNextChild() # add a program self.program = Program.Program() programs.append(self.program) self.program.add_initial_children() cad.AddUndoably(self.program)
def __init__(self, startPos): self.life = globs.particleLife self.currentTime = 0 self.startTime = 0 self.worldMatrix = translation2(startPos) if ParticleSystem.vao == None: vbuff = array.array("f") tbuff = array.array("f") Shapes.createRandPoints(vbuff, globs.particleCount) #Create randomVelocities tbuff = Shapes.createSquareTextureArray(tbuff) ParticleSystem.vao = glCommands.setup(vbuff, tbuff) ParticleSystem.vSize = len(vbuff) ParticleSystem.tex = ImageTexture2DArray(globs.starTextures[0]) ParticleSystem.prog = Program("particleVS.txt", "particleFS.txt")
def parse(src): i = 0 prog = Program.Program() lines, lastnewline = 1, -1 # so can give error locations as line:char tokenstart = 0, 1, 1 # byte, line, char state = 0 while i < len(src): while i < len(src) and src[i] not in (A, B, C): i += 1 if i >= len(src): break if state == 0: tokenstart = (i, lines, i - lastnewline) if src[i] == "\n": lines += 1 lastnewline = i next = DFA[(state, src[i])] action = type(next) if action is int: # next state in tree state = next elif action is tuple: # next opcode state = 0 opcode, parameter = next if parameter is int: (x, i) = parseNumber(src, i + 1) lines += 1 # parseNumber will end on a \n lastnewline = i prog.programdata.append(opcode(tokenstart, x)) elif parameter is str: (x, i) = parseString(src, i + 1) lines += 1 lastnewline = i prog.programdata.append(opcode(tokenstart, x)) else: prog.programdata.append(opcode(tokenstart)) else: # invalid state print( "Error parsing script: %s is not a valid command at byte 0x%X (line %d char %d)\n" % ((next, ) + tokenstart)) print("Program so far: ", repr(prog)) return None i += 1 # find all the labels for i in range(len(prog.programdata)): if prog.programdata[i].opcode == Program.Opcodes.Label: prog.labels[prog.programdata[i].label] = i return prog
def __init__(self, pos, meshName, shininess): self.pos = pos.xyz self.worldMatrix = translation3(self.pos) self.mesh = None self.Light = LightObj( vec3(0, .5, 1), # Position vec3(.3, .7, 1), # Color vec3(.1,.6,1), # Attenuation 1, # Positional 0 or 1 -1, # Spotlight angle -1 for omnidirectional vec3(0,0,1)) # Spotlight Dir self.alpha = 1 self.shininess = shininess if MapRoom.prog == None: MapRoom.prog = Program("vs.txt", "fs.txt") self.setMesh(meshName)
def create_random_program(config): program = Program.Program('Alien', config) n_consts = abs( int(np.random.normal(config.N_CONSTS_EV, config.N_CONSTS_SD))) for i in range(n_consts): value = create_random_const(config) const = 'const_' + str(random.getrandbits(100)) program.consts['loop'].append(const) program.consts['global'].append(const) assignment = Program.Assignment(config, const, False, value) program.assignments['preloop'].append(assignment) program.loop_tree = rec_create_random_tree(config, program.consts['loop']) program.rec_reduce() return program
def __init__(self, fontname, size): if Text.prog == None: Text.prog = Program("TextVertexShader.txt", "TextFragmentShader.txt") self.txt = "temp" self.samp = Sampler() self.font = TTF_OpenFont( os.path.join("assets", fontname).encode(), size) open(os.path.join("assets", fontname)) vbuff = Buffer(array.array("f", [0, 0, 1, 0, 1, 1, 0, 1])) ibuff = Buffer(array.array("I", [0, 1, 2, 0, 2, 3])) tmp = array.array("I", [0]) glGenVertexArrays(1, tmp) self.vao = tmp[0] glBindVertexArray(self.vao) ibuff.bind(GL_ELEMENT_ARRAY_BUFFER) vbuff.bind(GL_ARRAY_BUFFER) glEnableVertexAttribArray(0) glVertexAttribPointer(0, 2, GL_FLOAT, False, 2 * 4, 0) glBindVertexArray(0) self.tex = DataTexture2DArray(1, 1, 1, array.array("B", [0, 0, 0, 0])) self.textQuadSize = vec2(0, 0) self.pos = vec2(0, 0) self.dirty = False surf1p = TTF_RenderUTF8_Blended(self.font, self.txt.encode(), SDL_Color(255, 255, 255, 255)) surf2p = SDL_ConvertSurfaceFormat(surf1p, SDL_PIXELFORMAT_ABGR8888, 0) w = surf2p.contents.w h = surf2p.contents.h pitch = surf2p.contents.pitch if pitch != w * 4: print("Uh Oh!", pitch, w) pix = surf2p.contents.pixels B = string_at(pix, pitch * h) self.tex.setData(w, h, 1, B) SDL_FreeSurface(surf2p) SDL_FreeSurface(surf1p) self.textQuadSize = vec2(w, h) self.dirty = False Program.setUniform("textPosInPixels", self.pos) Program.setUniform("textQuadSizeInPixels", self.textQuadSize) Program.updateUniforms()
def __init__(self, fontname, size): if Text.prog == None: Text.prog = Program("textvs.txt", "textfs.txt") TTF_Init() self.font = TTF_OpenFont( os.path.join("assets", fontname).encode(), size) vbuff = Buffer(array.array("f", [0, 0, 1, 0, 1, 1, 0, 1])) ibuff = Buffer(array.array("I", [0, 1, 2, 0, 2, 3])) tmp = array.array("I", [0]) glGenVertexArrays(1, tmp) self.vao = tmp[0] glBindVertexArray(self.vao) ibuff.bind(GL_ELEMENT_ARRAY_BUFFER) vbuff.bind(GL_ARRAY_BUFFER) glEnableVertexAttribArray(0) glVertexAttribPointer(0, 2, GL_FLOAT, False, 2 * 4, 0) glBindVertexArray(0) self.tex = DataTexture2DArray(1, 1, 1, array.array("B", [0, 0, 0, 0])) self.textQuadSize = vec2(0, 0) self.pos = vec2(0, 0) self.dirty = False
def setup(pointArray): glEnable(GL_MULTISAMPLE) glClearColor(0, 0, 0, 1.0) my_buffer = Buffer(pointArray)#array.array("f", [0, 0])) # GenerateVAO tmp = array.array("I", [0]) glGenVertexArrays(1, tmp) vao = tmp[0] glBindVertexArray(vao) # Tell GL about buffer layout and use the buffer my_buffer.bind(GL_ARRAY_BUFFER) glEnableVertexAttribArray(0) # which pipe, items per vertex, type per item, auto-normalize, data size per item in bytes, start in buffer # numPoints = len(arrayOfPoints) glVertexAttribPointer(0, 2, GL_FLOAT, False, 2 * 4, 0) # unbind # glBindVertexArray(0) prog = Program("vs.txt", "fs.txt") prog.use()
def main(): f = open("input.txt", "r") inp = f.read().strip() res = None i = 0 program = None while res is None: program = Program.Program(inp) (op_code, argument) = program.program[i] if (op_code != nop.nop) & (op_code != Jump.jump): i += 1 continue if op_code == nop.nop: program.program[i] = Jump.jump, argument else: program.program[i] = nop.nop, argument res = program.start() i += 1 print(i) (res, cmp) = res print(cmp.accumulator)
def setup(): global starAmount global starsVao global quadProg global StarProgram global ShipProg global beep global enemyProg global enemy1Prog global backgroundProg global main_program global monster_program global ship global fire global enemy global enemy1 global nebula global powerup global powerup1 global cam global monster global starList global bullet1 global myShip global skyboxProg global skybox global skyboxTexture beep = Mix_LoadWAV(os.path.join("assets", "Beep-09.ogg").encode()) glEnable(GL_MULTISAMPLE) glClearColor(0.0, 0.0, 0.0, 1.0) starAmount = 50 starList = [] star_points = [] for i in range(starAmount): starList.append(Star()) for i in range(len(starList)): star_points.append(starList[i].x) star_points.append(starList[i].y) A = array.array("f", star_points) b = Buffer(A) tmp = array.array("I", [0]) glGenVertexArrays(1, tmp) starsVao = tmp[0] glBindVertexArray(starsVao) b.bind(GL_ARRAY_BUFFER) glEnableVertexAttribArray(0) glVertexAttribPointer(0, 2, GL_FLOAT, False, 2 * 4, 0) glBindVertexArray(0) myShip = Ship() cam = Camera(myShip.pos, myShip.up, myShip.facing) for i in range(3): asteroid_list.append(Asteroid(vec4(0, 0, 0, 0))) skyboxTexture = ImageTextureCube("nebula-%04d.jpg") skybox = Mesh("cube.obj.mesh") skybox.materials[0].tex = skyboxTexture skyboxProg = Program("skyboxVertexShader.txt", "skyboxFragmentShader.txt") StarProgram = Program("StarsVertexShader.txt", "StarsFragmentShader.txt") main_program = Program("MainVS.txt", "MainFS.txt") glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LEQUAL) Program.setUniform("lightPos", vec3(0, 1, -1) + myShip.pos.xyz) #vec3(0,1,-1) Program.updateUniforms() print("Setup Done")
IoInstruccion2 = IOInstruccion("Imprimir Pagina 2. ", "Printer") IoInstruccion3 = IOInstruccion("Imprimir Pagina 3. ", "Printer") IoInstruccion4 = IOInstruccion("Imprimir Pagina 4. ", "Printer") IoInstruccion5 = IOInstruccion("Imprimir Pagina 5. ", "Printer") IoInstruccion6 = IOInstruccion("Leer Pista 1. ", "CDROM") IoInstruccion7 = IOInstruccion("Leer Pista 2. ", "CDROM") IoInstruccion8 = IOInstruccion("Leer Pista 3. ", "CDROM") IoInstruccion9 = IOInstruccion("Leer Pista 4. ", "CDROM") IoInstruccion10 = IOInstruccion("Leer Pista 5. ", "CDROM") CpuInstruccion1= Instruccion("Instruccion de CPU #1") CpuInstruccion2= Instruccion("Instruccion de CPU #2") CpuInstruccion3= Instruccion("Instruccion de CPU #3") CpuInstruccion4= Instruccion("Instruccion de CPU #4") CpuInstruccion5= Instruccion("Instruccion de CPU #5") Programa1 = Program("Programa1") Programa1.add(CpuInstruccion1) Programa1.add(CpuInstruccion2) Programa1.add(IoInstruccion1) Programa1.add(IoInstruccion5) Programa1.add(CpuInstruccion4) Programa2 = Program("Programa2",2) Programa2.add(CpuInstruccion4) Programa2.add(CpuInstruccion5) Programa2.add(IoInstruccion3) Programa2.add(IoInstruccion6) Programa2.add(CpuInstruccion5) Programa2.add(IoInstruccion4) Programa2.add(IoInstruccion7) Programa2.add(CpuInstruccion3) Programa2.add(IoInstruccion5)
def CreateProgram(): return Program.Program() def CreateTool(): return Tool.Tool()