/* Subprograms and main program, discriminant = 0 mod 4, T. J. Dekker, 2007. */ /* Draws pictures of prime numbers and prime non-principal ideals in colors. */ /* The latter are obtained by dividing by a non-pricipal ideal of a given norm. */ /* main program moreover uses subprograms from files quadchar.c and quadsiev.c. */ /* DrawUnit.c defines 'Initialize' and, by inclusion, drawing subprograms used. */ # include # include "DrawUnit.c" # define X00 20 /* x-coordinate of start of picture */ # define Y00 16 /* y-coordinate of start of picture */ # define DX 5 /* spacing in x direction */ # define DY 5 /* and in y direction */ # define H 4 /* size of disks */ # define MAXFACS 4 /* maximum numbers of discriminant factors */ # define MAXPERIOD 1436 /* maximal period allowed by the program */ # define SIZE 40000 /* times 16 yields maximum capacity 400000 */ # define AMAX 72 /* getallen x + y à rad voor |x| <= AMAX */ # define BMAX 54 /* en voor |y| <= BMAX */ # define QNORM(x, y) abs(x * x + coef2 * y * y) /* norm of x + y à rad */ void drawprim (int, int, RGBColor *); int x0, y0, maxnorm, rad, discriminant, period, coef2, nfacs, facs[MAXFACS], qchar[MAXPERIOD], deltac[MAXPERIOD]; short int prinorm[SIZE]; Rect windRect; RGBColor red = {-1,0,0}, green = {0,-1,0}, blue = {0,0,-1}, black = {0,0,0}, gray = {32767,32767,16384} ; /* include quad0clasX.c where X is 1, 2 or 3: */ # include "quad0clas1.c" void drawprim (int a, int b ,RGBColor *color) /* draws H*H square on place a, b */ { int k, x, y; x = a * DX + x0; y = b * DY + y0; RGBForeColor(color); for (k = 1; k <= H; k++) { MoveTo (x + k, y + 1); LineTo (x + k, y + H); } } /* end drawprim */ void drawpicture() /* draws picture of primes, units and prime ideals for discriminant % 4 == 1 */ { int a, b, i; char q[40]; char signtoken[] = "-o+"; x0 = X00 + DX * AMAX; y0 = Y00 + 30 + DY * BMAX; MoveTo(X00 + 24, Y00); sprintf(q, "Q(Ã%d) chi ", rad);drawstring(q); coef2 = - discriminant / 4; showitem(); MoveTo(X00, Y00 + 20); for (i = 0; i < period; i++) DrawChar(signtoken[qchar[i] + 1]); for (b = -BMAX; b <= BMAX; b++) for (a = - AMAX; a <= AMAX; a++) drawitem(a, b, QNORM(a, b)); } /* end drawpicture */ void main () { char ch; int aa = AMAX * AMAX, bb = BMAX * BMAX, m, k; for (k = 0; (rad = radicand[k]) != 0; k++) { scanf("%c", &ch); /* interrupt program to save picture */ m = rad*bb; maxnorm = ((rad < 0) ? aa - m : (m > aa) ? m : aa) + 1; if (maxnorm > capacity(SIZE)) maxnorm = capacity(SIZE); disfactors(rad, &discriminant, &nfacs, facs); /* factorize radicand */ quadchar(discriminant, nfacs, facs, &period, qchar); /* character */ sievquad(nfacs, facs, qchar, SIZE, maxnorm, prinorm); /* primes */ Initialize(windRect); /* initialize picture of primes */ drawpicture(); /* draw character and picture of primes and units */ } }