#include <stdio.h>
#include <math.h>

#define	PAI	3.14159265358979323844

main(argc,argv)
int	argc;
char	**argv;
{
	int	i,j,n;
	double	t0,t1,t2,t3;

	if(argc != 2){
		fprintf(stderr,"Usage: sphere number\n");
		exit(1);
	}
	n=atoi(argv[1]);
	for(i=0;i<n;i++){
		t0=i*PAI/n;
		t1=(i+1)*PAI/n;
		for(j=0;j<2*n;j++){
			t2=j*PAI/n;
			t3=(j+1)*PAI/n;
			printf("\tHEX\t05,03\n");
			printf("\tHEX\t");
			putp(sin(t0)*cos(t2),sin(t0)*sin(t2),cos(t0));
			putchar(',');
			putp(sin(t1)*cos(t2),sin(t1)*sin(t2),cos(t1));
			if(i!=n-1){
				putchar(',');
				putp(sin(t1)*cos(t3),sin(t1)*sin(t3),cos(t1));
			}
			if(i!=0){
				putchar(',');
				putp(sin(t0)*cos(t3),sin(t0)*sin(t3),cos(t0));
			}
/*			putchar(';');*/
			putchar('\n');
		}
	}
}

putp(x,y,z)
double	x,y,z;
{
/*	printf(" (%02X,%02X,%02X,%g,%g,%g) ",(unsigned char)(x),(unsigned char)(y),(unsigned char)(z),x,y,z);*/
	printf("%02X,%02X,%02X",(unsigned char)(x*0x40+0x80),(unsigned char)(y*0x40+0x80),(unsigned char)(z*0x40));
}


