def foo(rule_nr,outdir,a,rule_study_number,pixel_factor=2): # output dir must exist path = os.path.join(outdir,"%s"%rule_nr) if not os.path.exists(path): os.makedirs(path) ca = Ca() for i in xrange(rule_study_number): # generate random input sequence line = [] while len(line) < a: line.append(random.randint(0, 1)) im = ca.getImage(line,rule_nr) strline = "" for j in line: strline += str(j) #im.save(os.path.join(path,"thumb_%s.png" % (strline)), "PNG") # enlarge im = im.resize((a*pixel_factor,a*pixel_factor), Image.NEAREST) im.save(os.path.join(path,"random_%s.png" % strline), "PNG")
def main(): if not os.path.exists("../output/images"): # output path must exist os.makedirs("../output/images") if make_anyway or not os.path.isfile("../output/images/rule%s.png" % rule_numbers[len(rule_numbers)-1]): # last file exists -> don't generate for rn in rule_numbers: # init first line line = list(numpy.zeros(a, dtype=numpy.int)) line[a/2] = 1 im = Ca().getImage(line,rn) im.save("../output/images/t_rule%s.png" % rn, "PNG") im = im.resize((a*pixel_factor,a*pixel_factor), Image.NEAREST) im.save("../output/images/rule%s.png" % rn, "PNG") print "Rule %s" % rn rulestudy.foo(rn,"../output/rules/",a,rule_study_number) print "Study complete" out_html(rule_numbers) rulestudy.html_out("../output/rules/")