int size = 1000; bool maze[size,size]; for x from 0 to size for y from 0 to size { int value = random(256); // * 255; value = value / 16 + value; value = value / 8 + value; maze[x,y] = value % 2 == 0; } if (true) // create tempran.png images { image tempran; tempran.open("tempran.png"); tempran.new(size,size); for x from 0 to size for y from 0 to size { int value = maze[x,y] ? 0 : 255; color col; col.r = value; col.g = value; col.b = value; tempran.setColor(x,y,col); } } image diamaze; diamaze.open("diamaze.png"); int xsize = 4*size; int ysize = 2*size; diamaze.new(xsize,ysize); bool visited[size,size]; for i from 0 to size for j from 0 to size if ((i+j)%2 == 1 && !visited[i,j]) { //printf("start %d,%d d\n",i, j); int len = 0; for pass from 0 to 2 { int i1 = i; int j1 = j; int i2 = 0; int j2 = 0; int dir = 2; //0:up, 1:right, 2:down, 3:left int x = 4*xsize - 2*i1 - 2*j1; int y = 2*i1 - 2*j1; while (y < 0) { y += ysize; x += ysize; } while (y >= ysize) { y -= ysize; x += ysize; } x = x % xsize; color col; if (pass == 0 || i2 != 0 || j2 != 0) { //col.g = 255; col.b = 155+random(10)*10; } else { int value = 0; int v = 2; for b from 0 to 16 { if (len <= v && value == 0) value = 255 - b * (255 / 16); v = v * 2; } if (value > 0) { col.r = value; col.g = 255-value; } else { col.g = 155+random(10)*10; col.b = 155+random(10)*10; } } bool go = true; while (go) //int k = 0; k < n*m; k++) { diamaze.setColor(x,y,col); if (dir == 2) { visited[i1,j1] = true; i1++; if (i1 == size) { i1 = 0; i2++; } if (maze[i1,j1]) { if (++y >= ysize) { y -= ysize; x = (x + ysize) % xsize; } diamaze.setColor(x,y,col); if (++y >= ysize) { y -= ysize; x = (x + ysize) % xsize; } dir = 3; } else { x = (x - 1 + xsize)%xsize; diamaze.setColor(x,y,col); x = (x - 1 + xsize)%xsize; dir = 1; } } else // dir == 0 { i1--; if (i1 < 0) { i1 = size-1; i2--; } if (maze[i1,j1]) { if (--y < 0) { y += ysize; x = (x + ysize) % xsize; } diamaze.setColor(x,y,col); if (--y < 0) { y += ysize; x = (x + ysize) % xsize; } dir = 1; } else { x = (x + 1)%xsize; diamaze.setColor(x,y,col); x = (x + 1)%xsize; dir = 3; } } diamaze.setColor(x,y,col); if (dir == 1) { j1++; if (j1 == size) { j1 = 0; j2++; } if (maze[i1,j1]) { if (--y < 0) { y += ysize; x = (x + ysize) % xsize; } diamaze.setColor(x,y,col); if (--y < 0) { y += ysize; x = (x + ysize) % xsize; } dir = 0; } else { x = (x - 1 + xsize)%xsize; diamaze.setColor(x,y,col); x = (x - 1 + xsize)%xsize; dir = 2; } } else // dir == 3 { j1--; if (j1 < 0) { j1 = size-1; j2--; } if (maze[i1,j1]) { if (++y >= ysize) { y -= ysize; x = (x + ysize) % xsize; } diamaze.setColor(x,y,col); if (++y >= ysize) { y -= ysize; x = (x + ysize) % xsize; } dir = 2; } else { x = (x + 1)%xsize; diamaze.setColor(x,y,col); x = (x + 1)%xsize; dir = 0; } } len++; if (i1 == i && j1 == j && dir == 2) go = false; } } }