Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* simple noise map generator
- * Usage: noisemap <size> <saturation>
- * size: 1..MAXSIZE (default = 5)
- * saturation: 1..100 (default = 50%)
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define DRAWCHAR "#. "
- #define MAXSIZE 50
- #define PERCENT_SATURATION 50
- #define min(a,b) \
- ( (a) < (b) ? (a) : (b) )
- #define max(a,b) \
- ( (a) > (b) ? (a) : (b) )
- #define minmax(a,b,c) \
- ( max((a), min((b), (c))) )
- #define setint(lvalue, arg) \
- ( (lvalue = atoi(argv[arg])), 1 )
- static int saturation = PERCENT_SATURATION;
- void
- draw_row(int size, int rownum)
- {
- printf("%2i ", rownum);
- while(size--)
- printf("%c%c", DRAWCHAR[rand() % 100 > saturation], DRAWCHAR[2]);
- putchar('\n');
- }
- void
- draw_header(int size)
- {
- fputs(" ", stdout);
- for(int i = 1; i <= size; i++)
- if(i % 10 == 0)
- printf("%i ", i / 10);
- else
- fputs(" ", stdout);
- fputs("\n ", stdout);
- for(int i = 1; i <= size; i++)
- printf("%i ", i % 10);
- putchar('\n');
- }
- int
- main(int argc, char **argv)
- {
- int size = 5;
- if(argc > 1 && setint(size, 1))
- size = minmax(1, MAXSIZE, size);
- if(argc > 2 && setint(saturation, 2))
- saturation = minmax(1, 100, saturation);
- srand(time(NULL));
- draw_header(size);
- for(int i = 1; i <= size; i++)
- draw_row(size, i);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement