# This is a simple script to automatically design a maze: from vmfactory import Vmaze_NHT from vmfactory.canvas import squares_grid canvas = squares_grid(4,4) # nodes will be numbered 0..15 # NHT means no half-turns (can't pass a light twice in a row) maze = Vmaze_NHT(canvas, start = 0, goal = 15) maze.colorize( maze.random_colors() ) maze.anneal(400,20) # optimize the maze # maze.make_report().savefig('myreport.png') maze.to_file('my_nice_maze.vm')
from matplotlib import animation import matplotlib.pyplot as plt from vmfactory import Vmaze_NHT from vmfactory.canvas import stacked_cubes input_name_format = "_tmp_evograph_%03d.vm" G = Vmaze_NHT(**stacked_cubes()) G.start, G.goal = 0, max(G.nodes()) G.colorize(G.random_colors()) counter = 0 score = G.score for i in range(100): G.improve(100, max(.1, 0.3 * (1 - 1.0 * i / 400.0))) if G.score != score: score = G.score G.to_file(input_name_format % counter) counter += 1 fig, axes = plt.subplots(1, 3, figsize=(10, 3)) def animate(nframe): G = Vmaze_NHT.from_file(input_name_format % nframe) fig = G.make_report(axes=axes) fig.savefig("_tmp_%02d.jpeg" % nframe) anim = animation.FuncAnimation(fig, animate, frames=counter) anim.save("test.gif", fps=.5, writer="imagemagick")
# This is a simple script to automatically design a maze: from vmfactory import Vmaze_NHT from vmfactory.canvas import squares_grid canvas = squares_grid(4, 4) # nodes will be numbered 0..15 # NHT means no half-turns (can't pass a light twice in a row) maze = Vmaze_NHT(canvas, start=0, goal=15) maze.colorize(maze.random_colors()) maze.anneal(400, 20) # optimize the maze # maze.make_report().savefig('myreport.png') maze.to_file('my_nice_maze.vm')
from matplotlib import animation import matplotlib.pyplot as plt from vmfactory import Vmaze_NHT from vmfactory.canvas import stacked_cubes input_name_format = "_tmp_evograph_%03d.vm" G = Vmaze_NHT(** stacked_cubes()) G.start, G.goal = 0, max(G.nodes()) G.colorize( G.random_colors() ) counter = 0 score = G.score for i in range(100): G.improve(100,max(.1,0.3*(1-1.0*i/400.0))) if G.score != score: score = G.score G.to_file(input_name_format%counter) counter += 1 fig, axes = plt.subplots(1,3, figsize=(10,3)) def animate(nframe): G = Vmaze_NHT.from_file(input_name_format % nframe) fig = G.make_report(axes=axes) fig.savefig("_tmp_%02d.jpeg"%nframe) anim = animation.FuncAnimation(fig, animate, frames=counter) anim.save("test.gif", fps=.5, writer="imagemagick")