Created
February 4, 2015 02:03
-
-
Save Wunkolo/cf0ac817b6659f413e6b to your computer and use it in GitHub Desktop.
Spiral generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Spirals | |
//┌─────────┐ | |
//│┌───────┐│ | |
//││┌─────┐││ | |
//│││┌───┐│││ | |
//││││┌─┐││││ | |
//│││││└┘││││ | |
//││││└──┘│││ | |
//│││└────┘││ | |
//││└──────┘│ | |
//│└────────┘ | |
//└────────── | |
#include <stdio.h> | |
#include <stdint.h> | |
#define SIZE 24 | |
int main() | |
{ | |
const int32_t dx[] = { 0, -1, 0, 1 }, dy[] = { -1, 0, 1, 0 }; | |
int32_t x = SIZE - 1, y = SIZE; | |
uint32_t **Grid = new uint32_t*[SIZE]; | |
for( size_t i = 0; i < SIZE; i++ ) | |
{ | |
Grid[i] = new uint32_t[SIZE]; | |
} | |
for( size_t i = 0, dir = 0; i < (SIZE << 1) - 1; ++i, dir = i & 3 ) | |
{ | |
for( size_t j = 0, js = ((SIZE << 1) - i) / 2; j < js; ++j ) | |
{ | |
Grid[x += dx[dir]][y += dy[dir]] = j + 1 == js ? "\xC0\xDA\xBF\xd9"[dir] : "\xC4\xB3"[dir & 1]; | |
} | |
} | |
for( size_t i = 0; i < SIZE*SIZE; i++ ) | |
{ | |
putchar(Grid[i / SIZE][i % SIZE]); | |
(i + 1) % SIZE == 0 ? putchar('\n') : 0; | |
} | |
for( size_t i = 0; i < SIZE; i++ ) | |
{ | |
delete[] Grid[i]; | |
} | |
delete[] Grid; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment