/* * sunburst.c * * Many encoding schemes were put forward when the UPC system was being considered, * and this code encodes numeric data according to one of the more interesting looking * varieties. The system proposed by Charecogn Systems Inc. doesn't seem to have had * an official name, but "sunburst" seems appropriate from its appearance. The idea was * that the symbol would be read by a sensor mounted on a rotating head. * * This code takes numeric data and produces an image as an SVG. * * More details in US Patent 3,636,317, Filed April 28th 1969. * */ #include #include #include #include void print_head(char upc_number[]) { printf("\n"); printf("\n"); printf("\n"); printf(" Sunburst %s\n\n", upc_number); printf(" \n"); printf(" \n"); } void print_foot() { printf(" \n"); printf("\n"); } static const char *torrey[11] = { "01010101", "10010101", "01100101", "10100101", "01010110", "10010110", "01100110", "10101010", "01011001", "10011001", "01001101" // Two "surplus" codes were also defined as "01011010" and "10110010" // In these codes 0 is dark and 1 is light }; int main(int argc, char** argv) { int in_length; char upc_number[12]; char binary[100]; int i; int posn; int left, right; double ax, ay, bx, by, cx, cy, dx, dy; if (argc != 2) { /* Only command line input should be the number to encode */ printf("Usage: sunburst {number}\n"); printf("Where {number} is the number to be encoded, up to 11 digits\n"); return 0; } else { in_length = strlen(argv[1]); if (in_length > 11) { /* Check maximum length */ printf("Input data too long\n"); return 0; } else { /* Add padding if needed */ strcpy(upc_number, ""); for(i = in_length; i < 11; i++) { strcat(upc_number, "0"); } strcat(upc_number, argv[1]); } } /* Check input is numeric */ for (i = 0; i < 11; i++) { if ((upc_number[i] < '0') || (upc_number[i] > '9')) { printf("Invalid character(s) in input data\n"); return 0; } } strcpy(binary, torrey[10]); // Start for (i = 0; i < 11; i++) { strcat(binary, torrey[upc_number[i] - '0']); } print_head(upc_number); posn = 0; do { if (binary[posn] == '0') { for (i = 0; binary[posn + i] == '0'; i++); left = posn; right = posn + i; ax = 50.0 + (18.72 * cos(0.06545 * left - 1.5708)); ay = 50.0 + (18.72 * sin(0.06545 * left - 1.5708)); bx = 50.0 + (50.0 * cos(0.06545 * left - 1.5708)); by = 50.0 + (50.0 * sin(0.06545 * left - 1.5708)); cx = 50.0 + (50.0 * cos(0.06545 * right - 1.5708)); cy = 50.0 + (50.0 * sin(0.06545 * right - 1.5708)); dx = 50.0 + (18.72 * cos(0.06545 * right - 1.5708)); dy = 50.0 + (18.72 * sin(0.06545 * right - 1.5708)); printf(" \n", bx, by, cx, cy, dx, dy, ax, ay); posn += i; } else { posn++; } } while (posn < 96); print_foot(); return (EXIT_SUCCESS); }