zenith-parsec (zen) <zenith parsec gmail com> |
Thursday, February 2 2006 20:34.01 CST |
Here is some code I wrote tht may be interesting to some of you. I was trying to work out how random-dot stereograms worked and decided to write some code to test some methods.
It's ugly code. ;] But it kinda works, and i think it shows how to do them. Oh yeah....it's all text.
to compile it, save it as stereo.c and then
$ cc -o stereo stereo.c -lm
$ ./stereo > stereo.txt
You may have to mess around a little to get the sizes you want.
#define HEIGHT 50
#define WIDTH 55
unsigned char screen[HEIGHT][WIDTH];
unsigned char map[HEIGHT][WIDTH];
unsigned char fill[11];
char f[]="!@#$%^&*()_+1234567890";
mkfill(char *s)
{
int i;
for(i=0;i<sizeof(fill);s[i]?i++:i)
{
s[i]=rand()%90 + ' ';
}
}
int fn(int x,int y)
{
double a,b,c;
int ret;
a=(WIDTH/2)-x;
b=(HEIGHT/2)-y;
c=(sqrt(a*a/4 + b*b)/4);
ret=c>4?0:8-c;
if(a>0)ret=-ret;
return (sizeof(fill)+ret)%sizeof(fill);
}
main(int argc,char *argv[])
{
int h,w;
srand(time(0)^getpid());
for(h=0;h<HEIGHT;h++)
{
for(w=0;w<WIDTH;w++)
{
map[h][w]=fn(w,h);
}
}
if(argc<2)
for(h=0;h<HEIGHT;h++)
{
int o;
mkfill(fill);
for(w=0;w<WIDTH;w++)
{
o = map[h][w];
screen[h][w]=fill[(o+w)%sizeof(fill)];
}
printf("\t");
printf("%s%s",fill,fill);
printf("%s%s",fill,fill);
for(w=0;w<WIDTH;w++)
{
printf("%c",screen[h][w]);
}
printf("%s%s",fill,fill);
printf("%s%s",fill,fill);
printf("\n");
}
else
{
for(h=0;h<HEIGHT;h++)
{
printf("\t");
for(w=0;w<WIDTH;w++)
{
printf("%c",map[h][w]+'0');
}
printf("\n");
}
}
}
Coming soon (maybe)... animated ascii random dot stereograms.
(not sure yet if the maybe is the 'soon' or the 'coming' part.
|