def to_maze(level, title): maze = Vmaze_NHT(level['canvas'], start=level['start'], goal=level['goal'], nodes_pos=level['nodes_pos']) maze.title = title return maze
def to_maze(level, title): maze = Vmaze_NHT(level['canvas'], start= level['start'], goal= level['goal'], nodes_pos = level['nodes_pos']) maze.title = title return maze
# This script shows how to make a canvas with the editor, # save it, and load it later :: from vmfactory import Vmaze from vmfactory.canvas import canvas_editor canvas = canvas_editor() # will open an interactive session. # For when the session has ended: maze = Vmaze(canvas) maze.to_file('mycanvas.can') # Later: from vmfactory import Vmaze_NHT maze_nht = Vmaze_NHT.from_file('mycanvas.can') maze_nht.draw_quick()
# 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')
# 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')
def animate(nframe): G = Vmaze_NHT.from_file(input_name_format % nframe) fig = G.make_report(axes=axes) fig.savefig("_tmp_%02d.jpeg" % nframe)
# The next script shows how to make an animation of a # maze being optimized (requires a recent Matplotlib # and ImageMagick): :: import os import networkx as nx 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)
def animate(nframe): G = Vmaze_NHT.from_file(input_name_format % nframe) fig = G.make_report(axes=axes) fig.savefig("_tmp_%02d.jpeg"%nframe)
# The next script shows how to make an animation of a # maze being optimized (requires a recent Matplotlib # and ImageMagick): :: import os import networkx as nx 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):