From 8b92b6038f8dd38924a26b886604558cf0288e61 Mon Sep 17 00:00:00 2001 From: epitron Date: Fri, 31 Aug 2018 01:48:30 -0400 Subject: [PATCH 1/9] Removed whitespace --- ConwayCL-Final/main.py | 110 ++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/ConwayCL-Final/main.py b/ConwayCL-Final/main.py index 8479e11..1d9196a 100644 --- a/ConwayCL-Final/main.py +++ b/ConwayCL-Final/main.py @@ -6,7 +6,7 @@ from scipy.misc import lena import random as r import datetime as date -import time +import time from PIL import Image import os import tkFileDialog as tfd @@ -30,21 +30,21 @@ def __init__(self, myCL, dimen): #Set the initial size for the generative/host array self.grid_w = self.arraySize[0] self.grid_h = self.arraySize[1] - + #initialise both buffer to 0 in x,y self.current_grid = np.where(myCL.a!=0, 255, 0) def initTexture(self): #data = np.flipud(lena()) #insert test data - + #Set the data source data = self.current_grid w,h = data.shape # generate a texture id self.mytexture = gl.glGenTextures(1) - + #bind? the tex id and some implicit thing? #2D causes epic memory leaks gl.glBindTexture(gl.GL_TEXTURE_3D,self.mytexture) @@ -73,7 +73,7 @@ def initStage(self,w,h): #Perspectives/layouts #L,R,B,T,?,? #gl.glOrtho(-0.1, 1.1, -0.1, 1.1, 0,1) - + """offset = 0.5 x1 = offset+1 x2 = (x1 - 1) *-1 @@ -91,7 +91,7 @@ def initStage(self,w,h): def changeOrtho(self, offset): x1 = offset+1 - x2 = (x1 - 1) *-1 + x2 = (x1 - 1) *-1 y1 = offset+1 y2 = (x1 - 1) *-1 @@ -120,7 +120,7 @@ def doRender(self, pmouse, last_pm): GLR.initStage(GLR.SCREEN_SIZE[0],GLR.SCREEN_SIZE[1]) GLR.changeOrtho(myOrtho) GLR.initTexture() - + offs = GLR.calcOffsets( GLR.SCREEN_SIZE[0], GLR.SCREEN_SIZE[1], pmouse, last_pm) GLR.doDraw(GLR.SCREEN_SIZE[0],GLR.SCREEN_SIZE[1], offs[0], offs[1]) @@ -180,7 +180,7 @@ def execute(self): self.kAutomata.RunAutomata(self.queue, self.a.shape, None, self.ar_ySize, self.a_buf, self.b_buf) # np.int32(self.offset), else: self.kAutomata.RunAutomata(self.queue, self.a.shape, None, self.ar_ySize, self.b_buf, self.a_buf) - + self.tickState = not self.tickState #self.offset += 512 @@ -189,19 +189,19 @@ def execute(self): def build_render(self): if self.tickState == False: self.kUtil.AddToBuffer(self.queue, self.a.shape, None, self.ar_ySize, self.a_buf, self.render_buf) - self.kUtil.BuildFrame(self.queue, self.a.shape, None, self.ar_ySize, self.a_buf, self.render_buf, self.render_buf) + self.kUtil.BuildFrame(self.queue, self.a.shape, None, self.ar_ySize, self.a_buf, self.render_buf, self.render_buf) else: self.kUtil.AddToBuffer(self.queue, self.a.shape, None, self.ar_ySize, self.b_buf, self.render_buf) - self.kUtil.BuildFrame(self.queue, self.a.shape, None, self.ar_ySize, self.b_buf, self.render_buf, self.render_buf) + self.kUtil.BuildFrame(self.queue, self.a.shape, None, self.ar_ySize, self.b_buf, self.render_buf, self.render_buf) #Build Render-layered frame def build_render_no_blur(self): if self.tickState == False: self.kUtil.ReplaceBuffer(self.queue, self.a.shape, None, self.ar_ySize, self.a_buf, self.render_buf) - self.kUtil.BuildFrame(self.queue, self.a.shape, None, self.ar_ySize, self.a_buf, self.render_buf, self.render_buf) + self.kUtil.BuildFrame(self.queue, self.a.shape, None, self.ar_ySize, self.a_buf, self.render_buf, self.render_buf) else: self.kUtil.ReplaceBuffer(self.queue, self.a.shape, None, self.ar_ySize, self.b_buf, self.render_buf) - self.kUtil.BuildFrame(self.queue, self.a.shape, None, self.ar_ySize, self.b_buf, self.render_buf, self.render_buf) + self.kUtil.BuildFrame(self.queue, self.a.shape, None, self.ar_ySize, self.b_buf, self.render_buf, self.render_buf) #Read from GPU buffer to host's array (self.a) @@ -212,7 +212,7 @@ def getData(self): else: self.kUtil.GetWorld(self.queue, self.a.shape, None, self.ar_ySize, self.b_buf, self.dest_buf) cl.enqueue_read_buffer(self.queue, self.dest_buf, self.a).wait() - + #Read from GPU buffer to host's array (self.a) def getRenderData(self): @@ -223,7 +223,7 @@ def getRenderData(self): def getGameState(self): self.kUtil.GetWorld(self.queue, self.a.shape, None, self.ar_ySize, self.render_buf, self.dest_buf) cl.enqueue_read_buffer(self.queue, self.dest_buf, self.gameAr).wait() - + #Seed, fill buffer def seed(self, seedRand): @@ -238,7 +238,7 @@ def seed(self, seedRand): #Return 0s array def zeroWorld(self): self.a = np.zeros((self.ar_ySize,self.ar_ySize), dtype=np.int32) - + #User Input - Place Square def place_square(self,x,y,size): @@ -319,7 +319,7 @@ def bitRender(self, rn, zoom, CLMAXVAL, colour_mode): RGB_array[:,:,2] = np.where(MainCL.a == 1, 255, np.where(MainCL.a != 0, np.where(MainCL.a<128, (MainCL.a*255)/128, np.where(MainCL.a<256,255-((MainCL.a/3)%256),0)), 0)) sp.misc.imsave(name + '.bmp', sp.ndimage.zoom(RGB_array, (zoom,zoom,1), order=0)) - + #Reload kernel and reseed world def reseed(self): if seed_bitmap_image != "null": @@ -374,7 +374,7 @@ def place_square_GPU(self,x,y,size): self.kUtil.PlaceBlock(self.queue, self.a.shape, None, self.ar_ySize, x, y, size, self.a_buf) else: self.kUtil.PlaceBlock(self.queue, self.a.shape, None, self.ar_ySize, x, y, size, self.b_buf) - + def place_square_filter_GPU(self,x,y,size): self.kUtil.PlaceBlock(self.queue, self.a.shape, None, self.ar_ySize, x, y, size, self.render_buf) @@ -401,11 +401,11 @@ def configUI(self, uBlock): #For hiding unused GUI fauxgui = Tk() fauxgui.withdraw() - - + + #--- Preset Configuration ------------- - res_expo = 10 + res_expo = 10 seed_strength = 3 renderEvery = 1 image_magnification = 1 @@ -426,7 +426,7 @@ def configUI(self, uBlock): list = [item for item in last_config.split(',') if item.strip()] rule_playlist_ar = [item for item in playlist.split(',') if item.strip()] - + #replay last config? uinput = raw_input(" > Replay last custom configuration? (Y/N): ") if uinput != "" and uinput != "n" and uinput != "N": @@ -438,10 +438,10 @@ def configUI(self, uBlock): renderEvery = int(list[4]) image_magnification = int(list[5]) bitmap_render = int(list[6]) - + vetoConfig = True - + if(not vetoConfig): uinput = raw_input(" > (Int) [2 ^ " + str(res_expo) + " = " + str(2**res_expo) + "] Resolution: 2 to the power of: ") if uinput != "": @@ -464,7 +464,7 @@ def configUI(self, uBlock): print " > Done!" if(not vetoConfig): - + usePreset = raw_input(" > Use preset configuration? (Y/N): ") if usePreset == "N" or usePreset == "n": #Query user about seeding the initial cell configurations @@ -472,10 +472,10 @@ def configUI(self, uBlock): if SeedType != "" and SeedType != "n" and SeedType != "N": #Seed from image seed_bitmap_image = tfd.askopenfilename(initialdir="./SeedImages", title="Select Seeding-Image File (*.bmp)") - MainCL.loadImg(seed_bitmap_image) + MainCL.loadImg(seed_bitmap_image) else: #Seed Strength - uinput = raw_input(" > (Int) [" + str(seed_strength) + "] Enter random seed strength (1/x): ") + uinput = raw_input(" > (Int) [" + str(seed_strength) + "] Enter random seed strength (1/x): ") if uinput != "": seed_strength = int(uinput) @@ -487,7 +487,7 @@ def configUI(self, uBlock): uinput = raw_input(" > Render as bitmap files? (Y/N): ") if uinput != "" and uinput != "n" and uinput != "N": bitmap_render = 1 - + uinput = raw_input(" > (Int) [" + str(image_magnification) + "] Magnify rendered bitmap pixels by: ") if uinput != "": image_magnification = int(uinput) @@ -497,21 +497,21 @@ def configUI(self, uBlock): #Save presets sOut = str(res_expo) + "," - sOut += ruleFName + "," - sOut += seed_bitmap_image + "," - sOut += str(seed_strength) + "," - sOut += str(renderEvery) + "," - sOut += str(image_magnification) + "," + sOut += ruleFName + "," + sOut += seed_bitmap_image + "," + sOut += str(seed_strength) + "," + sOut += str(renderEvery) + "," + sOut += str(image_magnification) + "," sOut += str(bitmap_render) - + #Write file config_file = open("Last_Config", "w") config_file.write(sOut) config_file.close() - - + + if vetoConfig and seed_bitmap_image != "null": - MainCL.loadImg(seed_bitmap_image) + MainCL.loadImg(seed_bitmap_image) else : #Randomly seed host array MainCL.seed(seed_strength) @@ -522,7 +522,7 @@ def configUI(self, uBlock): #----- - # Begin main program loop + # Begin main program loop #----- print " > Begin OpenGL render" @@ -530,7 +530,7 @@ def configUI(self, uBlock): GLR = RenderGL(MainCL, SCR_DIMS) pygame.init() screen = pygame.display.set_mode(GLR.SCREEN_SIZE, HWSURFACE|OPENGL|DOUBLEBUF) - clock = pygame.time.Clock() + clock = pygame.time.Clock() done = False #Set & render the initial stage @@ -557,7 +557,7 @@ def configUI(self, uBlock): use_filter = False - show_ship = False + show_ship = False shoot_now = False bullet_x = 0 @@ -583,7 +583,7 @@ def configUI(self, uBlock): ship_yv2 = 0 while done==False: - + pygmouse = pygame.mouse.get_pos() #Pygame Event Handler @@ -709,8 +709,8 @@ def configUI(self, uBlock): #flipDrawNow = not flipDrawNow #if not paused and drawNow == flipDrawNow: # MainCL.initBuffers() - - + + #Min, max zoom corrector if myOrtho > 2: @@ -719,7 +719,7 @@ def configUI(self, uBlock): myOrtho = -0.49 #In #----- - # Begin main program loop + # Begin main program loop #----- if not paused: """bullet_x = 0 @@ -747,7 +747,7 @@ def configUI(self, uBlock): bullet_xv = (ship_x - mx) / (bullet_life) bullet_yv = (ship_y - my) / (bullet_life) if(bullet_life > 0): - bullet_life -= 1 + bullet_life -= 1 if(bullet_life % bullet_exp_timer == 0): bullet_size = bullet_explosion else: @@ -778,8 +778,8 @@ def configUI(self, uBlock): #Bottleneck, get the data from CL-GL sharing if not use_filter: MainCL.getData() - - + + ###### Build on actual renders #MainCL.build_render() @@ -790,34 +790,34 @@ def configUI(self, uBlock): GLR.current_grid = np.flipud(np.where(MainCL.a!=0, np.where(MainCL.a Date: Fri, 31 Aug 2018 01:49:40 -0400 Subject: [PATCH 2/9] Removed 'lena' import (no longer in scipy), handle errors when loading from playlist --- ConwayCL-Final/main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ConwayCL-Final/main.py b/ConwayCL-Final/main.py index 1d9196a..f67aada 100644 --- a/ConwayCL-Final/main.py +++ b/ConwayCL-Final/main.py @@ -3,7 +3,6 @@ import scipy as sp from scipy import misc from scipy import ndimage -from scipy.misc import lena import random as r import datetime as date import time @@ -619,7 +618,16 @@ def configUI(self, uBlock): MainCL.saveSeedImage() #48-57 are the numbers if event.key >= 48 and event.key <= 57: - ruleFName = MainCL.setKernel(rule_playlist_ar[event.key-48]) + try: + fn = rule_playlist_ar[event.key-48] + print + print fn + if os.path.exists(fn): + ruleFName = MainCL.setKernel(rule_playlist_ar[event.key-48]) + else: + print " |_ file not found" + except IndexError: + print "no playlist entry" if event.type == KEYUP: print event.key if event.key == K_ESCAPE: From f6ec1ec3fe24d1ba486ddee7dc446abd17929540 Mon Sep 17 00:00:00 2001 From: epitron Date: Fri, 31 Aug 2018 02:06:31 -0400 Subject: [PATCH 3/9] Error handling, switch from comma-separated configs to newline-separated ones, some more comments --- ConwayCL-Final/Last_Config | 8 ++++- ConwayCL-Final/RulePlaylist | 10 ++++++- ConwayCL-Final/main.py | 58 +++++++++++++++++-------------------- 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/ConwayCL-Final/Last_Config b/ConwayCL-Final/Last_Config index 8e26c62..cb3288c 100644 --- a/ConwayCL-Final/Last_Config +++ b/ConwayCL-Final/Last_Config @@ -1 +1,7 @@ -9,/media/pseudo/Media and Storage/PyCl-Convergence/ConwayCL-Final/RuleKernels/Count/Multiple Attractors/MiniAtom/MiniAtom-19.cl,null,2,1,2,0 \ No newline at end of file +10 +RuleKernels/Count/Multiple Attractors/MiniAtom/MiniAtom-19.cl +null +2 +1 +2 +0 diff --git a/ConwayCL-Final/RulePlaylist b/ConwayCL-Final/RulePlaylist index 04599f5..556ebb2 100644 --- a/ConwayCL-Final/RulePlaylist +++ b/ConwayCL-Final/RulePlaylist @@ -1 +1,9 @@ -./RuleKernels/Count/MooreWire-2.cl,./RuleKernels/Count/Multiple Attractors/EW-FMA7-16.cl,./RuleKernels/Count/Multiple Attractors/EW-FMA7-2.cl,./RuleKernels/Count/MeltingHills.cl,./RuleKernels/Count/Multiple Attractors/MiniAtom-2.cl,./RuleKernels/Count/Multiple Attractors/Feeders-14.cl,./RuleKernels/Count/Atoms/SmallAtom/AtomSmall-2.cl,./RuleKernels/Count/Atoms/Atom-ThreeRings-1.cl,./RuleKernels/Count/Honeycomb/Honeycomb-4.cl,./RuleKernels/Count/WG-NoMod.cl, \ No newline at end of file +./RuleKernels/Count/MooreWire-2.cl +./RuleKernels/Count/Multiple Attractors/EW-FMA7-4/EF74-1.cl +./RuleKernels/Count/MeltingHills.cl +./RuleKernels/Count/Multiple Attractors/MiniAtom-2.cl +./RuleKernels/Count/Multiple Attractors/Feeders-14.cl +./RuleKernels/Count/Atoms/SmallAtom/AtomSmall-2.cl +./RuleKernels/Count/Atoms/Atom-ThreeRings-1.cl +./RuleKernels/Count/Honeycomb/Honeycomb-4.cl +./RuleKernels/Count/WG-NoMod.cl diff --git a/ConwayCL-Final/main.py b/ConwayCL-Final/main.py index f67aada..73f27c0 100644 --- a/ConwayCL-Final/main.py +++ b/ConwayCL-Final/main.py @@ -148,11 +148,8 @@ def loadProgram(self, filename): #Load last configuration def loadConfig(self, filename): - #read f = open(filename, 'r') - fstr = "".join(f.readlines()) - return fstr - + return [line.strip() for line in f.readlines()] #initialize host side (CPU) arrays def initHostArrays(self, res_expo): @@ -420,23 +417,23 @@ def configUI(self, uBlock): MainCL.configUI((64,64,64)) last_config = MainCL.loadConfig("Last_Config") - playlist = MainCL.loadConfig("RulePlaylist") - vetoConfig = False + playlist = MainCL.loadConfig("RulePlaylist") + vetoConfig = False - list = [item for item in last_config.split(',') if item.strip()] - rule_playlist_ar = [item for item in playlist.split(',') if item.strip()] + # list = [item for item in last_config.split(',') if item.strip()] + # rule_playlist_ar = [item for item in playlist.split(',') if item.strip()] #replay last config? uinput = raw_input(" > Replay last custom configuration? (Y/N): ") if uinput != "" and uinput != "n" and uinput != "N": #Overrite the defaults - res_expo = int(list[0]) - ruleFName = list[1] - seed_bitmap_image = list[2] - seed_strength = int(list[3]) - renderEvery = int(list[4]) - image_magnification = int(list[5]) - bitmap_render = int(list[6]) + res_expo = int(last_config[0]) + ruleFName = last_config[1] + seed_bitmap_image = last_config[2] + seed_strength = int(last_config[3]) + renderEvery = int(last_config[4]) + image_magnification = int(last_config[5]) + bitmap_render = int(last_config[6]) vetoConfig = True @@ -597,15 +594,15 @@ def configUI(self, uBlock): shoot_now = True else: panNow = not panNow - if event.key == 119: + if event.key == 119: # w ship_yv1 = 2 - if event.key == 115: + if event.key == 97: # a + ship_xv2 = 2 + if event.key == 115: # s ship_yv2 = 2 - if event.key == 100: + if event.key == 100: # d ship_xv1 = 2 - if event.key == 97: - ship_xv2 = 2 - if event.key == 105: + if event.key == 105: # i show_ship = not show_ship print "Ship:", show_ship if event.key == 264: @@ -614,20 +611,19 @@ def configUI(self, uBlock): ship_scroll_weapon = 1 if event.key == 262: ship_scroll_weapon = 2 - if event.key == 117: + if event.key == 117: # u MainCL.saveSeedImage() - #48-57 are the numbers - if event.key >= 48 and event.key <= 57: - try: - fn = rule_playlist_ar[event.key-48] - print + if event.key >= 48 and event.key <= 57: # the number keys (0 through 9) + index = (event.key - 49) % 10 # circularly rotate the indexes left by 1, causing the "1" keypress to be the first index and "0" to be the last index (just like the keyboard!) + if index >= len(playlist): + print "no playlist entry" + else: + fn = playlist[index] print fn if os.path.exists(fn): - ruleFName = MainCL.setKernel(rule_playlist_ar[event.key-48]) + ruleFName = MainCL.setKernel(fn) else: - print " |_ file not found" - except IndexError: - print "no playlist entry" + print " file not found" if event.type == KEYUP: print event.key if event.key == K_ESCAPE: From ddddb377989a32e2fe1e76bd0c2bed44b09c5c3a Mon Sep 17 00:00:00 2001 From: epitron Date: Fri, 31 Aug 2018 02:13:58 -0400 Subject: [PATCH 4/9] Added playlist keys to the README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 894fdce..0f5a22e 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ Run the Python script './PyCl-Convergence-master/ConwayCL-Final/Main.py' in the * 'I' to toggle use of 'Game Mode' (Prerequisite: 'F' for Filter Mode must be on) + * '0' through '9' to load a rule from the 'RulePlaylist' file + There's Three Modes: DRAW, VIEW, and GAME DRAW (Typical Default) @@ -91,7 +93,7 @@ GAME (Temporarily Default Override) * 'F' to toggle use of 'Photographic' filter - + From debea90795a6ddf4445c0db3f9629e8185716c08 Mon Sep 17 00:00:00 2001 From: epitron Date: Fri, 31 Aug 2018 02:14:14 -0400 Subject: [PATCH 5/9] RulesPlaylist updated with paths to existent files --- ConwayCL-Final/RulePlaylist | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ConwayCL-Final/RulePlaylist b/ConwayCL-Final/RulePlaylist index 556ebb2..43457cd 100644 --- a/ConwayCL-Final/RulePlaylist +++ b/ConwayCL-Final/RulePlaylist @@ -1,9 +1,10 @@ -./RuleKernels/Count/MooreWire-2.cl +./RuleKernels/Count/Conway.cl ./RuleKernels/Count/Multiple Attractors/EW-FMA7-4/EF74-1.cl ./RuleKernels/Count/MeltingHills.cl -./RuleKernels/Count/Multiple Attractors/MiniAtom-2.cl -./RuleKernels/Count/Multiple Attractors/Feeders-14.cl -./RuleKernels/Count/Atoms/SmallAtom/AtomSmall-2.cl -./RuleKernels/Count/Atoms/Atom-ThreeRings-1.cl +./RuleKernels/Count/Multiple Attractors/Feeders/Feeders-14.cl ./RuleKernels/Count/Honeycomb/Honeycomb-4.cl +./RuleKernels/Count/Atoms/Atom-TwoRings-1.cl +./RuleKernels/Count/Atoms/Atom-ThreeRings-1.cl ./RuleKernels/Count/WG-NoMod.cl +./RuleKernels/Count/MooreWire-2.cl +./RuleKernels/BiSum/Churning.cl From 40581d1b3fbce63d31a6ebc99d5051ea922e9cf3 Mon Sep 17 00:00:00 2001 From: epitron Date: Fri, 31 Aug 2018 02:20:01 -0400 Subject: [PATCH 6/9] Fixed up pathnames in the readme --- README.md | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0f5a22e..dd483e0 100644 --- a/README.md +++ b/README.md @@ -45,9 +45,9 @@ If your machine can run GPU-accelerated simulations with https://code.google.com # Once that is set up... -Open the terminal in './PyCl-Convergence-master/ConwayCL-Final' +Open the terminal in './PyCl-Convergence/ConwayCL-Final' -Run the Python script './PyCl-Convergence-master/ConwayCL-Final/Main.py' in the terminal with: 'python main.py' +Run the Python script './PyCl-Convergence/ConwayCL-Final/main.py' in the terminal with: 'python main.py' * Spam the ENTER key to use default settings @@ -92,13 +92,3 @@ GAME (Temporarily Default Override) * Spacebar or Left Click to shoot at the Mouse Position * 'F' to toggle use of 'Photographic' filter - - - - - - - - - - From c76b4293ece92c760f85fa74a639a355dcfb44b7 Mon Sep 17 00:00:00 2001 From: epitron Date: Fri, 31 Aug 2018 02:28:14 -0400 Subject: [PATCH 7/9] 'Last_Config' changed to 'SavedConfig', and comments/newlines are now allowed --- ConwayCL-Final/Last_Config | 7 ------- ConwayCL-Final/SavedConfig | 14 ++++++++++++++ ConwayCL-Final/main.py | 31 ++++++++++++++----------------- 3 files changed, 28 insertions(+), 24 deletions(-) delete mode 100644 ConwayCL-Final/Last_Config create mode 100644 ConwayCL-Final/SavedConfig diff --git a/ConwayCL-Final/Last_Config b/ConwayCL-Final/Last_Config deleted file mode 100644 index cb3288c..0000000 --- a/ConwayCL-Final/Last_Config +++ /dev/null @@ -1,7 +0,0 @@ -10 -RuleKernels/Count/Multiple Attractors/MiniAtom/MiniAtom-19.cl -null -2 -1 -2 -0 diff --git a/ConwayCL-Final/SavedConfig b/ConwayCL-Final/SavedConfig new file mode 100644 index 0000000..59e7e77 --- /dev/null +++ b/ConwayCL-Final/SavedConfig @@ -0,0 +1,14 @@ +# resolution exponent (2^exp) +10 +# initial rule +RuleKernels/Count/Multiple Attractors/MiniAtom/MiniAtom-19.cl +# seed bitmap +null +# seed strength +2 +# render every 'n' steps +1 +# magnification +2 +# bitmap render +0 diff --git a/ConwayCL-Final/main.py b/ConwayCL-Final/main.py index 73f27c0..ce2e3ac 100644 --- a/ConwayCL-Final/main.py +++ b/ConwayCL-Final/main.py @@ -149,7 +149,7 @@ def loadProgram(self, filename): #Load last configuration def loadConfig(self, filename): f = open(filename, 'r') - return [line.strip() for line in f.readlines()] + return [ line.strip() for line in f.readlines() if line.strip() and not line[0] == "#" ] #initialize host side (CPU) arrays def initHostArrays(self, res_expo): @@ -416,24 +416,21 @@ def configUI(self, uBlock): MainCL.configUI((64,64,64)) - last_config = MainCL.loadConfig("Last_Config") - playlist = MainCL.loadConfig("RulePlaylist") - vetoConfig = False - - # list = [item for item in last_config.split(',') if item.strip()] - # rule_playlist_ar = [item for item in playlist.split(',') if item.strip()] + config = MainCL.loadConfig("SavedConfig") + playlist = MainCL.loadConfig("RulePlaylist") + vetoConfig = False #replay last config? - uinput = raw_input(" > Replay last custom configuration? (Y/N): ") + uinput = raw_input(" > Use saved configuration? (Y/N): ") if uinput != "" and uinput != "n" and uinput != "N": - #Overrite the defaults - res_expo = int(last_config[0]) - ruleFName = last_config[1] - seed_bitmap_image = last_config[2] - seed_strength = int(last_config[3]) - renderEvery = int(last_config[4]) - image_magnification = int(last_config[5]) - bitmap_render = int(last_config[6]) + # Override the defaults + res_expo = int(config[0]) + ruleFName = config[1] + seed_bitmap_image = config[2] + seed_strength = int(config[3]) + renderEvery = int(config[4]) + image_magnification = int(config[5]) + bitmap_render = int(config[6]) vetoConfig = True @@ -501,7 +498,7 @@ def configUI(self, uBlock): sOut += str(bitmap_render) #Write file - config_file = open("Last_Config", "w") + config_file = open("SavedConfig", "w") config_file.write(sOut) config_file.close() From 06a8cedb7a3fce1d6891ba86be195a0f135a81fb Mon Sep 17 00:00:00 2001 From: epitron Date: Fri, 31 Aug 2018 02:39:47 -0400 Subject: [PATCH 8/9] If there's only one platform and one device, use it; otherwise, call "cl.create_some_context" --- ConwayCL-Final/main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ConwayCL-Final/main.py b/ConwayCL-Final/main.py index ce2e3ac..c71dd55 100644 --- a/ConwayCL-Final/main.py +++ b/ConwayCL-Final/main.py @@ -132,10 +132,19 @@ def doRender(self, pmouse, last_pm): class CL: def __init__(self): - self.ctx = cl.create_some_context() + self.ctx = self.create_context() self.queue = cl.CommandQueue(self.ctx) self.tickState = False + # If there's only one platform and one device, use it; otherwise, call "create_some_context" + def create_context(self): + platforms = cl.get_platforms() + if len(platforms) == 1: + devices = platforms[0].get_devices() + if len(devices) == 1: + return cl.Context(devices) + return cl.create_some_context() + #Load kernel file and load as internal program def loadProgram(self, filename): #read in the OpenCL source file as a string From 7f32b7f4f8d9ec50d70317fcadc6c799177fdc40 Mon Sep 17 00:00:00 2001 From: epitron Date: Fri, 31 Aug 2018 19:37:16 -0400 Subject: [PATCH 9/9] "SavedConfig" is now written in new format --- ConwayCL-Final/main.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ConwayCL-Final/main.py b/ConwayCL-Final/main.py index c71dd55..63e2b7d 100644 --- a/ConwayCL-Final/main.py +++ b/ConwayCL-Final/main.py @@ -498,17 +498,19 @@ def configUI(self, uBlock): if uinput != "" and uinput != "n" and uinput != "N": #Save presets - sOut = str(res_expo) + "," - sOut += ruleFName + "," - sOut += seed_bitmap_image + "," - sOut += str(seed_strength) + "," - sOut += str(renderEvery) + "," - sOut += str(image_magnification) + "," - sOut += str(bitmap_render) + sOut = [ + str(res_expo), + ruleFName, + seed_bitmap_image, + str(seed_strength), + str(renderEvery), + str(image_magnification), + str(bitmap_render) + ] #Write file config_file = open("SavedConfig", "w") - config_file.write(sOut) + config_file.write("\n".join(sOut) + "\n") config_file.close()