Open main menu

CDOT Wiki β

Changes

GPU610 Team Tsubame

934 bytes added, 17:05, 5 April 2017
Maze
The Maze program (by corzani@github) generates a maze image (of type PNG).
This funtion The following function creates the canvas of the Maze and initialize it by filling all the hexadecimal within each pixel
After the canvas is filled, the function calls the createImage function.
Finally, the function write the result from the createImage function in a png file using the "lpng" extension
The function returns void.
void MazePng::toPng(unsigned int scale){
...
color_type = PNG_COLOR_TYPE_RGB;
createImage(row_pointers, 0);
...
}
The following function carves the path of the Maze by changing the colour of pixels to white.
void MazePng::createImage(png_bytep *row_pointers, unsigned int scale) {
...
//This loops sets the pixels of the row_pointers using the cells pattern
for (unsigned int y = 0; y < height; ++y) {
setPixel(row_pointers, 0, (y * 2) + 1, WALL);
for (unsigned int x = 0; x < width; ++x) {
switch ((cells[(y * width) + x] & 0xC0) >> 6) {
case 2:
temp[0] = PATH;
setPixel(row_pointers, 2 + (x * 2), (y * 2) + 1, temp[0]);
break;
case 1:
temp[1] = PATH;
setPixel(row_pointers, 1 + (x * 2), (y * 2) + 2, temp[1]);
break;
case 0:
setPixel(row_pointers, 2 + (x * 2), (y * 2) + 1, temp[0]);
setPixel(row_pointers, 1 + (x * 2), (y * 2) + 2, temp[1]);
break;
}
setPixel(row_pointers, 1 + (x * 2), (y * 2) + 1, PATH);
}
}
}
'''Testing Environment:'''
* Operating system: Windows 8.1 Enterprise 64-bit (6.3, Build 9600) (9600.winblue_ltsb.160812-0914)
46
edits