hundred_dolla_tea
hundred_dolla_tea

Reputation: 561

Simple frameworks for drawing a generated maze in C++

I generate a maze using a randomized version of Kruskal's. The program logic for generating the maze is not an issue for me.I am having trouble figuring out how I would actually go about physically displaying the maze drawing.

To my understanding, the initial maze would start as a H by W grid, where each cell has all of its "borders"/walls in place. My only experience with C++ drawing is simply printing chars in the terminal, to represent different figures. However, it doesn't seem suited for more complex drawings like a cell of a certain width and height surrounded by 4 much thinner black lines. I suppose I could surround each cell character with 8 wall characters, but that seems quite cumbersome and not very elegant (walls would look bulky/ not thin).

I have seen some awesome screenshots on SO that people have taken of their generated maze, where they were able to draw the thin walls surrounded the cells with ease. I have never used a graphing/drawing library in C++ and after a few hours of search I am still quite lost.

For those algorithmic fanatics out there, what are the simplest frameworks to draw simple grids/mazes in C++?

Upvotes: 0

Views: 858

Answers (1)

Flash_Steel
Flash_Steel

Reputation: 628

Without a specific library for displaying images you won't be able to actually show your image. OpenCV has a fantastic range of tools for generating, editing and displaying images. There are a huge amount of tutorials from step by step installation for your system to doing anything you may wish to do with OpenCV.

A simple enough method regardless of the libraries you use might be to

  1. Create an image in memory with n pixels per unit in your grid. So your image would be (n * H) x (n * W) pixels large
  2. Set all the pixels to be a single colour
  3. Loop over every unit in your grid which is a path and draw a square of a second colour on your image from (n*W, n*H) to (n*[W+1], n*[H+1])
  4. Draw the image to your output object

What you will end up with is a 2-tone image with walls the background colour and the path the foreground colour.

Unfortunately I cannot be any more specific without code examples or you picking the libraries you would like to use. OpenCV is widelyu used and so widely supported, so I recommend that.

Upvotes: 2

Related Questions