mpe@shamash.cdc.com (2375) (06/06/90)
Some time ago, in a galaxy far far away, I put a plee for anyone who has a copy of the hologram article which was featured in Computer Cellar Inc to forward it to me or the NET. Two kind souls responded and offered to help. As promised, here is a copy of everything that I received reguarding the topic of hologram construction using a PC and a VGA monitor. =============================================================== #include <stdio.h> #include <math.h> /*********************************************************************** * * * This program is somewhat based on the basic program from the * * computer generated holography article in the April/May 90 issue * * of Circuit Cellar INK. I tried to enhance it a bit. It's by * * no means optimized. Using a DECStation 3100 and the 640x480 * * size the program took 9 minutes to run. With a 4704x4704 size * * the program takes about 10.5 hours to run. * * * * The output is a raw bitmap file. I should probably get it to * * output a pbm file, but the raw bitmap works for me. * * * * -- john <jds@m2c.org> * ***********************************************************************/ /* * This program was written for Berkeley Unix. It should run on just * about anything. Be sure to compile with the optimizer on and to * link in the math library. * * cc -O -o ink ink.c -lm * * Usage: ink > outfile -- or -- ink outfile */ /* * The following values are for a PC screen size. Scale to * an appropriate size for your device. */ /* screen scaling factor */ #define L 0.0255145 /* Depth of image */ #define PZ 129528.0 /* height of fringe pattern to generate */ #define HEIGHT 480 /* width of fringe pattern to generate */ #define WIDTH 640 /* Amplitude of cos() function */ #define A 252.0 /* DTHETA determines # of dots to do -- ndots = PI/DTHETA */ #define DTHETA 0.075 main(argc,argv) int argc; char *argv[]; { int x,y,bit_pat,bit_cnt; double r,px,py,d,s,theta,phase; double pz_sq, half_height, half_width; double d_mult; FILE *fopen(),*fp; pz_sq = PZ*PZ; half_height = HEIGHT / 2.0; half_width = WIDTH / 2.0; d_mult = (2.0 * M_PI) / L; if(argc>1) { if((fp=fopen(argv[1],"w"))==NULL) { fprintf(stderr,"%s: couldn't open %s for writing\n",argv[0],argv[1]); exit(-1); } } else fp = stdout; for(x=0;x<WIDTH;x++) { bit_pat = 0; bit_cnt = 0; for(y=0;y<HEIGHT;y++) { s = 0.0; for(theta=0.0;theta<=M_PI;theta+=DTHETA) { r = A * cos(3.0 * theta); px = half_width + r * cos(theta) - (double) x; py = half_height + r * sin(theta) - (double) y; d = sqrt( px*px + py*py + pz_sq); /*phase = (2.0 * M_PI / L) * d;*/ phase = d_mult * d; s = s + sin(phase); } bit_pat <<= 1; if(s >= 0.0) bit_pat += 1; bit_cnt++; if(bit_cnt==8) { bit_cnt = 0; putc((char)bit_pat,fp); bit_pat = 0; } } } } =============================================================== 5 DEFDBL A-Z 10 SCREEN 12: PI = 3.141592653589793#: s = 0: CLS 20 l = 0.0255145: pz = 129528: h = 320: k = 240: a = 252 30 FOR x = 0 TO 639 40 FOR y = 0 TO 479 50 FOR t = 0 TO 1 * pi STEP 0.075 55 r = a * COS(3 * t) 60 px = h + r * COS(t) : py = k + r * SIN(t) 70 d = (((px - x) ^ 2) + ((py - y) ^ 2) + ((pz) ^ 2)) ^ 0.5 80 phase = (2 * pi / l) * d 90 s = s + SIN(phase) 100 NEXT t 110 IF s >= 0 THEN COLOR 7: PSET (x, y): GOTO 130 120 COLOR 0: PSET (x, y) 130 s = 0 135 NEXT y 140 NEXT x 150 DO: LOOP WHILE INKEY$ = "" 200 END ===============================================================