コード例 #1
0
import gifmaze as gm
from gifmaze.algorithms import random_dfs

surface = gm.GIFSurface(600, 400, bg_color=0)
surface.set_palette([0, 0, 0, 255, 255, 255])
maze = gm.Maze(149, 99, mask=None).scale(4).translate((2, 2))

anim = gm.Animation(surface)
anim.pause(100)
anim.run(random_dfs,
         maze,
         speed=10,
         delay=5,
         trans_index=None,
         cmap={
             0: 0,
             1: 1
         },
         mcl=2,
         start=(0, 0))
anim.pause(300)
surface.save('d:\\random_dfs.gif')
surface.close()
コード例 #2
0
# -*- coding: utf-8 -*-
"""
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Make GIF Animation of Prim's Algorithm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
import gifmaze as gm
from algorithms import prim

width, height = 600, 400
# define the surface to drawn on
surface = gm.GIFSurface(width, height, bg_color=0)
surface.set_palette([0, 0, 0, 255, 255, 255])

# define the maze
maze = gm.Maze(147, 97, mask=None).scale(4).translate((6, 6))

# define the animation environment
anim = gm.Animation(surface)
anim.pause(200)
# run the algorithm
anim.run(prim, maze, start=(0, 0), speed=30, delay=5)
anim.pause(500)

# save the result
surface.save('prim.gif')
surface.close()
コード例 #3
0
            yield render(maze)

    maze.mark_cell(pixels[-1], color_pixel(len(pixels) - 1))
    if maze.num_changes > 0:
        yield render(maze)


order = 6  # order of the curve
curve_size = (1 << order)  # width & height of the curve
maze_size = 2 * curve_size - 1  # pad one space between two adjacent vertices
cell_size = 4
margin = 6
image_size = cell_size * maze_size + 2 * margin

pixels = tuple(pixels_hilbert(curve_size))  # (x, y) coordinate of the pixels
colors = [0, 0, 0]  # global color table
for i in range(255):
    rgb = hls_to_rgb((i / 256.0) % 1, 0.5, 1.0)
    colors += [int(round(255 * x)) for x in rgb]

surface = gm.GIFSurface(image_size, image_size, bg_color=0)
surface.set_palette(colors)
maze = gm.Maze(maze_size, maze_size, mask=None).scale(cell_size).translate((margin, margin))

anim = gm.Animation(surface)
anim.pause(100)
anim.run(hilbert, maze, speed=20, delay=5, pixels=pixels)
anim.pause(500)
surface.save("hilbert.gif")
surface.close()
コード例 #4
0
    200,  # tree color
    255,
    0,
    255
]  # path color

for i in range(256):
    rgb = hls_to_rgb((i / 360.0) % 1, 0.5, 1.0)
    palette += [int(round(255 * x)) for x in rgb]

surface.set_palette(palette)

# create a maze instance and set its position in the image
size = (surface.width, surface.height)
mask = generate_text_mask(size, 'UST', './resources/ubuntu.ttf', 350)
maze = gm.Maze(111, 67, mask=mask).scale(4).translate((75, 56))

# create an animation environment
anim = gm.Animation(surface)

# here `trans_index=1` is for compatible with eye of gnome in linux,
# you may always use the default 0 for chrome and firefox.
anim.pause(100, trans_index=1)

# paint the background region that contains the maze
left, top, width, height = 70, 50, 450, 280
anim.paint(left, top, width, height, 0)
anim.pause(100)

# Run the maze generation algorithm.
# Only three colors are used in the Wilson's algorithm hence
コード例 #5
0
import gifmaze as gm
from algorithms import kruskal, dfs, random_dfs
from algorithms import prim
from gentext import generate_text_mask

width, height = 800, 320
# define the surface to drawn on
surface = gm.GIFSurface(width, height, bg_color=0)
surface.set_palette([0, 0, 0, 235, 235, 235, 150, 200, 100, 161, 35,
                     6])  # 78, 205, 196,   161,35,6

# define the maze
mask = generate_text_mask(
    (width, height), "Je t'aime", '‪C:\Windows\Fonts\GILC____.TTF', 240
)  # C:/Windows/Fonts/STZHONGS.TTF ./resources/ubuntu.ttf 147, 97  fontsize 480
maze = gm.Maze(int(width / 4 - 3), int(height / 4 - 3),
               mask=mask).scale(4).translate((6, 6))

# define the animation environment
anim = gm.Animation(surface)
anim.pause(200)
# run the algorithm
anim.run(prim, maze, speed=50, delay=2)
anim.pause(300)

start = (0, 0)
end = (maze.width - 1, maze.height - 1)

# run the maze solving algorithm.
# the tree and walls are unchanged throughout this process
# hence we color them using the transparent channel 0.
コード例 #6
0
ファイル: main.py プロジェクト: xpingli/pywonderland
    0,
    255
]  # path color

for i in range(256):
    rgb = hls_to_rgb((i / 360.0) % 1, 0.5, 1.0)
    palette += [int(round(255 * x)) for x in rgb]

surface.set_palette(palette)

# --------------------------------------------------------
# create a maze instance and set its position in the image
# --------------------------------------------------------
size = (surface.width, surface.height)
mask = generate_text_mask(size, 'UST', 'ubuntu.ttf', 350)
maze = gm.Maze(117, 73, mask=mask).scale(4).translate((69, 49))

# ------------------------------------------------------------------
# create an animation instance to write the animation to the surface
# ------------------------------------------------------------------
anim = gm.Animation(surface)

# here `trans_index=1` is for compatible with eye of chrome in linux.
# you may always use the default 0 for chrome and firefox.
anim.pause(100, trans_index=1)

# paint the background region that contains the maze.
left, top, width, height = 66, 47, 475, 297
anim.paint(left, top, width, height, 0)
anim.pause(100)
    200,  # tree color
    244,
    25,
    220
]  # path color

for i in range(256):
    rgb = hls_to_rgb((i / 360.0) % 1, 0.5, 1.0)
    palette += [int(round(255 * x)) for x in rgb]

surface.set_palette(palette)

# create a maze instance and set its position in the image
size = (surface.width, surface.height)
mask = generate_text_mask(size, 'UST', './resources/ubuntu.ttf', 300)
maze = gm.Maze(119, 75, mask=mask).scale(3).translate((50, 35))

# create an animation environment
anim = gm.Animation(surface)

# here `trans_index=1` is for compatible with eye of gnome in linux,
# you may always use the default 0 for chrome and firefox.
anim.pause(100, trans_index=1)

# paint the background region that contains the maze
left, top, width, height = 48, 32, 361, 231
anim.paint(left, top, width, height, 0)
anim.pause(100)

# Run the maze generation algorithm.
# Only three colors are used in the Wilson's algorithm hence