// cc -o schotter-c schotter.c -lm

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

int main(int argc, char **argv) {
  double X, Y;
  
  void Open(double X, double Y) {}
  void Close(void) {}
  void Leer(double X, double Y) { printf("\nMoveto(%d, %d)\n", (int)round(X), (int)round(Y)); }
  void Line(double X, double Y) { printf("Lineto(%d, %d)\n", (int)round(X), (int)round(Y)); }
  void Sonk(int X) {}
  
  double J(double Ja, double Je) {  //  ZUFALLS-GENERATOR J
    static double Ji = 1306859721;
    Ji = 5 * Ji;
    if (Ji >= 8589934592) Ji -= 8589934592;
    if (Ji >= 4294967296) Ji -= 4294967296;
    if (Ji >= 2147483648) Ji -= 2147483648;
    return ((Ji / 2147483648) * (Je - Ja) + Ja);
  }
  
  //  SCHOTTER
  double R, Pihalb, Pi4t, P, Q, P1, Q1, Xm, Ym, Hor, Ver, Jli, Jre, Jun, Job;
  int I, M, T;
  
  void Serie(double Quer, double Hoch, int Xmal, int Ymal, void Figur(void)) {
    double Yanf;
    int Countx, County;
    
    P = -Quer * Xmal * .5;
    Yanf = -Hoch * Ymal * .5;
    Q = Yanf;
    for (Countx = 1; Countx <= Xmal; Countx++) {
      Q = Yanf;
      for (County = 1; County <= Ymal; County++) {
        Figur();
        Q += Hoch;
      }
      P += Quer;
    }
    Leer(-148.0, -105.0);
    Close();
    Sonk(11);
    Open(X, Y);
  }
  
  void Quad(void) {
    double P1, Q1, Psi, Ja1, Je1, Ja2, Je2;
    int S;
    
    Je1 = 5 * 1 / 264;
    Ja1 = -Je1;
    Je2 = Pi4t * (1 + (I / 264));
    Ja2 = Pi4t * (1 - (I / 264));
    P1 = P + 5 + J(Ja1, Je1);
    Q1 = Q + 5 + J(Ja1, Je1);
    Psi = J(Ja2, Je2);
    Leer(P1 + R * cos(Psi), Q1 + R * sin(Psi));
    for (S = 1; S <= 4; S++) {
      Psi += Pihalb;
      Line(P1 + R * cos(Psi), Q1 + R * sin(Psi));
    }
    I++;
  }
  
  X = Y = 0;
  Open(X, Y);
  R = 5 * 1.4142;
  Pihalb = 3.14159 * .5;
  Pi4t = Pihalb * .5;
  I = 0;
  Serie(10.0, 10.0, 22, 12, &Quad);
  Close();
  
  exit(0);
  return (1);
}
