Press enter to skip the top menu

Computer Graphics CS

Layering

                    import Layering_Modules
                    def main():
                        intMaxRows=800
                        intMaxCols=800

                        for fileIndexer in range(1,90):
                            arrPage1=[]
                            arrPage2=[]
                            arrTemp=[]
                            fileName="Layered Image"+str(fileIndexer)+".pbm"
                            file1=open(fileName,"r")
                            strData=file1.readline()
                            if strData=="P1\n":
                                strByte=file1.read(1)
                                while strByte != " ":
                                    strByte=file1.read(1)
                                strByte=file1.read(1)
                                while strByte!="\n":
                                    strByte=file1.read(1)
                                #The above six lines read the control data at the start of the pbm file
                                #and leave the pointer at the first byte of actual data
                                for intRowCounter in range(intMaxRows):
                                    for intColCounter in range(intMaxCols):
                                        arrTemp.append(file1.read(1))
                                    arrPage1.append(arrTemp)
                                    file1.read(1)
                                    arrTemp=[]
                                file1.close()
                                fileName="Rotation"+str(fileIndexer)+".pbm"
                                file1=open(fileName,"r")
                                strData=file1.readline()
                                if strData=="P1\n":
                                    strByte=file1.read(1)
                                    while strByte != " ":
                                        strByte=file1.read(1)
                                    strByte=file1.read(1)
                                    while strByte!="\n":
                                        strByte=file1.read(1)
                                    #The above six lines read the control data at the start of the pbm file
                                    #and leave the pointer at the first byte of actual data
                                    for intRowCounter in range(intMaxRows):
                                        for intColCounter in range(intMaxCols):
                                            arrTemp.append(file1.read(1))
                                        arrPage2.append(arrTemp)
                                        file1.read(1)
                                        arrTemp=[]
                                    file1.close()
                                    for intRowCounter in range(intMaxRows):
                                        for intColCounter in range(intMaxCols):
                                            if arrPage1[intRowCounter][intColCounter]=='1':
                                                arrPage2[intRowCounter][intColCounter]='1'
                                Layering_Modules.saveFile(arrPage2,intMaxRows,intMaxCols,"Layered Double",fileIndexer)
                    
                    if __name__ == "__main__":
                        main()

                
                    def createArray(passedValue):
                        strOutString=""
                        for intVal in passedValue:     
                            strOutString=strOutString+str(intVal)
                        return strOutString
                    
                    def createBackground(maxWidth,maxHeight):
                        #initialises image to white
                        arrAll=[]
                        arrRow=[]
                        for intRows in range(maxWidth):
                            for intCols in range(maxWidth):
                                arrRow.append(0)
                            arrAll.append(arrRow)
                            arrRow=[]
                        return arrAll
                    
                    def saveFile(arrAll, maxRows, maxCols,fileName, versionNumber):
                        myfile=open(fileName+str(versionNumber)+".pbm",'w')
                        myfile.write('P1' +"\n")
                        myfile.write(str(maxRows)+" "+str(maxCols)+"\n")
                        for intRows in range(maxRows):
                            myfile.write(createArray(arrAll[intRows])+"\n")
                        myfile.close()