home *** CD-ROM | disk | FTP | other *** search
/ Computerworld: Vánoce 98 / Computerworld_1998-12_cd.bin / cw / programy / java / takeover / coal / Coal / coal.java < prev    next >
Encoding:
Java Source  |  1998-05-15  |  88.1 KB  |  2,599 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Graphics;
  4. import java.awt.Color;
  5. import java.awt.image.*;
  6. import java.awt.*;
  7. import java.io.*;
  8. import java.net.*;
  9.  
  10. class face {
  11.   int p,p1,p2,nr,clr,clr1,clr2,nx,ny,nx1,ny1,nx2,ny2;
  12. }
  13.  
  14. class PL {
  15.   int x,mapx,mapy;
  16. }
  17.  
  18. class POLY3_2 {
  19.   int x[] = new int[3];
  20.   int y[] = new int[3];
  21. }
  22.  
  23. class mat {
  24.  
  25.   int a1,a2,a3,b1,b2,b3,c1,c2,c3;
  26.  
  27. }
  28.  
  29. class idx {
  30.   int z,nr;
  31. }
  32.  
  33. class Particle {
  34.  
  35. float fx,fy,fz;
  36. int sx,sy,sz,px,py,pz,phix,phiy,phiz;
  37. mat rotx = new mat(), roty = new mat(), rotz = new mat();
  38.  
  39.   public Particle(int x, int y, int z) {
  40.     fx=x; fy=y; fz=z;
  41.     sx=x; sy=y; sz=z;
  42.   }
  43.  
  44.   public void addx(float x) {
  45.     fx+=x;
  46.     sx=(int)fx;
  47.   }
  48.  
  49.   public void addy(float y) {
  50.     fy+=y;
  51.     sy=(int)fy;
  52.   }
  53.  
  54.   public void addz(float z) {
  55.     fz+=z;
  56.     sz=(int)fz;
  57.   }
  58.  
  59.   public void setRotx(int x) {
  60.     phix=x;
  61.   }
  62.  
  63.   public void setRoty(int y) {
  64.     phiy=y;
  65.   }
  66.  
  67.   public void setRotz(int z) {
  68.     phiz=z;
  69.   }
  70.  
  71. }
  72.  
  73. public class Coal extends Applet implements Runnable{
  74.  
  75.  
  76. int i,i1,x,y,color,cnt = 1,xpos = 0,timer = 0, cnter = 0, cnter1 = 0, cval = 1;
  77. int scrx=120,scrx1=120,scrx2=200,scrx3=200,sx=60;
  78. int cameray = 120, camerax = 0, cameraz = 100;
  79. double tstval,xadd,xval,yval;
  80. int cnt1 = 0;
  81. int cnt2 = 0;
  82. int cnt3 = 0;
  83. Particle stars[] = new Particle[250];
  84. double lightx = 0.1f, lighty=0.1f, lightz=0.8f;
  85. idx indx[] = new idx[520];
  86. int maxverts,maxface;
  87. int SinTab[] = new int[256],CosTab[] = new int[256];
  88. mat rotz = new mat(), roty = new mat(), rotx = new mat();
  89. int pointx[] = new int[1290],pointy[] = new int[1290],pointz[] = new int[300], pointz2[] = new int[300];
  90. double normx[] = new double[900], normy[] = new double[900], normz[] = new double[900];
  91. double gnormx[] = new double[520], gnormy[] = new double[520], gnormz[] = new double[520];
  92. int px[] = new int[300],py[] = new int[300],pz[] = new int[300];
  93. int pix[] = new int[240*200];
  94. int pix1[] = new int[240*200];
  95. int difx[] = new int[240*200];
  96. int dispic[] = new int[240*200];
  97. int blue[] = new int[240*200];
  98. int red[] = new int[240*200];
  99. int green[] = new int[240*200];
  100. int tex[];
  101. int noise[] = new int[3000];
  102. int cloud[] = new int[128*128];
  103. int cloud1[] = new int[128*128];
  104. double Stab[] = new double[361];
  105. double Ctab[] = new double[361];
  106. Image Img,Img1,Shows[];
  107. int frameNumber = -1;
  108. MemoryImageSource source;
  109. Toolkit t = getToolkit();
  110. Thread killme = null;
  111. PixelGrabber grab;
  112. Dimension offDimension;
  113. Image offImage;
  114. Graphics offGraphics;
  115. int delay,partnr;
  116. int sxpos[] = new int[240],sypos[] = new int[240];
  117. int scnt[] = new int[125];
  118. int picxsize = 240;
  119. int picysize = 100;
  120. double brnval = 0.2f;
  121. boolean pos = false;
  122. boolean pos1[] = new boolean[121];
  123. String s,text[] = new String[4];
  124. MediaTracker tracer = new MediaTracker(this);
  125. face facelist[] = new face[520];
  126. AudioClip music;
  127. PL poly_hullxs[] = new PL[3000];
  128. PL poly_hullxe[] = new PL[3000];
  129.  
  130. Color c = new Color(0.0f,0.0f,0.0f);
  131.  
  132. public int Rand1(int base,int delta)
  133. { int i;
  134.   i=base+(int)(Math.random()*delta)-delta/2;
  135.   if (i<0) i=0; if (i>255) i=255;
  136.   return i;
  137. }
  138.  
  139.   public int Sinus(int Idx)
  140.    { return(SinTab[Idx]); }
  141.  
  142.   public int Cosinus(int Idx)
  143.    { return(CosTab[Idx]); }
  144.  
  145.   public void Calrotxmat (int phix, mat rotx)
  146.    {
  147.      rotx.a1=0; rotx.a2=0; rotx.a3=0;
  148.      rotx.b1=0; rotx.b2=Cosinus(phix); rotx.b3=Sinus(phix);
  149.      rotx.c1=0; rotx.c2=Sinus(phix); rotx.c3=Cosinus(phix);
  150.    }
  151.  
  152.    public void Calrotymat (int phiy, mat roty)
  153.    {
  154.       roty.a1=Cosinus(phiy); roty.a2=0; roty.a3=-Sinus(phiy);
  155.       roty.b1=0; roty.b2=0; roty.b3=0;
  156.       roty.c1=Sinus(phiy); roty.c2=0; roty.c3=Cosinus(phiy);
  157.    }
  158.  
  159.    public void Calrotzmat (int phiz, mat rotz)
  160.    {
  161.      rotz.a1=Cosinus(phiz); rotz.a2=Sinus(phiz); rotz.a3=0;
  162.      rotz.b1=Sinus(phiz); rotz.b2=Cosinus(phiz); rotz.b3=0;
  163.      rotz.c1=0; rotz.c2=0; rotz.c3=0;
  164.    }
  165.  
  166. void Normvek(double normx[], double normy[], double normz[], int nr)
  167. {
  168.   double l=normx[nr]*normx[nr]+normy[nr]*normy[nr]+normz[nr]*normz[nr];
  169.   if (l>0.0f) { l=1/Math.sqrt(l);
  170.     normx[nr]*=l;
  171.     normy[nr]*=l;
  172.     normz[nr]*=l;
  173.  }
  174. }
  175.  
  176. void Calcnorm(face Face,double normx[], double normy[], double normz[], int nr)
  177. { int x,y,z;
  178.   normx[nr]=normy[nr]=normz[nr]=0;
  179.   x=(py[Face.p]-py[Face.p1])*(pz[Face.p]+pz[Face.p1]);
  180.   y=(pz[Face.p]-pz[Face.p1])*(px[Face.p]+px[Face.p1]);
  181.   z=(px[Face.p]-px[Face.p1])*(py[Face.p]+py[Face.p1]);
  182.   normx[nr]+=x;
  183.   normy[nr]+=y;
  184.   normz[nr]+=z;
  185.   x=(py[Face.p1]-py[Face.p2])*(pz[Face.p1]+pz[Face.p2]);
  186.   y=(pz[Face.p1]-pz[Face.p2])*(px[Face.p1]+px[Face.p2]);
  187.   z=(px[Face.p1]-px[Face.p2])*(py[Face.p1]+py[Face.p2]);
  188.   normx[nr]+=x;
  189.   normy[nr]+=y;
  190.   normz[nr]+=z;
  191.   x=(py[Face.p2]-py[Face.p])*(pz[Face.p2]+pz[Face.p]);
  192.   y=(pz[Face.p2]-pz[Face.p])*(px[Face.p2]+px[Face.p]);
  193.   z=(px[Face.p2]-px[Face.p])*(py[Face.p2]+py[Face.p]);
  194.   normx[nr]+=x;
  195.   normy[nr]+=y;
  196.   normz[nr]+=z;
  197. //  normz[nr]*=-1;
  198. }
  199.  
  200. public int[] CalcMarble(int K,int H)
  201. { int i,j,i2,j2,i3,j3,h,h2,delta,a,b,c,d;
  202.   int cloud[] = new int[256*256];
  203.   for (h=256; h>1; h=h2)
  204.     { h2=h/2; delta=h*K+H;
  205.       for (i=0; i<256; i+=h)
  206.         for (i2=((i+h)&255),j=0; j<256; j+=h)
  207.           { /* Get corner heights (a=TL, b=TR, c=BL, d=BR) */
  208.             j2=((j+h)&255);
  209.             i3=i+h2; j3=j+h2;
  210.             a=cloud[(i<<8)+j]; b=cloud[(i2<<8)+j];
  211.             c=cloud[(i<<8)+j2]; d=cloud[(i2<<8)+j2];
  212.             /* Central point */
  213.             cloud[(i3<<8)+j3]=Rand1((a+b+c+d)/4,delta);
  214.             /* Top point */
  215.             if (i==0)
  216.               cloud[(i3<<8)+j]=Rand1((a+b)/2,delta);
  217.             /* Left point */
  218.             if (j==0)
  219.               cloud[(i<<8)+j3]=Rand1((a+c)/2,delta);
  220.             /* Right point */
  221.             cloud[(i2<<8)+j3]=Rand1((b+d)/2,delta);
  222.             /* Bottom point */
  223.             cloud[(i3<<8)+j2]=Rand1((c+d)/2,delta);
  224.           }
  225.     }
  226.     return cloud;
  227. }
  228.  
  229. void Texture_poly3(POLY3_2 pnt,int x0,int y0,int x1,int y1,int x2, int y2) {
  230. //═══ shade poly with Z-Buffer
  231.  
  232.   int i,i1,miny,maxy;
  233.   int ys,ye;     // y start,end
  234.   int xl,yl;     // x,y length
  235.   int xp,yp;     // x,y position
  236.   int xadd,yadd; // x,y adders
  237.   int xcnt;      // x position counter
  238.   int cadd,zadd;
  239.   int ccnt,zcnt;
  240.   int a1,a2;
  241.   int ysort[] = new int[3];
  242.   int order;
  243.   int map = 0;
  244.   
  245.   // calc point order in y axis
  246.   ysort[2] = 2;
  247.   if(pnt.y[0]<pnt.y[1]) {
  248.     ysort[0] = 0; ysort[1] = 1;
  249.   } else {
  250.     ysort[0] = 1; ysort[1] = 0;
  251.   }
  252.   if(pnt.y[ysort[1]]>pnt.y[ysort[2]]) {
  253.     i = ysort[2];  // swap ysort[x] and ysort[y]
  254.     ysort[2] = ysort[1];
  255.     ysort[1] = i;
  256.   };
  257.   if(pnt.y[ysort[0]]>pnt.y[ysort[1]]) {
  258.     i = ysort[0];   // swap ysort[x] and ysort[y]
  259.     ysort[0] = ysort[1];
  260.     ysort[1] = i;
  261.   };
  262.  
  263.   // y start,end setzen
  264.   ys = pnt.y[ysort[0]];
  265.   ye = pnt.y[ysort[2]];
  266.  
  267.   // winkel berechnen:  a1 zu y-achse, a2 zu y-achse
  268.   a1 = ((pnt.x[ysort[1]]-pnt.x[ysort[0]]) << 16)/((pnt.y[ysort[1]]-pnt.y[ysort[0]])+1);
  269.   a2 = ((pnt.x[ysort[2]]-pnt.x[ysort[0]]) << 16)/((pnt.y[ysort[2]]-pnt.y[ysort[0]])+1);
  270.  
  271.   // Sortierfolge abbilden
  272.   order = ysort[0] * 3 + ysort[2];
  273.  
  274.   // map bilden, bit 0 -> start punkte 1 -> end punkte
  275.   switch(order) {
  276.     // p0,p2,p1: a2<=a1 -> 110
  277.     case 1: map = 6; break;
  278.     // p0,p1,p2: a2<=a1 -> 011
  279.     case 2: map = 3; break;
  280.     // p1,p2,p0: a2<=a1 -> 110
  281.     case 3: map = 6; break;
  282.     // p1,p0,p2: a2<=a1 -> 101
  283.     case 5: map = 5; break;
  284.     // p2,p1,p0: a2<=a1 -> 011
  285.     case 6: map = 3; break;
  286.     // p2,p0,p1: a2<=a1 -> 101
  287.     case 7: map = 5; break;
  288.   }
  289.   if(a2>a1) map ^= 0xff;  // angle a2>a1 -> turn map
  290.  
  291.   //───  run from x0,y0 to x1,y1
  292.   xl = pnt.x[1] - pnt.x[0];
  293.   yl = Math.abs(pnt.y[1] - pnt.y[0]);
  294.   if((map & 0x01) == 0) {
  295.   // poly_hullxs; else poly_hull = poly_hullxe;
  296.     yp = pnt.y[0];
  297.     poly_hullxs[yp].x = pnt.x[0];
  298.     ccnt = (x0 << 8);
  299.     zcnt = (y0 << 8);
  300.     poly_hullxs[yp].mapx = ccnt;
  301.     poly_hullxs[yp].mapy = zcnt;
  302.     if(yl>0) {
  303.       xadd = (xl << 8) / yl;
  304.       if(pnt.y[1]>pnt.y[0]) yadd = 1; else yadd = -1;
  305.       xcnt = pnt.x[0] << 8;
  306.       cadd = ((x1 - x0) << 8) / yl;
  307.       zadd = ((y1 - y0) << 8) / yl;
  308.       while(yp != pnt.y[1]) {
  309.         yp += yadd;
  310.         xcnt += xadd;
  311.         poly_hullxs[yp].x = xcnt / 256;
  312.         ccnt += cadd;
  313.         zcnt += zadd;
  314.         poly_hullxs[yp].mapx = ccnt;
  315.         poly_hullxs[yp].mapy = zcnt;
  316.       }
  317.     }
  318.   } else {
  319.     yp = pnt.y[0];
  320.     poly_hullxe[yp].x = pnt.x[0];
  321.     ccnt = (x0 << 8);
  322.     zcnt = (y0 << 8);
  323.     poly_hullxe[yp].mapx = ccnt;
  324.     poly_hullxe[yp].mapy = zcnt;
  325.     if(yl>0) {
  326.       xadd = (xl << 8) / yl;
  327.       if(pnt.y[1]>pnt.y[0]) yadd = 1; else yadd = -1;
  328.       xcnt = pnt.x[0] << 8;
  329.       cadd = ((x1 - x0) << 8) / yl;
  330.       zadd = ((y1 - y0) << 8) / yl;
  331.       while(yp != pnt.y[1]) {
  332.         yp += yadd;
  333.         xcnt += xadd;
  334.         poly_hullxe[yp].x = xcnt / 256;
  335.         ccnt += cadd;
  336.         zcnt += zadd;
  337.         poly_hullxe[yp].mapx = ccnt;
  338.         poly_hullxe[yp].mapy = zcnt;
  339.       }
  340.     }
  341.   }
  342.   //───  run from x1,y1 to x2,y2
  343.   xl = pnt.x[2] - pnt.x[1];
  344.   yl = Math.abs(pnt.y[2] - pnt.y[1]);
  345.   if((map & 0x02) == 0) {
  346.     //poly_hull = poly_hullxs; else poly_hull = poly_hullxe;
  347.     yp = pnt.y[1];
  348.     poly_hullxs[yp].x = pnt.x[1];
  349.     ccnt = (x1 << 8);
  350.     zcnt = (y1 << 8);
  351.     poly_hullxs[yp].mapx = ccnt;
  352.     poly_hullxs[yp].mapy = zcnt;
  353.     if(yl>0) {
  354.       xadd = (xl << 8) / yl;
  355.       if(pnt.y[2]>pnt.y[1]) yadd = 1; else yadd = -1; // y direction
  356.       xcnt = pnt.x[1] << 8;
  357.       cadd = ((x2 - x1) << 8) / yl;
  358.       zadd = ((y2 - y1) << 8) / yl;
  359.       while(yp != pnt.y[2]) {
  360.         yp += yadd;
  361.         xcnt += xadd;
  362.         poly_hullxs[yp].x = xcnt / 256;
  363.         ccnt += cadd;
  364.         zcnt += zadd;
  365.         poly_hullxs[yp].mapx = ccnt;
  366.         poly_hullxs[yp].mapy = zcnt;
  367.       }
  368.     }
  369.   } else {
  370.     yp = pnt.y[1];
  371.     poly_hullxe[yp].x = pnt.x[1];
  372.     ccnt = (x1 << 8);
  373.     zcnt = (y1 << 8);
  374.     poly_hullxe[yp].mapx = ccnt;
  375.     poly_hullxe[yp].mapy = zcnt;
  376.     if(yl>0) {
  377.       xadd = (xl << 8) / yl;
  378.       if(pnt.y[2]>pnt.y[1]) yadd = 1; else yadd = -1; // y direction
  379.       xcnt = pnt.x[1] << 8;
  380.       cadd = ((x2 - x1) << 8) / yl;
  381.       zadd = ((y2 - y1) << 8) / yl;
  382.       while(yp != pnt.y[2]) {
  383.         yp += yadd;
  384.         xcnt += xadd;
  385.         poly_hullxe[yp].x = xcnt / 256;
  386.         ccnt += cadd;
  387.         zcnt += zadd;
  388.         poly_hullxe[yp].mapx = ccnt;
  389.         poly_hullxe[yp].mapy = zcnt;
  390.       }
  391.     }
  392.   }
  393.   //───  run from x2,y2 to x0,y0
  394.   xl = pnt.x[0] - pnt.x[2];
  395.   yl = Math.abs(pnt.y[0] - pnt.y[2]);
  396.   if((map & 0x04) == 0) {
  397.     //poly_hull = poly_hullxs; else poly_hull = poly_hullxe;
  398.     yp = pnt.y[2];
  399.     poly_hullxs[yp].x = pnt.x[2];
  400.     ccnt = (x2 << 8);
  401.     zcnt = (y2 << 8);
  402.     poly_hullxs[yp].mapx = ccnt;
  403.     poly_hullxs[yp].mapy = zcnt;
  404.     if(yl>0) {
  405.       xadd = (xl << 8) / yl;
  406.       if(pnt.y[0]>pnt.y[2]) yadd = 1; else yadd = -1;
  407.       xcnt = pnt.x[2] << 8;
  408.       cadd = ((x0 - x2) << 8) / yl;
  409.       zadd = ((y0 - y2) << 8) / yl;
  410.       while(yp != pnt.y[0]) {
  411.         yp += yadd;
  412.         xcnt += xadd;
  413.         poly_hullxs[yp].x = xcnt / 256;
  414.         ccnt += cadd;
  415.         zcnt += zadd;
  416.         poly_hullxs[yp].mapx = ccnt;
  417.         poly_hullxs[yp].mapy = zcnt;
  418.       }
  419.     }
  420.    } else {
  421.     yp = pnt.y[2];
  422.     poly_hullxe[yp].x = pnt.x[2];
  423.     ccnt = (x2 << 8);
  424.     zcnt = (y2 << 8);
  425.     poly_hullxe[yp].mapx = ccnt;
  426.     poly_hullxe[yp].mapy = zcnt;
  427.     if(yl>0) {
  428.       xadd = (xl << 8) / yl;
  429.       if(pnt.y[0]>pnt.y[2]) yadd = 1; else yadd = -1;
  430.       xcnt = pnt.x[2] << 8;
  431.       cadd = ((x0 - x2) << 8) / yl;
  432.       zadd = ((y0 - y2) << 8) / yl;
  433.       while(yp != pnt.y[0]) {
  434.         yp += yadd;
  435.         xcnt += xadd;
  436.         poly_hullxe[yp].x = xcnt / 256;
  437.         ccnt += cadd;
  438.         zcnt += zadd;
  439.         poly_hullxe[yp].mapx = ccnt;
  440.         poly_hullxe[yp].mapy = zcnt;
  441.       }
  442.     }
  443.   }
  444.   // draw
  445.   for(i=ys; i<=ye; i++) {
  446.     int ypos=i*picxsize;
  447.     ccnt = (poly_hullxs[i].mapx + 127) << 8;
  448.     zcnt = (poly_hullxs[i].mapy + 127) << 8;
  449.     xl = poly_hullxe[i].x - poly_hullxs[i].x;
  450.     if(xl>0) {
  451.       cadd = ((poly_hullxe[i].mapx - poly_hullxs[i].mapx) << 8)/ xl;
  452.       zadd = ((poly_hullxe[i].mapy - poly_hullxs[i].mapy) << 8)/ xl;
  453.     } else {cadd = 0; zadd=0; }
  454.     for(i1=poly_hullxs[i].x; i1<=poly_hullxe[i].x; i1++) {
  455.        if (i1>0&&i1<picxsize&&i>0&&i<picysize) red[i1+ypos]=tex[(ccnt >> 16)+((zcnt >> 16) << 8)];
  456.       ccnt += cadd;
  457.       zcnt += zadd;
  458.     }
  459.   }
  460. }
  461.  
  462. public void Bubble (int xc,int yc,int r,int col)
  463. {int x,y,p;
  464.   x=0; y=r;
  465.   if (xc+x>0&&xc+x<picxsize&&yc+y>0&&yc+y<picysize) blue[xc+x+(yc+y)*picxsize]=col;
  466.   if (xc-x>0&&xc-x<picxsize&&yc+y>0&&yc+y<picysize) blue[xc-x+(yc+y)*picxsize]=col;
  467.   if (xc+x>0&&xc+x<picxsize&&yc-y>0&&yc-y<picysize) blue[xc+x+(yc-y)*picxsize]=col;
  468.   if (xc-x>0&&xc-x<picxsize&&yc-y>0&&yc-y<picysize) blue[xc-x+(yc-y)*picxsize]=col;
  469.   if (xc+y>0&&xc+y<picxsize&&yc+x>0&&yc+x<picysize) blue[xc+y+(yc+x)*picxsize]=col;
  470.   if (xc-y>0&&xc-y<picxsize&&yc+x>0&&yc+x<picysize) blue[xc-y+(yc+x)*picxsize]=col;
  471.   if (xc+y>0&&xc+y<picxsize&&yc-x>0&&yc-x<picysize) blue[xc+y+(yc-x)*picxsize]=col;
  472.   if (xc-y>0&&xc-y<picxsize&&yc-x>0&&yc-x<picysize) blue[xc-y+(yc-x)*picxsize]=col;
  473.   p=1-r;
  474.   while (x<y) {
  475.     if (p<0) x=x+1; else {x=x+1; y=y-1;}
  476.     if (p<0) p=p+2*x+1; else p=p+2*(x-y)+1;
  477.     if (xc+x>0&&xc+x<picxsize&&yc+y>0&&yc+y<picysize) blue[xc+x+(yc+y)*picxsize]=col;
  478.     if (xc-x>0&&xc-x<picxsize&&yc+y>0&&yc+y<picysize) blue[xc-x+(yc+y)*picxsize]=col;
  479.     if (xc+x>0&&xc+x<picxsize&&yc-y>0&&yc-y<picysize) blue[xc+x+(yc-y)*picxsize]=col;
  480.     if (xc-x>0&&xc-x<picxsize&&yc-y>0&&yc-y<picysize) blue[xc-x+(yc-y)*picxsize]=col;
  481.     if (xc+y>0&&xc+y<picxsize&&yc+x>0&&yc+x<picysize) blue[xc+y+(yc+x)*picxsize]=col;
  482.     if (xc-y>0&&xc-y<picxsize&&yc+x>0&&yc+x<picysize) blue[xc-y+(yc+x)*picxsize]=col;
  483.     if (xc+y>0&&xc+y<picxsize&&yc-x>0&&yc-x<picysize) blue[xc+y+(yc-x)*picxsize]=col;
  484.     if (xc-y>0&&xc-y<picxsize&&yc-x>0&&yc-x<picysize) blue[xc-y+(yc-x)*picxsize]=col;
  485.   }
  486. }
  487.  
  488. public void Circle1 (int xc,int yc,int r,int col)
  489. {int x,y,p;
  490.   x=0; y=r;
  491.   if (xc+x>0&&xc+x<picxsize&&yc+y>0&&yc+y<picysize) pix1[xc+x+(yc+y)*picxsize]=col;
  492.   if (xc-x>0&&xc-x<picxsize&&yc+y>0&&yc+y<picysize) pix1[xc-x+(yc+y)*picxsize]=col;
  493.   if (xc+x>0&&xc+x<picxsize&&yc-y>0&&yc-y<picysize) pix1[xc+x+(yc-y)*picxsize]=col;
  494.   if (xc-x>0&&xc-x<picxsize&&yc-y>0&&yc-y<picysize) pix1[xc-x+(yc-y)*picxsize]=col;
  495.   if (xc+y>0&&xc+y<picxsize&&yc+x>0&&yc+x<picysize) pix1[xc+y+(yc+x)*picxsize]=col;
  496.   if (xc-y>0&&xc-y<picxsize&&yc+x>0&&yc+x<picysize) pix1[xc-y+(yc+x)*picxsize]=col;
  497.   if (xc+y>0&&xc+y<picxsize&&yc-x>0&&yc-x<picysize) pix1[xc+y+(yc-x)*picxsize]=col;
  498.   if (xc-y>0&&xc-y<picxsize&&yc-x>0&&yc-x<picysize) pix1[xc-y+(yc-x)*picxsize]=col;
  499.   p=1-r;
  500.   while (x<y) {
  501.     if (p<0) x=x+1; else {x=x+1; y=y-1;}
  502.     if (p<0) p=p+2*x+1; else p=p+2*(x-y)+1;
  503.     if (xc+x>0&&xc+x<picxsize&&yc+y>0&&yc+y<picysize) pix1[xc+x+(yc+y)*picxsize]=col;
  504.     if (xc-x>0&&xc-x<picxsize&&yc+y>0&&yc+y<picysize) pix1[xc-x+(yc+y)*picxsize]=col;
  505.     if (xc+x>0&&xc+x<picxsize&&yc-y>0&&yc-y<picysize) pix1[xc+x+(yc-y)*picxsize]=col;
  506.     if (xc-x>0&&xc-x<picxsize&&yc-y>0&&yc-y<picysize) pix1[xc-x+(yc-y)*picxsize]=col;
  507.     if (xc+y>0&&xc+y<picxsize&&yc+x>0&&yc+x<picysize) pix1[xc+y+(yc+x)*picxsize]=col;
  508.     if (xc-y>0&&xc-y<picxsize&&yc+x>0&&yc+x<picysize) pix1[xc-y+(yc+x)*picxsize]=col;
  509.     if (xc+y>0&&xc+y<picxsize&&yc-x>0&&yc-x<picysize) pix1[xc+y+(yc-x)*picxsize]=col;
  510.     if (xc-y>0&&xc-y<picxsize&&yc-x>0&&yc-x<picysize) pix1[xc-y+(yc-x)*picxsize]=col;
  511.   }
  512. }
  513.  
  514. public void Circle (int xc,int yc,int r,int col)
  515. {int x,y,p;
  516.   x=0; y=r;
  517.   if (xc+x>0&&xc+x<240&&yc+y>0&&yc+y<200) if (difx[xc+x+(yc+y)*240]>15&&dispic[xc+x+(yc+y)*240]<col) dispic[xc+x+(yc+y)*240]=col;
  518.   if (xc-x>0&&xc-x<240&&yc+y>0&&yc+y<200) if (difx[xc-x+(yc+y)*240]>15&&dispic[xc-x+(yc+y)*240]<col) dispic[xc-x+(yc+y)*240]=col;
  519.   if (xc+x>0&&xc+x<240&&yc-y>0&&yc-y<200) if (difx[xc+x+(yc-y)*240]>15&&dispic[xc+x+(yc-y)*240]<col) dispic[xc+x+(yc-y)*240]=col;
  520.   if (xc-x>0&&xc-x<240&&yc-y>0&&yc-y<200) if (difx[xc-x+(yc-y)*240]>15&&dispic[xc-x+(yc-y)*240]<col) dispic[xc-x+(yc-y)*240]=col;
  521.   if (xc+y>0&&xc+y<240&&yc+x>0&&yc+x<200) if (difx[xc+y+(yc+x)*240]>15&&dispic[xc+y+(yc+x)*240]<col) dispic[xc+y+(yc+x)*240]=col;
  522.   if (xc-y>0&&xc-y<240&&yc+x>0&&yc+x<200) if (difx[xc-y+(yc+x)*240]>15&&dispic[xc-y+(yc+x)*240]<col) dispic[xc-y+(yc+x)*240]=col;
  523.   if (xc+y>0&&xc+y<240&&yc-x>0&&yc-x<200) if (difx[xc+y+(yc-x)*240]>15&&dispic[xc+y+(yc-x)*240]<col) dispic[xc+y+(yc-x)*240]=col;
  524.   if (xc-y>0&&xc-y<240&&yc-x>0&&yc-x<200) if (difx[xc-y+(yc-x)*240]>15&&dispic[xc-y+(yc-x)*240]<col) dispic[xc-y+(yc-x)*240]=col;
  525.   p=1-r;
  526.   while (x<y) {
  527.     if (p<0) x=x+1; else {x=x+1; y=y-1;}
  528.     if (p<0) p=p+2*x+1; else p=p+2*(x-y)+1;
  529.     if (xc+x>0&&xc+x<240&&yc+y>0&&yc+y<200) if (difx[xc+x+(yc+y)*240]>15&&dispic[xc+x+(yc+y)*240]<col) dispic[xc+x+(yc+y)*240]=col;
  530.     if (xc-x>0&&xc-x<240&&yc+y>0&&yc+y<200) if (difx[xc-x+(yc+y)*240]>15&&dispic[xc-x+(yc+y)*240]<col) dispic[xc-x+(yc+y)*240]=col;
  531.     if (xc+x>0&&xc+x<240&&yc-y>0&&yc-y<200) if (difx[xc+x+(yc-y)*240]>15&&dispic[xc+x+(yc-y)*240]<col) dispic[xc+x+(yc-y)*240]=col;
  532.     if (xc-x>0&&xc-x<240&&yc-y>0&&yc-y<200) if (difx[xc-x+(yc-y)*240]>15&&dispic[xc-x+(yc-y)*240]<col) dispic[xc-x+(yc-y)*240]=col;
  533.     if (xc+y>0&&xc+y<240&&yc+x>0&&yc+x<200) if (difx[xc+y+(yc+x)*240]>15&&dispic[xc+y+(yc+x)*240]<col) dispic[xc+y+(yc+x)*240]=col;
  534.     if (xc-y>0&&xc-y<240&&yc+x>0&&yc+x<200) if (difx[xc-y+(yc+x)*240]>15&&dispic[xc-y+(yc+x)*240]<col) dispic[xc-y+(yc+x)*240]=col;
  535.     if (xc+y>0&&xc+y<240&&yc-x>0&&yc-x<200) if (difx[xc+y+(yc-x)*240]>15&&dispic[xc+y+(yc-x)*240]<col) dispic[xc+y+(yc-x)*240]=col;
  536.     if (xc-y>0&&xc-y<240&&yc-x>0&&yc-x<200) if (difx[xc-y+(yc-x)*240]>15&&dispic[xc-y+(yc-x)*240]<col) dispic[xc-y+(yc-x)*240]=col;
  537.   }
  538. }
  539.  
  540. void Shade_poly3(POLY3_2 pnt,int c0,int c1,int c2) {
  541. //═══ shade poly with Z-Buffer
  542.  
  543.   int i,i1,miny,maxy;
  544.   int ys,ye;     // y start,end
  545.   int xl,yl;     // x,y length
  546.   int xp,yp;     // x,y position
  547.   int xadd,yadd; // x,y adders
  548.   int xcnt;      // x position counter
  549.   int cadd,zadd;
  550.   int ccnt,zcnt;
  551.   int a1,a2;
  552.   int ysort[] = new int[3];
  553.   int order;
  554.   int map = 0;
  555.   
  556.   // calc point order in y axis
  557.   ysort[2] = 2;
  558.   if(pnt.y[0]<pnt.y[1]) {
  559.     ysort[0] = 0; ysort[1] = 1;
  560.   } else {
  561.     ysort[0] = 1; ysort[1] = 0;
  562.   }
  563.   if(pnt.y[ysort[1]]>pnt.y[ysort[2]]) {
  564.     i = ysort[2];  // swap ysort[x] and ysort[y]
  565.     ysort[2] = ysort[1];
  566.     ysort[1] = i;
  567.   };
  568.   if(pnt.y[ysort[0]]>pnt.y[ysort[1]]) {
  569.     i = ysort[0];   // swap ysort[x] and ysort[y]
  570.     ysort[0] = ysort[1];
  571.     ysort[1] = i;
  572.   };
  573.  
  574.   // y start,end setzen
  575.   ys = pnt.y[ysort[0]];
  576.   ye = pnt.y[ysort[2]];
  577.  
  578.   // winkel berechnen:  a1 zu y-achse, a2 zu y-achse
  579.   a1 = ((pnt.x[ysort[1]]-pnt.x[ysort[0]]) << 16)/((pnt.y[ysort[1]]-pnt.y[ysort[0]])+1);
  580.   a2 = ((pnt.x[ysort[2]]-pnt.x[ysort[0]]) << 16)/((pnt.y[ysort[2]]-pnt.y[ysort[0]])+1);
  581.  
  582.   // Sortierfolge abbilden
  583.   order = ysort[0] * 3 + ysort[2];
  584.  
  585.   // map bilden, bit 0 -> start punkte 1 -> end punkte
  586.   switch(order) {
  587.     // p0,p2,p1: a2<=a1 -> 110
  588.     case 1: map = 6; break;
  589.     // p0,p1,p2: a2<=a1 -> 011
  590.     case 2: map = 3; break;
  591.     // p1,p2,p0: a2<=a1 -> 110
  592.     case 3: map = 6; break;
  593.     // p1,p0,p2: a2<=a1 -> 101
  594.     case 5: map = 5; break;
  595.     // p2,p1,p0: a2<=a1 -> 011
  596.     case 6: map = 3; break;
  597.     // p2,p0,p1: a2<=a1 -> 101
  598.     case 7: map = 5; break;
  599.   }
  600.   if(a2>a1) map ^= 0xff;  // angle a2>a1 -> turn map
  601.  
  602.   //───  run from x0,y0 to x1,y1
  603.   xl = pnt.x[1] - pnt.x[0];
  604.   yl = Math.abs(pnt.y[1] - pnt.y[0]);
  605.   if((map & 0x01) == 0) {
  606.   // poly_hullxs; else poly_hull = poly_hullxe;
  607.     yp = pnt.y[0];
  608.     poly_hullxs[yp].x = pnt.x[0];
  609.     ccnt = (c0 << 8);
  610.     poly_hullxs[yp].mapx = ccnt;
  611.     if(yl>0) {
  612.       xadd = (xl << 8) / yl;
  613.       if(pnt.y[1]>pnt.y[0]) yadd = 1; else yadd = -1;
  614.       xcnt = pnt.x[0] << 8;
  615.       cadd = ((c1 - c0) << 8) / yl;
  616.       while(yp != pnt.y[1]) {
  617.         yp += yadd;
  618.         xcnt += xadd;
  619.         poly_hullxs[yp].x = xcnt / 256;
  620.         ccnt += cadd;
  621.         poly_hullxs[yp].mapx = ccnt;
  622.       }
  623.     }
  624.   } else {
  625.     yp = pnt.y[0];
  626.     poly_hullxe[yp].x = pnt.x[0];
  627.     ccnt = (c0 << 8);
  628.     poly_hullxe[yp].mapx = ccnt;
  629.     if(yl>0) {
  630.       xadd = (xl << 8) / yl;
  631.       if(pnt.y[1]>pnt.y[0]) yadd = 1; else yadd = -1;
  632.       xcnt = pnt.x[0] << 8;
  633.       cadd = ((c1 - c0) << 8) / yl;
  634.       while(yp != pnt.y[1]) {
  635.         yp += yadd;
  636.         xcnt += xadd;
  637.         poly_hullxe[yp].x = xcnt / 256;
  638.         ccnt += cadd;
  639.         poly_hullxe[yp].mapx = ccnt;
  640.       }
  641.     }
  642.   }
  643.   //───  run from x1,y1 to x2,y2
  644.   xl = pnt.x[2] - pnt.x[1];
  645.   yl = Math.abs(pnt.y[2] - pnt.y[1]);
  646.   if((map & 0x02) == 0) {
  647.     //poly_hull = poly_hullxs; else poly_hull = poly_hullxe;
  648.     yp = pnt.y[1];
  649.     poly_hullxs[yp].x = pnt.x[1];
  650.     ccnt = (c1 << 8);
  651.     poly_hullxs[yp].mapx = ccnt;
  652.     if(yl>0) {
  653.       xadd = (xl << 8) / yl;
  654.       if(pnt.y[2]>pnt.y[1]) yadd = 1; else yadd = -1; // y direction
  655.       xcnt = pnt.x[1] << 8;
  656.       cadd = ((c2 - c1) << 8) / yl;
  657.       while(yp != pnt.y[2]) {
  658.         yp += yadd;
  659.         xcnt += xadd;
  660.         poly_hullxs[yp].x = xcnt / 256;
  661.         ccnt += cadd;
  662.         poly_hullxs[yp].mapx = ccnt;
  663.       }
  664.     }
  665.   } else {
  666.     yp = pnt.y[1];
  667.     poly_hullxe[yp].x = pnt.x[1];
  668.     ccnt = (c1 << 8);
  669.     poly_hullxe[yp].mapx = ccnt;
  670.     if(yl>0) {
  671.       xadd = (xl << 8) / yl;
  672.       if(pnt.y[2]>pnt.y[1]) yadd = 1; else yadd = -1; // y direction
  673.       xcnt = pnt.x[1] << 8;
  674.       cadd = ((c2 - c1) << 8) / yl;
  675.       while(yp != pnt.y[2]) {
  676.         yp += yadd;
  677.         xcnt += xadd;
  678.         poly_hullxe[yp].x = xcnt / 256;
  679.         ccnt += cadd;
  680.         poly_hullxe[yp].mapx = ccnt;
  681.       }
  682.     }
  683.   }
  684.   //───  run from x2,y2 to x0,y0
  685.   xl = pnt.x[0] - pnt.x[2];
  686.   yl = Math.abs(pnt.y[0] - pnt.y[2]);
  687.   if((map & 0x04) == 0) {
  688.     //poly_hull = poly_hullxs; else poly_hull = poly_hullxe;
  689.     yp = pnt.y[2];
  690.     poly_hullxs[yp].x = pnt.x[2];
  691.     ccnt = (c2 << 8);
  692.     poly_hullxs[yp].mapx = ccnt;
  693.     if(yl>0) {
  694.       xadd = (xl << 8) / yl;
  695.       if(pnt.y[0]>pnt.y[2]) yadd = 1; else yadd = -1;
  696.       xcnt = pnt.x[2] << 8;
  697.       cadd = ((c0 - c2) << 8) / yl;
  698.       while(yp != pnt.y[0]) {
  699.         yp += yadd;
  700.         xcnt += xadd;
  701.         poly_hullxs[yp].x = xcnt / 256;
  702.         ccnt += cadd;
  703.         poly_hullxs[yp].mapx = ccnt;
  704.       }
  705.     }
  706.    } else {
  707.     yp = pnt.y[2];
  708.     poly_hullxe[yp].x = pnt.x[2];
  709.     ccnt = (c2 << 8);
  710.     poly_hullxe[yp].mapx = ccnt;
  711.     if(yl>0) {
  712.       xadd = (xl << 8) / yl;
  713.       if(pnt.y[0]>pnt.y[2]) yadd = 1; else yadd = -1;
  714.       xcnt = pnt.x[2] << 8;
  715.       cadd = ((c0 - c2) << 8) / yl;
  716.       while(yp != pnt.y[0]) {
  717.         yp += yadd;
  718.         xcnt += xadd;
  719.         poly_hullxe[yp].x = xcnt / 256;
  720.         ccnt += cadd;
  721.         poly_hullxe[yp].mapx = ccnt;
  722.       }
  723.     }
  724.   }
  725.   // draw
  726.   for(i=ys; i<=ye; i++) {
  727.     int ypos=i*picxsize;
  728.     ccnt = (poly_hullxs[i].mapx + 127) << 8;
  729.     xl = poly_hullxe[i].x - poly_hullxs[i].x;
  730.     if(xl>0) {
  731.       cadd = ((poly_hullxe[i].mapx - poly_hullxs[i].mapx) << 8)/ xl;
  732.     } else {cadd = 0; zadd=0; }
  733.     for(i1=poly_hullxs[i].x; i1<=poly_hullxe[i].x; i1++) {
  734.       if (i1>0&&i1<picxsize&&i>0&&i<picysize)
  735.         red[i1+ypos]=(ccnt >> 16);
  736.       ccnt += cadd;
  737.     }
  738.   }
  739. }
  740.  
  741. void sort(int l,int r)
  742. {int i,j,x,y,tst,z;
  743.   i=l; j=r; tst=((l+r) >> 1);
  744.   x=indx[tst].z;
  745.   while (i<j) {
  746.     while (indx[i].z<x) i++;
  747.     while (x<indx[j].z) j--;
  748.     if (i<=j) {
  749.       y=indx[i].z; indx[i].z=indx[j].z; indx[j].z=y;
  750.       y=indx[i].nr; indx[i].nr=indx[j].nr; indx[j].nr=y;
  751.       i++; j--;
  752.      }
  753.   }
  754.   if (l<j) sort(l,j);
  755.   if (i<r) sort(i,r);
  756. }
  757.  
  758. void quicksort(int lo, int hi)
  759. {
  760.   sort(lo,hi);
  761. }
  762.  
  763. void Shade_tria3d(face Face, int clr)
  764. {  int Xp[] = new int[3],Yp[] = new int[3];
  765.    POLY3_2 p1 = new POLY3_2();
  766.    int tst=((camerax-px[Face.p])*100); int tst1=pz[Face.p]-100;
  767.    int tst2=((cameray-py[Face.p])*100);
  768.    int tst3=((camerax-px[Face.p1])*100); int tst4=pz[Face.p1]-100;
  769.    int tst5=((cameray-py[Face.p1])*100);
  770.    int tst6=((camerax-px[Face.p2])*100); int tst7=pz[Face.p2]-100;
  771.    int tst8=((cameray-py[Face.p2])*100);
  772.    Xp[0] = 100+(int)tst/tst1;
  773.    Yp[0] = 84+(int)tst2/tst1;
  774.    Xp[1] = 100+(int)tst3/tst4;
  775.    Yp[1] = 84+(int)tst5/tst4;
  776.    Xp[2] = 100+(int)tst6/tst7;
  777.    Yp[2] = 84+(int)tst8/tst7;
  778.    p1.x[0]=Xp[0];
  779.    p1.y[0]=Yp[0];
  780.    p1.x[1]=Xp[1];
  781.    p1.y[1]=Yp[1];
  782.    p1.x[2]=Xp[2];
  783.    p1.y[2]=Yp[2];
  784.    Shade_poly3(p1,Face.clr,Face.clr1,Face.clr2);
  785. }
  786.  
  787. void Texture_tria3d(face Face)
  788. {  int Xp[] = new int[3],Yp[] = new int[3];
  789.    POLY3_2 p1 = new POLY3_2();
  790.    int tst=((camerax-px[Face.p])*100); int tst1=pz[Face.p]-100;
  791.    int tst2=((cameray-py[Face.p])*100);
  792.    int tst3=((camerax-px[Face.p1])*100); int tst4=pz[Face.p1]-100;
  793.    int tst5=((cameray-py[Face.p1])*100);
  794.    int tst6=((camerax-px[Face.p2])*100); int tst7=pz[Face.p2]-100;
  795.    int tst8=((cameray-py[Face.p2])*100);
  796.    Xp[0] = 100+(int)tst/tst1;
  797.    Yp[0] = 84+(int)tst2/tst1;
  798.    Xp[1] = 100+(int)tst3/tst4;
  799.    Yp[1] = 84+(int)tst5/tst4;
  800.    Xp[2] = 100+(int)tst6/tst7;
  801.    Yp[2] = 84+(int)tst8/tst7;
  802.    p1.x[0]=Xp[0];
  803.    p1.y[0]=Yp[0];
  804.    p1.x[1]=Xp[1];
  805.    p1.y[1]=Yp[1];
  806.    p1.x[2]=Xp[2];
  807.    p1.y[2]=Yp[2];
  808.    Texture_poly3(p1,Face.nx,Face.ny,Face.nx1,Face.ny1,Face.nx2,Face.ny2);
  809. }
  810.  
  811. public void X_line(int x1,int y1,int x2, int y2,int clr)
  812. {int x,y,dx,dy,ince,incne,d,cx,cy,fsh;
  813.  dx=x2-x1;
  814.  dy=y2-y1;
  815.  if (dx<0) dx=dx*-1; if (dy<=0) dy=dy*-1;
  816.  if (dx>dy) d=dy*2-dx; else d=dx*2-dy;
  817.  if (dx>dy) ince=dy*2; else ince=dx*2;
  818.  x=x1; y=y1;
  819.  incne=(dy-dx)*2;
  820.  if (dx>=dy) {
  821.     if (x1<x2) while (x<x2) {
  822.       if (d<=0) {d=d+ince; x++; } else {d=d+incne; x++; if (y1<y2) y++; else y--;}
  823.         if (x>=0&&x<picxsize&&y>=0&&y<picysize) dispic[x+y*picxsize]+=clr;
  824.        }
  825.     if (x1>x2) while (x>x2) {
  826.      if (d<=0) {d=d+ince; x--; } else {d=d+incne; x--; if (y1<y2) y++; else y--;}
  827.         if (x>=0&&x<picxsize&&y>=0&&y<picysize) dispic[x+y*picxsize]+=clr;
  828.     }
  829.  }
  830.  if (dy>dx) {
  831.     if (y<y2) while (y<y2) {
  832.       if (d<=0) {d=d+ince; y++;} else {d=d-incne; y++; if(x1>x2) x--; else x++;}
  833.         if (x>=0&&x<picxsize&&y>=0&&y<picysize) dispic[x+y*picxsize]+=clr;
  834.      }
  835.      if (y>y2) while (y>y2) {
  836.       if (d<=0) {d=d+ince; y--;} else {d=d-incne; y--; if(x1>x2) x--; else x++;}
  837.         if (x>=0&&x<picxsize&&y>=0&&y<picysize) dispic[x+y*picxsize]+=clr;
  838.      }
  839.   }
  840. }
  841.  
  842. public void line(int x1,int y1,int x2, int y2,int clr)
  843. {int x,y,dx,dy,ince,incne,d,cx,cy,fsh;
  844.  dx=x2-x1;
  845.  dy=y2-y1;
  846.  if (dx<0) dx=dx*-1; if (dy<=0) dy=dy*-1;
  847.  if (dx>dy) d=dy*2-dx; else d=dx*2-dy;
  848.  if (dx>dy) ince=dy*2; else ince=dx*2;
  849.  x=x1; y=y1;
  850.  incne=(dy-dx)*2;
  851.  if (dx>=dy) {
  852.     if (x1<x2) while (x<x2) {
  853.       if (d<=0) {d=d+ince; x++; } else {d=d+incne; x++; if (y1<y2) y++; else y--;}
  854.         if (x>=0&&x<picxsize&&y>=0&&y<picysize) { red[x+y*picxsize]=clr; }
  855.        }
  856.     if (x1>x2) while (x>x2) {
  857.      if (d<=0) {d=d+ince; x--; } else {d=d+incne; x--; if (y1<y2) y++; else y--;}
  858.        if (x>=0&&x<picxsize&&y>=0&&y<picysize) { red[x+y*picxsize]=clr; }
  859.     }
  860.  }
  861.  if (dy>dx) {
  862.     if (y<y2) while (y<y2) {
  863.       if (d<=0) {d=d+ince; y++;} else {d=d-incne; y++; if(x1>x2) x--; else x++;}
  864.         if (x>=0&&x<picxsize&&y>=0&&y<picysize) { red[x+y*picxsize]=clr; }
  865.      }
  866.      if (y>y2) while (y>y2) {
  867.       if (d<=0) {d=d+ince; y--;} else {d=d-incne; y--; if(x1>x2) x--; else x++;}
  868.         if (x>=0&&x<picxsize&&y>=0&&y<picysize) { red[x+y*picxsize]=clr; }
  869.      }
  870.   }
  871. }
  872.  
  873. public void LensCircle (int xc,int yc,int r,int col)
  874. {int x,y,p;
  875.   x=0; y=r;
  876.   if (xc+x>0&&xc+x<200&&yc+y>0&&yc+y<167) red[xc+x+(yc+y)*200]=col;
  877.   if (xc-x>0&&xc-x<200&&yc+y>0&&yc+y<167) red[xc-x+(yc+y)*200]=col;
  878.   if (xc+x>0&&xc+x<200&&yc-y>0&&yc-y<167) red[xc+x+(yc-y)*200]=col;
  879.   if (xc-x>0&&xc-x<200&&yc-y>0&&yc-y<167) red[xc-x+(yc-y)*200]=col;
  880.   if (xc+y>0&&xc+y<200&&yc+x>0&&yc+x<167) red[xc+y+(yc+x)*200]=col;
  881.   if (xc-y>0&&xc-y<200&&yc+x>0&&yc+x<167) red[xc-y+(yc+x)*200]=col;
  882.   if (xc+y>0&&xc+y<200&&yc-x>0&&yc-x<167) red[xc+y+(yc-x)*200]=col;
  883.   if (xc-y>0&&xc-y<200&&yc-x>0&&yc-x<167) red[xc-y+(yc-x)*200]=col;
  884.   p=1-r;
  885.   while (x<y) {
  886.     if (p<0) x=x+1; else {x=x+1; y=y-1;}
  887.     if (p<0) p=p+2*x+1; else p=p+2*(x-y)+1;
  888.     if (xc+x>0&&xc+x<200&&yc+y>0&&yc+y<167) red[xc+x+(yc+y)*200]=col;
  889.     if (xc-x>0&&xc-x<200&&yc+y>0&&yc+y<167) red[xc-x+(yc+y)*200]=col;
  890.     if (xc+x>0&&xc+x<200&&yc-y>0&&yc-y<167) red[xc+x+(yc-y)*200]=col;
  891.     if (xc-x>0&&xc-x<200&&yc-y>0&&yc-y<167) red[xc-x+(yc-y)*200]=col;
  892.     if (xc+y>0&&xc+y<200&&yc+x>0&&yc+x<167) red[xc+y+(yc+x)*200]=col;
  893.     if (xc-y>0&&xc-y<200&&yc+x>0&&yc+x<167) red[xc-y+(yc+x)*200]=col;
  894.     if (xc+y>0&&xc+y<200&&yc-x>0&&yc-x<167) red[xc+y+(yc-x)*200]=col;
  895.     if (xc-y>0&&xc-y<200&&yc-x>0&&yc-x<167) red[xc-y+(yc-x)*200]=col;
  896.   }
  897. }
  898.  
  899. void Line3d (int x1, int y1, int z1, int x2, int y2, int z2)
  900. { int Xp[] = new int[2],Yp[] = new int[2];
  901.   int tst,tst1,tst2,tst3,tst4,tst5;
  902.    tst=((camerax-x1)*100); tst1=z1-100;
  903.    tst2=((cameray-y1)*100);
  904.    tst3=((camerax-x2)*100); tst4=z2-100;
  905.    tst5=((cameray-y2)*100);
  906.    if (z1<100&&z2<100) {
  907.      Xp[0] = 100+(int)tst/tst1;
  908.      Yp[0] = 83+(int)tst2/tst1;
  909.      Xp[1] = 100+(int)tst3/tst4;
  910.      Yp[1] = 83+(int)tst5/tst4;
  911.      line(Xp[0],Yp[0],Xp[1],Yp[1],192);
  912.    }
  913. }
  914.  
  915. void Lens3d(int x, int y, int z ,int clr) {
  916.    int tst=((camerax-x)*100); int tst1=z-100;
  917.    int tst2=((cameray-y)*100);
  918.    int xp = 100+(int)tst/tst1;
  919.    int yp = 83+(int)tst2/tst1;
  920.    int r = 4+(z >> 3);
  921.    for (int i=0; i<r; i++) {
  922.      int color=clr-(i << 3);
  923.      LensCircle(xp,yp,i,Math.abs(color));
  924.      LensCircle(xp+1,yp,i,Math.abs(color));
  925.    }
  926. }
  927.  
  928.  
  929.   void Set3dPixel2 (int x1, int y1, int z1,int clr) {
  930.     int Xp[] = new int[1],Yp[] = new int[1];
  931.     int tst,tst1,tst2;
  932.     if (z1<cameraz) {
  933.       tst=((camerax-x1)*cameraz); tst1=z1-cameraz;
  934.       tst2=((cameray-y1)*cameraz);
  935.       Xp[0] = 100+(int)tst/tst1;
  936.       Yp[0] = 84+(int)tst2/tst1;
  937.       for (int i=0; i<3; i++) { LensCircle(Xp[0],Yp[0],i,clr-(i << 4)); LensCircle(Xp[0]+1,Yp[0],i,clr-(i << 4)); }
  938.     }
  939.  }
  940.  
  941. void Tria3d(face Face, int clr)
  942. {  int Xp[] = new int[3],Yp[] = new int[3];
  943.    int tst=((camerax-px[Face.p])*100); int tst1=pz[Face.p]-100;
  944.    int tst2=((cameray-py[Face.p])*100);
  945.    int tst3=((camerax-px[Face.p1])*100); int tst4=pz[Face.p1]-100;
  946.    int tst5=((cameray-py[Face.p1])*100);
  947.    int tst6=((camerax-px[Face.p2])*100); int tst7=pz[Face.p2]-100;
  948.    int tst8=((cameray-py[Face.p2])*100);
  949.    Xp[0] = 100+(int)tst/tst1;
  950.    Yp[0] = 83+(int)tst2/tst1;
  951.    Xp[1] = 100+(int)tst3/tst4;
  952.    Yp[1] = 83+(int)tst5/tst4;
  953.    Xp[2] = 100+(int)tst6/tst7;
  954.    Yp[2] = 83+(int)tst8/tst7;
  955.    line(Xp[0],Yp[0],Xp[1],Yp[1],clr);
  956.    line(Xp[1],Yp[1],Xp[2],Yp[2],clr);
  957.    line(Xp[2],Yp[2],Xp[0],Yp[0],clr);
  958. }
  959.  
  960. public void ClearCircle (int xc,int yc,int r,int col)
  961. {int x,y,p;
  962.   x=0; y=r;
  963.   if (xc+x>0&&xc+x<240&&yc+y>0&&yc+y<200) green[xc+x+(yc+y)*240]+=col;
  964.   if (xc-x>0&&xc-x<240&&yc+y>0&&yc+y<200) green[xc-x+(yc+y)*240]+=col;
  965.   if (xc+x>0&&xc+x<240&&yc-y>0&&yc-y<200) green[xc+x+(yc-y)*240]+=col;
  966.   if (xc-x>0&&xc-x<240&&yc-y>0&&yc-y<200) green[xc-x+(yc-y)*240]+=col;
  967.   if (xc+y>0&&xc+y<240&&yc+x>0&&yc+x<200) green[xc+y+(yc+x)*240]+=col;
  968.   if (xc-y>0&&xc-y<240&&yc+x>0&&yc+x<200) green[xc-y+(yc+x)*240]+=col;
  969.   if (xc+y>0&&xc+y<240&&yc-x>0&&yc-x<200) green[xc+y+(yc-x)*240]+=col;
  970.   if (xc-y>0&&xc-y<240&&yc-x>0&&yc-x<200) green[xc-y+(yc-x)*240]+=col;
  971.   p=1-r;
  972.   while (x<y) {
  973.     if (p<0) x=x+1; else {x=x+1; y=y-1;}
  974.     if (p<0) p=p+2*x+1; else p=p+2*(x-y)+1;
  975.     if (xc+x>0&&xc+x<240&&yc+y>0&&yc+y<200) green[xc+x+(yc+y)*240]+=col;
  976.     if (xc-x>0&&xc-x<240&&yc+y>0&&yc+y<200) green[xc-x+(yc+y)*240]+=col;
  977.     if (xc+x>0&&xc+x<240&&yc-y>0&&yc-y<200) green[xc+x+(yc-y)*240]+=col;
  978.     if (xc-x>0&&xc-x<240&&yc-y>0&&yc-y<200) green[xc-x+(yc-y)*240]+=col;
  979.     if (xc+y>0&&xc+y<240&&yc+x>0&&yc+x<200) green[xc+y+(yc+x)*240]+=col;
  980.     if (xc-y>0&&xc-y<240&&yc+x>0&&yc+x<200) green[xc-y+(yc+x)*240]+=col;
  981.     if (xc+y>0&&xc+y<240&&yc-x>0&&yc-x<200) green[xc+y+(yc-x)*240]+=col;
  982.     if (xc-y>0&&xc-y<240&&yc-x>0&&yc-x<200) green[xc-y+(yc-x)*240]+=col;
  983.   }
  984. }
  985.  
  986.   public void init() {
  987.     for (i=0; i<256; i++) SinTab[i]=(int)(Math.sin(2*i*Math.PI/255)*128);
  988.     for (i=0; i<256; i++) CosTab[i]=(int)(Math.cos(2*i*Math.PI/255)*128);
  989.     music = getAudioClip(getCodeBase(),"data/music.au");
  990.     setBackground(c);
  991.     int fps = 30;
  992.     int index = 0;
  993.     offGraphics= null;
  994.     delay = (fps >0) ? (1000 / fps) : 100;
  995.     s=getParameter("Variante");
  996.     int clouds[] = new int[256*256];
  997.     clouds=CalcMarble(4,6);
  998.     for (int y=0; y<128; y++)
  999.        for (int x=0; x<128; x++) cloud[x+(y << 7)]=clouds[(x << 1)+((y << 1) << 8)];
  1000.     clouds=CalcMarble(4,8);
  1001.     for (int y=0; y<128; y++)
  1002.        for (int x=0; x<128; x++) cloud1[x+(y << 7)]=clouds[(x << 1)+((y << 1) << 8)];
  1003.     getAppletContext().showStatus("Applet from OtakInc loaded pure REALTIME!");
  1004.     Img = getImage(getCodeBase(),"data/logo.gif");
  1005.     grab = new PixelGrabber(Img,0,0,240,200,pix1,0,240);
  1006.     try {
  1007.       grab.grabPixels();
  1008.      } catch (InterruptedException e) {};
  1009.     for (int i1=0; i1<200; i1++)
  1010.       for (int i=0; i<240; i++) {
  1011.         red[i+i1*240]=(int)((pix1[i+i1*240] >> 16) & 0xff);
  1012.         green[i+i1*240]=(int)((pix1[i+i1*240] >> 8) & 0xff);
  1013.         blue[i+i1*240]=(int)(pix1[i+i1*240] & 0xff);
  1014.         difx[i+i1*240]=(int)(red[i+i1*240]+green[i+i1*240]+blue[i+i1*240])/3;
  1015.         dispic[i+i1*240]=0;
  1016.     }
  1017.     for (i=0; i<360; i++) { Stab[i]=Math.sin(Math.PI*i/180); Ctab[i]=Math.cos(Math.PI*i/180); }
  1018.     for (i=0; i<5; i++) scnt[i]=(int)(Math.random()*360);
  1019.     for (i=0; i<3000; i++) noise[i]=(int)(Math.random()*16);
  1020.     source = new MemoryImageSource(240,200,pix,0,240);
  1021.     Img = createImage(source);
  1022.     for (int i=0; i<520; i++)  facelist[i] = new face();
  1023.     for (int i=0; i<3000; i++) {
  1024.       poly_hullxs[i] = new PL();
  1025.       poly_hullxe[i] = new PL();
  1026.     }
  1027.     for (int i=0; i<520; i++) indx[i] = new idx();
  1028.     boolean CORDS = true;
  1029.     cnt=cnt1=0;
  1030.     try {
  1031.       URL url = new URL(getCodeBase(), "data/scene1.3D");
  1032.       DataInputStream in = new DataInputStream((InputStream) url.getContent());
  1033.       try {
  1034.           String X="a";
  1035.           while (X!=null) {
  1036.             X = in.readLine();
  1037.             if (X==null||X.regionMatches(false,0,"FACES",0,4))
  1038.              { CORDS=false;
  1039.                 if (X!=null) X = in.readLine();
  1040.              }
  1041.             if (X!=null&&CORDS==false&&X.compareTo("VERTEX")==0) {
  1042.                CORDS=true;
  1043.                X = in.readLine();
  1044.             }
  1045.             if (CORDS==true) {
  1046.               String Y = in.readLine();
  1047.               String Z = in.readLine();
  1048.               Float cx = Float.valueOf(X);
  1049.               Float cy = Float.valueOf(Y);
  1050.               Float cz = Float.valueOf(Z);
  1051.               double x = cx.doubleValue();
  1052.               double y = cy.doubleValue();
  1053.               double z = cz.doubleValue();
  1054.               pointx[cnt]=(int)(x*25);
  1055.               pointy[cnt]=(int)(y*25);
  1056.               pointz[cnt]=(int)(z*25);
  1057.               pointz2[cnt]=pointz[cnt];
  1058.               cnt++;
  1059.             }
  1060.             if (CORDS==false&&X!=null) {
  1061.               String p1 = in.readLine();
  1062.               String p2 = in.readLine();
  1063.               Float cp = Float.valueOf(X);
  1064.               int fp = (int)cp.doubleValue();
  1065.               cp = Float.valueOf(p1);
  1066.               int fp1 = (int)cp.doubleValue();
  1067.               cp = Float.valueOf(p2);
  1068.               int fp2 = (int)cp.doubleValue();
  1069.               facelist[cnt1].p=fp;
  1070.               facelist[cnt1].p1=fp1;
  1071.               facelist[cnt1].p2=fp2;
  1072.               facelist[cnt1].nr=cnt1;
  1073.               cnt1++;
  1074.             }
  1075.           }
  1076.       } catch (EOFException e) {}
  1077.       in.close();
  1078.     } catch (IOException e) { getAppletContext().showStatus("FILE-ERROR"); }
  1079.     for (int i=cnt; i<cnt+10; i++) {
  1080.       pointx[i]=30;
  1081.       pointy[i]=30;
  1082.       pointz[i]=20;
  1083.       scnt[i-cnt]=i*36;
  1084.     }
  1085.     maxverts=cnt;
  1086.     maxface=cnt1;
  1087.     cnt=cnt1=0;
  1088.     Font myFont=new Font("TimesRoman", Font.BOLD, 24);
  1089.     FontMetrics myMetrix=getFontMetrics(myFont);
  1090.     setFont(myFont);
  1091.     sxpos[0]=80; sypos[0]=0;
  1092.     sxpos[1]=60; sypos[1]=0;
  1093.     partnr=timer=0;
  1094. //    partnr=9;
  1095.     music.loop();
  1096.   }
  1097.  
  1098.   public void start() {
  1099.   if (killme== null)
  1100.    {
  1101.      killme = new Thread(this);
  1102.      killme.start();
  1103.     }
  1104.   }
  1105.  
  1106.  
  1107.   public void LoadOp_2() {
  1108.     Img = getImage(getCodeBase(),"data/pic1.jpg");
  1109.     tracer.addImage(Img,0);
  1110.     try {
  1111.       tracer.waitForAll();
  1112.     } catch (InterruptedException e) {}
  1113.     grab = new PixelGrabber(Img,0,0,240,100,pix1,0,240);
  1114.     try {
  1115.       grab.grabPixels();
  1116.      } catch (InterruptedException e) {};
  1117.     for (int y=0; y<picysize; y++)
  1118.       for (int x=0; x<picxsize; x++) {
  1119.         blue[x+y*picxsize]=pix1[x+y*picxsize]&0xff;
  1120.         red[x+y*picxsize]=(pix1[x+y*picxsize] >> 16)&0xff;
  1121.         green[x+y*picxsize]=(pix1[x+y*picxsize] >> 8)&0xff;
  1122.     }
  1123.     source = new MemoryImageSource(picxsize,100,pix,0,picxsize);
  1124.     Img = createImage(source);
  1125.     xadd=(double)picxsize/100;
  1126.     xval=8*xadd; yval=0.0f; cnt=0; cnt1=8;
  1127.     timer=0; partnr=2;
  1128.   }
  1129.  
  1130.   public void LoadOp_3() {
  1131.     Img = getImage(getCodeBase(),"data/pic2.jpg");
  1132.     tracer.addImage(Img,0);
  1133.     try {
  1134.       tracer.waitForAll();
  1135.     } catch (InterruptedException e) {}
  1136.     grab = new PixelGrabber(Img,0,0,240,200,pix1,0,240);
  1137.     try {
  1138.       grab.grabPixels();
  1139.      } catch (InterruptedException e) {};
  1140.     picysize=200;
  1141.     for (int y=0; y<picysize; y++)
  1142.       for (int x=0; x<picxsize; x++) {
  1143.         blue[x+y*picxsize]=pix1[x+y*picxsize]&0xff;
  1144.         red[x+y*picxsize]=(pix1[x+y*picxsize] >> 16)&0xff;
  1145.         green[x+y*picxsize]=(pix1[x+y*picxsize] >> 8)&0xff;
  1146.         difx[x+y*picxsize]=(int)(blue[x+y*picxsize]+green[x+y*picxsize]+red[x+y*picxsize])/3;
  1147.     }
  1148.     source = new MemoryImageSource(picxsize,200,pix,0,picxsize);
  1149.     Img = createImage(source);
  1150.     cnt1=255; partnr=4; timer=0; cnt2=0;
  1151.   }
  1152.  
  1153.  
  1154.   public void Load_Op4() {
  1155.     Img = getImage(getCodeBase(),"data/pic4.jpg");
  1156.     grab = new PixelGrabber(Img,0,0,240,200,pix1,0,240);
  1157.     try {
  1158.       grab.grabPixels();
  1159.      } catch (InterruptedException e) {};
  1160.     for (int i1=0; i1<200; i1++)
  1161.       for (int i=0; i<125; i++) {
  1162.         red[i+i1*125]=pix1[i+50+i1*240];
  1163.     }
  1164.     Img = getImage(getCodeBase(),"data/pic5.jpg");
  1165.     grab = new PixelGrabber(Img,0,0,240,200,pix1,0,240);
  1166.     try {
  1167.       grab.grabPixels();
  1168.      } catch (InterruptedException e) {};
  1169.     for (int i1=0; i1<200; i1++)
  1170.       for (int i=0; i<125; i++) {
  1171.         green[i+i1*125]=pix1[i+50+i1*240];
  1172.     }
  1173.     Img = getImage(getCodeBase(),"data/pic3.jpg");
  1174.     grab = new PixelGrabber(Img,0,0,240,200,pix1,0,240);
  1175.     try {
  1176.       grab.grabPixels();
  1177.      } catch (InterruptedException e) {};
  1178.     for (int i1=0; i1<200; i1++)
  1179.       for (int i=0; i<125; i++) {
  1180.         pix[i+i1*125]=pix1[i+50+i1*240];
  1181.     }
  1182.     cnt=0;
  1183.     source = new MemoryImageSource(125,200,pix,0,125);
  1184.     Img1 = createImage(source);
  1185.     pos1[0]=false;
  1186.     pos1[1]=false;
  1187.     pos1[2]=false;
  1188.     cnt=cnt1=cnt2=timer=0;
  1189.     partnr=6;
  1190.   }
  1191.  
  1192.   public void Load_Part1() {
  1193.     source = new MemoryImageSource(240,200,pix,0,240);
  1194.     Img = createImage(source);
  1195.     for (y=-100; y<100; y++)
  1196.       for (x=-120; x<120; x++) {
  1197.          tstval=Math.atan((double)y/(double)x);
  1198.           red[(x+120)+(y+100)*240]=0;
  1199.           green[(x+120)+(y+100)*240]=0;
  1200.           difx[(x+120)+(y+100)*240]=(int)((Math.sin(tstval)+Math.cos(tstval)*32.0f*64.0f)/(double)x);
  1201.           dispic[(x+120)+(y+100)*240]=(int)(tstval*180/(360/255)/Math.PI);
  1202.       }
  1203.     cnt=cnt1=cnt2=timer=0; partnr=8;
  1204.     text[0]="Oh no not again!";
  1205.     text[1]="Yes thats better";
  1206.     sxpos[0]=260;
  1207.     pos1[0]=false;
  1208.     for (int i=1; i<11; i++) scnt[i]=(i-1)*36;
  1209.   }
  1210.  
  1211.   public void Load_Part2() {
  1212.     source = new MemoryImageSource(200,167,pix,0,200);
  1213.     Img = createImage(source);
  1214.     cnt=cnt1=cnt2=timer=0; partnr=10;
  1215.     picxsize=200;
  1216.     picysize=167;
  1217.     for (int y=0; y<200; y++) {
  1218.       int ypos=y*240;
  1219.       for (int x=0 ; x<240; x++) { dispic[x+ypos]=red[x+ypos]=green[x+ypos]=0;
  1220.        pix[x+ypos]=(255 << 24);  }
  1221.     }
  1222.   }
  1223.  
  1224.   public void Load_Part4() {
  1225.     cnt=cnt1=cnt2=cnter=timer=0; partnr=14;
  1226.     picxsize=200;
  1227.     picysize=167;
  1228.     camerax=-80; cameray=-80; cameraz=100;
  1229.     boolean CORDS = true;
  1230.     int val=0;
  1231.     try {
  1232.       URL url = new URL(getCodeBase(), "data/scene2.3D");
  1233.       DataInputStream in = new DataInputStream((InputStream) url.getContent());
  1234.       try {
  1235.           String X="a";
  1236.           while (X!=null) {
  1237.             X = in.readLine();
  1238.             if (X==null||X.regionMatches(false,0,"FACES",0,4))
  1239.              { CORDS=false;
  1240.                 if (X!=null) X = in.readLine();
  1241.              }
  1242.             if (X!=null&&CORDS==false&&X.compareTo("VERTEX")==0) {
  1243.                CORDS=true;
  1244.                val=cnt;
  1245.                X = in.readLine();
  1246.             }
  1247.             if (CORDS==true) {
  1248.               String Y = in.readLine();
  1249.               String Z = in.readLine();
  1250.               Float cx = Float.valueOf(X);
  1251.               Float cy = Float.valueOf(Y);
  1252.               Float cz = Float.valueOf(Z);
  1253.               double x = cx.doubleValue();
  1254.               double y = cy.doubleValue();
  1255.               double z = cz.doubleValue();
  1256.               pointx[cnt]=(int)(x*40);
  1257.               pointy[cnt]=(int)(y*40);
  1258.               pointz[cnt]=(int)(z*40);
  1259.               cnt++;
  1260.             }
  1261.             if (CORDS==false&&X!=null) {
  1262.               String p1 = in.readLine();
  1263.               String p2 = in.readLine();
  1264.               Float cp = Float.valueOf(X);
  1265.               int fp = (int)cp.doubleValue();
  1266.               cp = Float.valueOf(p1);
  1267.               int fp1 = (int)cp.doubleValue();
  1268.               cp = Float.valueOf(p2);
  1269.               int fp2 = (int)cp.doubleValue();
  1270.               facelist[cnt1].p=fp+val;
  1271.               facelist[cnt1].p1=fp1+val;
  1272.               facelist[cnt1].p2=fp2+val;
  1273.               facelist[cnt1].nr=cnt1;
  1274.               cnt1++;
  1275.             }
  1276.           }
  1277.       } catch (EOFException e) {}
  1278.       in.close();
  1279.     } catch (IOException e) { getAppletContext().showStatus("FILE-ERROR"); }
  1280.     maxverts=cnt;
  1281.     maxface=cnt1;
  1282.     cnt=cnt1=0;
  1283.     for (int y=0; y<200; y++) {
  1284.       int ypos=y*240;
  1285.       for (int x=0 ; x<240; x++) { dispic[x+ypos]=red[x+ypos]=green[x+ypos]=0;
  1286.        pix[x+ypos]=(255 << 24);  }
  1287.     }
  1288.   }
  1289.  
  1290.   public void Load_Part5_1() {
  1291.     cnt=cnt1=cnt2=cnter=timer=0; partnr=16;
  1292.     picxsize=200;
  1293.     picysize=167;
  1294.     camerax=120; cameray=0; cameraz=100;
  1295.     tex = new int[256*256];
  1296.     Img = getImage(getCodeBase(),"data/texture.jpg");
  1297.     grab = new PixelGrabber(Img,0,0,256,256,tex,0,256);
  1298.     try {
  1299.       grab.grabPixels();
  1300.      } catch (InterruptedException e) {};
  1301.     for (int y=0; y<256; y++)
  1302.       for (int x=0; x<256; x++) tex[x+(y << 8)]=(tex[x+(y << 8)] >> 16)&0xff;
  1303.     boolean CORDS = true;
  1304.     int val=0;
  1305.     try {
  1306.       URL url = new URL(getCodeBase(), "data/scene3.3D");
  1307.       DataInputStream in = new DataInputStream((InputStream) url.getContent());
  1308.       try {
  1309.           String X="a";
  1310.           while (X!=null) {
  1311.             X = in.readLine();
  1312.             if (X==null||X.regionMatches(false,0,"FACES",0,4))
  1313.              { CORDS=false;
  1314.                 if (X!=null) X = in.readLine();
  1315.              }
  1316.             if (X!=null&&CORDS==false&&X.compareTo("VERTEX")==0) {
  1317.                CORDS=true;
  1318.                val=cnt;
  1319.                X = in.readLine();
  1320.             }
  1321.             if (CORDS==true) {
  1322.               String Y = in.readLine();
  1323.               String Z = in.readLine();
  1324.               Float cx = Float.valueOf(X);
  1325.               Float cy = Float.valueOf(Y);
  1326.               Float cz = Float.valueOf(Z);
  1327.               double x = cx.doubleValue();
  1328.               double y = cy.doubleValue();
  1329.               double z = cz.doubleValue();
  1330.               pointx[cnt]=(int)(x*15);
  1331.               pointy[cnt]=(int)(y*15);
  1332.               pointz[cnt]=(int)(z*15);
  1333.               cnt++;
  1334.             }
  1335.             if (CORDS==false&&X!=null) {
  1336.               String p1 = in.readLine();
  1337.               String p2 = in.readLine();
  1338.               Float cp = Float.valueOf(X);
  1339.               int fp = (int)cp.doubleValue();
  1340.               cp = Float.valueOf(p1);
  1341.               int fp1 = (int)cp.doubleValue();
  1342.               cp = Float.valueOf(p2);
  1343.               int fp2 = (int)cp.doubleValue();
  1344.               facelist[cnt1].p=fp+val;
  1345.               facelist[cnt1].p1=fp1+val;
  1346.               facelist[cnt1].p2=fp2+val;
  1347.               facelist[cnt1].nr=cnt1;
  1348.               cnt1++;
  1349.             }
  1350.           }
  1351.       } catch (EOFException e) {}
  1352.       in.close();
  1353.     } catch (IOException e) { getAppletContext().showStatus("FILE-ERROR"); }
  1354.     maxverts=cnt;
  1355.     maxface=cnt1;
  1356.     cnt=cnt1=0;
  1357.     for (int y=0; y<200; y++) {
  1358.       int ypos=y*240;
  1359.       for (int x=0 ; x<240; x++) { dispic[x+ypos]=red[x+ypos]=green[x+ypos]=0;
  1360.        pix[x+ypos]=(255 << 24);  }
  1361.     }
  1362.   }
  1363.  
  1364.   public void Load_Part6() {
  1365.     Img = getImage(getCodeBase(),"data/pic6.jpg");
  1366.     tracer.addImage(Img,0);
  1367.     try {
  1368.       tracer.waitForAll();
  1369.     } catch (InterruptedException e) {}
  1370.     grab = new PixelGrabber(Img,0,0,240,200,pix1,0,240);
  1371.     try {
  1372.       grab.grabPixels();
  1373.      } catch (InterruptedException e) {};
  1374.     for (int i=0; i<25; i++) { sxpos[i]=(int)(Math.random()*240); sypos[i]=(int)(Math.random()*140); }
  1375.     for (int i1=0; i1<picysize; i1++)
  1376.       for (int i=0; i<picxsize; i++) {
  1377.         red[i+i1*picxsize]=0;
  1378.         green[i+i1*picxsize]=(int)((pix1[i+i1*picxsize] >> 8) & 0xff);
  1379.         blue[i+i1*picxsize]=0;
  1380.     }
  1381.     for (int i=0; i<20; i++) { pointx[i]=(int)(Math.random()*240); pointy[i]=200+(int)(Math.random()*30);
  1382.       pointz[i]=(int)(Math.random()*5); py[i]=3+(int)(Math.random()*3);
  1383.      }
  1384.     cnt=cnt1=cnt2=cnter=timer=0; partnr=20;
  1385.   }
  1386.  
  1387.   public void Load_EndPart() {
  1388.     Img = getImage(getCodeBase(),"data/pic7.gif");
  1389.     tracer.addImage(Img,0);
  1390.     try {
  1391.       tracer.waitForAll();
  1392.     } catch (InterruptedException e) {}
  1393.     Shows = new Image[7];
  1394.     text = new String[49];
  1395.     text[0]="You have";
  1396.     text[1]="experienced";
  1397.     text[2]="COAL from";
  1398.     text[3]="OtakInc";
  1399.     text[4]="A JAVA-Demo";
  1400.     text[5]="made in 1998";
  1401.     text[6]="for the";
  1402.     text[7]="TakeOver '98";
  1403.     text[8]="Party in";
  1404.     text[9]="Eindhoven";
  1405.     text[10]="in";
  1406.     text[11]="Netherland";
  1407.     text[12]="This is";
  1408.     text[13]="the first";
  1409.     text[14]="Demo or";
  1410.     text[15]="Intro, etc";
  1411.     text[16]="Which uses";
  1412.     text[17]="a realtime";
  1413.     text[18]="coaldraw -";
  1414.     text[19]="filter";
  1415.     text[20]="Coaldraw and";
  1416.     text[21]="Coal3D is";
  1417.     text[22]="an OtakInc";
  1418.     text[23]="development.";
  1419.     text[24]="Our goal was";
  1420.     text[25]="to demonstrate";
  1421.     text[26]="some new code";
  1422.     text[27]="not seen";
  1423.     text[28]="before!";
  1424.     text[29]="We hope you";
  1425.     text[30]="enjoyed it";
  1426.     text[31]="Thanks for";
  1427.     text[32]="watching!";
  1428.     text[33]="And thanks";
  1429.     text[34]="to the";
  1430.     text[35]="organisers";
  1431.     text[36]="especially";
  1432.     text[37]="Sparcus from";
  1433.     text[38]="Nostalgia";
  1434.     text[39]="who considered";
  1435.     text[40]="a JAVA-Compo";
  1436.     text[41]="in the last";
  1437.     text[42]="minute.";
  1438.     text[43]=" ";
  1439.     text[44]="C'YA";
  1440.     text[45]=" ";
  1441.     text[46]="Furuike ya";
  1442.     text[47]="kawazu tobikamu";
  1443.     text[48]="mizu no oto";
  1444.     for (int i=0; i<50; i++) pointy[i]=300+i*10;
  1445.     Shows[0] = getImage(getCodeBase(),"data/end1.jpg");
  1446.     Shows[1] = getImage(getCodeBase(),"data/end2.jpg");
  1447.     Shows[2] = getImage(getCodeBase(),"data/end3.jpg");
  1448.     Shows[3] = getImage(getCodeBase(),"data/end4.jpg");
  1449.     Shows[4] = getImage(getCodeBase(),"data/end5.jpg");
  1450.     Shows[5] = getImage(getCodeBase(),"data/end6.jpg");
  1451.     Shows[6] = getImage(getCodeBase(),"data/end7.jpg");
  1452.     for (int i=0; i<7; i++) tracer.addImage(Shows[i],i);
  1453.     try {
  1454.       tracer.waitForAll();
  1455.     } catch (InterruptedException e) {}
  1456.     picxsize = Img.getWidth(null);
  1457.     picysize = Img.getHeight(null);
  1458.     grab = new PixelGrabber(Img,0,0,picxsize,picysize,pix1,0,picxsize);
  1459.     try {
  1460.       grab.grabPixels();
  1461.      } catch (InterruptedException e) {};
  1462.     source = new MemoryImageSource(picxsize,picysize,pix,0,picxsize);
  1463.     Img = createImage(source);
  1464.     for (int y=0; y<picysize; y++)
  1465.       for (int x=0; x<picxsize; x++) {
  1466.         red[x+y*picxsize]=(int)((pix1[x+y*picxsize] >> 16) & 0xff);
  1467.         pix1[x+y*picxsize]=0;
  1468.     }
  1469.     Img = createImage(source);
  1470.     Font myFont=new Font("Arial", Font.BOLD, 10);
  1471.     FontMetrics myMetrix=getFontMetrics(myFont);
  1472.     offGraphics.setFont(myFont);
  1473.     sxpos[0]=picxsize >> 1;
  1474.     sypos[0]=picysize >> 1;
  1475.     sxpos[1]=30+picxsize >> 1;
  1476.     sypos[1]=-15+(picysize >> 1);
  1477.     scnt[0]=40;
  1478.     scnt[1]=160;
  1479.     for (int i=2; i<9; i++) scnt[i]=(i-2)*50;
  1480.     cnt=cnt1=cnt2=cnter=timer=0; partnr=22;
  1481.     sxpos[2]=0; sypos[2]=6;
  1482.     sxpos[3]=240; sypos[3]=188;
  1483.   }
  1484.  
  1485.   public void Load_Part5() {
  1486.     cnt=cnt1=cnt2=cnter=timer=0; partnr=18;
  1487.     picxsize=240;
  1488.     picysize=200;
  1489.     cnt=cnt1=0;
  1490.     int val=0;
  1491.     Img = getImage(getCodeBase(),"data/greetz.gif");
  1492.     tracer.addImage(Img,0);
  1493.     try {
  1494.       tracer.waitForAll();
  1495.     } catch (InterruptedException e) {}
  1496.     grab = new PixelGrabber(Img,0,0,64,64,pix1,0,64);
  1497.     try {
  1498.       grab.grabPixels();
  1499.      } catch (InterruptedException e) {};
  1500.      for (int y=0; y<64; y++) {
  1501.        int ypos=(y << 6);
  1502.        for (int x=0; x<64; x++) pix1[x+ypos]=(pix1[x+ypos] >> 16)&0xff;
  1503.      }
  1504.      Img = getImage(getCodeBase(),"data/greetz2.gif");
  1505.     tracer.addImage(Img,0);
  1506.     try {
  1507.       tracer.waitForAll();
  1508.     } catch (InterruptedException e) {}
  1509.     grab = new PixelGrabber(Img,0,0,240,200,difx,0,240);
  1510.     try {
  1511.       grab.grabPixels();
  1512.      } catch (InterruptedException e) {};
  1513.      for (int y=0; y<200; y++) {
  1514.        int ypos=y*240;
  1515.        for (int x=0; x<240; x++) difx[x+ypos]=(difx[x+ypos] >> 16)&0xff;
  1516.      }
  1517.     cnt=cnt1=0;
  1518. /*    text = new String[9];
  1519.     text[0]="   RAM-JAM";
  1520.     text[1]="  D-LUSION";
  1521.     text[2]="DIGITAL NERDS";
  1522.     text[3]="   COMPLEX";
  1523.     text[4]="    CREST";
  1524.     text[5]="H-TOWN PLAYERZ";
  1525.     text[6]="  NOSTALGIA";
  1526.     text[7]="    STACK";
  1527.     text[8]="    QUAD";*/
  1528.     Font myFont=new Font("Arial", Font.BOLD, 24);
  1529.     FontMetrics myMetrix=getFontMetrics(myFont);
  1530.     offGraphics.setFont(myFont);
  1531.     pos=false;
  1532.     for (int y=0; y<200; y++) {
  1533.       int ypos=y*240;
  1534.       for (int x=0 ; x<240; x++) { red[x+ypos]=green[x+ypos]=0;
  1535.        pix[x+ypos]=(255 << 24);  }
  1536.     }
  1537.     cnt3=0; timer=1;
  1538.     Img.flush();
  1539.     source = new MemoryImageSource(240,200,pix,0,240);
  1540.     Img = createImage(source);
  1541.   }
  1542.  
  1543.  
  1544.  
  1545.   public void Load_Part3() {
  1546.     cnt=cnt1=cnt2=cnter=timer=0; partnr=12;
  1547.     picxsize=200;
  1548.     picysize=167;
  1549.     camerax=0; cameray=0; cameraz=100;
  1550.     for (int y=0; y<200; y++) {
  1551.       int ypos=y*240;
  1552.       for (int x=0 ; x<240; x++) { dispic[x+ypos]=red[x+ypos]=green[x+ypos]=0;
  1553.        pix[x+ypos]=(255 << 24);  }
  1554.     }
  1555.     for (int i=0; i<125; i++) scnt[i]=(int)(Math.random()*100);
  1556.     for (int i2=0; i2<5; i2++)
  1557.       for (int i1=0; i1<5; i1++)
  1558.         for (int i=0; i<5; i++) { pointx[i+i1*5+i2*25]=-10+i*5; pointy[i+i1*5+i2*25]=-10+i1*5; pointz[i+i1*5+i2*25]=-10+i2*5; }
  1559.   }
  1560.  
  1561.   public void paint(Graphics g) {
  1562.     update(g);
  1563.   }
  1564.  
  1565.   public void Pic_1() {
  1566.      offGraphics.setColor(Color.black);
  1567.      if (pos1[0]==false) offGraphics.drawImage(Img,0,0,this);
  1568.      if (pos1[0]==true) {
  1569.        offGraphics.drawImage(Img1,sx,0,80,200,this);
  1570.        if (pos1[1]==false) sx-=8;
  1571.        if (sx<0) { sx=0; pos1[1]=true; }
  1572.        offGraphics.drawImage(Img1,scrx,0,scrx1,200,20,30,100,130,this);
  1573.        offGraphics.drawImage(Img1,scrx2,0,scrx3,200,55,60,85,90,this);
  1574.        if (pos1[1]==true) {
  1575.          offGraphics.drawString("Code",10,65);
  1576.          offGraphics.drawString("  & ",10,95);
  1577.          offGraphics.drawString("Ideas",10,125);
  1578.          if (scrx>80) { scrx-=4; scrx1+=4; }
  1579.          if (scrx<80) scrx=125;
  1580.        }
  1581.        if (scrx<90) pos1[2]=true;
  1582.        if (pos1[2]==true) {
  1583.          offGraphics.drawString("By",100,95);
  1584.          if (scrx2>160) { scrx2-=4; scrx3+=4; }
  1585.          if (scrx2<=160) offGraphics.drawString("Chojin",160,95);
  1586.        }
  1587.      }
  1588.      timer++;
  1589.      if (timer>10) pos1[0]=true;
  1590.      if (timer>60) {
  1591.        source = new MemoryImageSource(125,200,red,0,125);
  1592.        Img1 = createImage(source);
  1593.        Img = getImage(getCodeBase(),"data/pic4.jpg");
  1594.        tracer.addImage(Img,0);
  1595.        try {
  1596.          tracer.waitForAll();
  1597.        } catch (InterruptedException e) {}
  1598.        cnt=1;
  1599.        scrx=120; scrx1=120; scrx2=200; scrx3=200; sx=60; timer=0;
  1600.        pos1[0]=false;
  1601.        pos1[1]=false;
  1602.        pos1[2]=false;
  1603.      }
  1604.    }
  1605.  
  1606.    public void Pic_2() {
  1607.      offGraphics.setColor(Color.black);
  1608.      if (pos1[0]==false) offGraphics.drawImage(Img,0,0,this);
  1609.      if (pos1[0]==true) {
  1610.        offGraphics.drawImage(Img1,sx,0,80,200,this);
  1611.        if (pos1[1]==false) sx-=8;
  1612.        if (sx<0) { sx=0; pos1[1]=true; }
  1613.        offGraphics.drawImage(Img1,scrx,0,scrx1,200,20,30,100,130,this);
  1614.        offGraphics.drawImage(Img1,scrx2,0,scrx3,200,35,65,85,105,this);
  1615.        if (pos1[1]==true) {
  1616.          offGraphics.drawString("Music",10,95);
  1617.          if (scrx>80) { scrx-=4; scrx1+=4; }
  1618.          if (scrx<80) scrx=125;
  1619.        }
  1620.        if (scrx<90) pos1[2]=true;
  1621.        if (pos1[2]==true) {
  1622.          offGraphics.drawString("From",100,95);
  1623.          if (scrx2>160) { scrx2-=4; scrx3+=4; }
  1624.         if (scrx2<=160) { offGraphics.drawString("Slayers",160,75);
  1625.                           offGraphics.drawString("  &    ",160,95);
  1626.                           offGraphics.drawString("Chojin",160,115);
  1627.                          }
  1628.        }
  1629.      }
  1630.      timer++;
  1631.      if (timer>10) pos1[0]=true;
  1632.      if (timer>60) {
  1633.        source = new MemoryImageSource(125,200,green,0,125);
  1634.        Img1 = createImage(source);
  1635.        Img = getImage(getCodeBase(),"data/pic5.jpg");
  1636.        tracer.addImage(Img,0);
  1637.        try {
  1638.          tracer.waitForAll();
  1639.        } catch (InterruptedException e) {}
  1640.        cnt=2;
  1641.        scrx=120; scrx1=120; scrx2=200; scrx3=200; sx=60; timer=0;
  1642.        pos1[0]=false;
  1643.        pos1[1]=false;
  1644.        pos1[2]=false;
  1645.      }
  1646.    }
  1647.  
  1648.  public void Pic_3() {
  1649.      offGraphics.setColor(Color.white);
  1650.      if (pos1[0]==false) offGraphics.drawImage(Img,0,0,this);
  1651.      if (pos1[0]==true) {
  1652.        offGraphics.drawImage(Img1,sx,0,80,200,this);
  1653.        if (pos1[1]==false) sx-=8;
  1654.        if (sx<0) { sx=0; pos1[1]=true; }
  1655.        offGraphics.drawImage(Img1,scrx,0,scrx1,200,12,56,65,125,this);
  1656.        offGraphics.drawImage(Img1,scrx2,0,scrx3,200,17,108,57,153,this);
  1657.        if (pos1[1]==true) {
  1658.          offGraphics.drawString("Guest",10,65);
  1659.          offGraphics.drawString("Stars",10,95);
  1660.          if (scrx>80) { scrx-=4; scrx1+=4; }
  1661.          if (scrx<80) scrx=125;
  1662.        }
  1663.        if (scrx<90) pos1[2]=true;
  1664.        if (pos1[2]==true) {
  1665.          if (scrx2>160) { scrx2-=4; scrx3+=4; }
  1666.          if (scrx2<=160) { offGraphics.drawString("The",155,65);
  1667.                            offGraphics.drawString("Slayers",155,95);
  1668.                            offGraphics.drawString("Crew",155,125);
  1669.                          }
  1670.        }
  1671.      }
  1672.     timer++;
  1673.     if (timer>10) pos1[0]=true;
  1674.     if (timer>60) partnr=7;
  1675.    }
  1676.  
  1677.  public void Opening_1() {
  1678.     int distort;
  1679.     int dred=0,dblue=0,dgreen=0;
  1680.     for (int i=0; i<2; i++) {
  1681.       sxpos[i]=(int)(Math.random()*240);
  1682.       sypos[i]=0;
  1683.     }
  1684.     for (int i1=0; i1<2; i1++) {
  1685.       while (sxpos[i1]<239&&sxpos[i1]>1&&sypos[i1]<199&&difx[sxpos[i1]+sypos[i1]*240]<48) {
  1686.          dispic[sxpos[i1]+sypos[i1]*240]=128;
  1687.          difx[sxpos[i1]+sypos[i1]*240]+=2;
  1688.          int value=difx[(sxpos[i1]-1)+(sypos[i1]+1)*240];
  1689.          int min=value;
  1690.          int value1=difx[sxpos[i1]+(sypos[i1]+1)*240];
  1691.          int value2=difx[sxpos[i1]+1+(sypos[i1]+1)*240];
  1692.          int value3=difx[sxpos[i1]+1+sypos[i1]*240];
  1693.          int value4=difx[sxpos[i1]-1+sypos[i1]*240];
  1694.          if (value1<min) min=value1; else value1=min+1;
  1695.          if (value2<min) min=value2; else value2=min+1;
  1696.          if (value3<min) min=value3; else value3=min+1;
  1697.          if (value4<min) min=value4; else value4=min+1;
  1698.          if (min==value) sypos[i1]++;
  1699.          if (min==value1) { sxpos[i1]--; sypos[i1]++; }
  1700.          if (min==value2) { sxpos[i1]++; sypos[i1]++; }
  1701.          if (min==value3) sxpos[i1]++;
  1702.          if (min==value4) sxpos[i1]--;
  1703.        }
  1704.        if (difx[sxpos[i1]+sypos[i1]*240]>20) {
  1705.           for (int r=0; r<30; r++) { Circle(sxpos[i1],sypos[i1],r,128-(r << 2));
  1706.                                     Circle(sxpos[i1]+1,sypos[i1],r,128-(r << 2));
  1707.                                   }
  1708.        }
  1709.      }
  1710.      for (int y=0; y < 200; y++) {
  1711.         int ypos=y*240;
  1712.         for (int x = 0; x < 240; x++) {
  1713.           dblue=((3*blue[x+ypos]) >> 3) + (dispic[x+ypos] << 1);
  1714.           dgreen=((3*green[x+ypos]) >> 3)+(dispic[x+ypos] << 1);
  1715.           dred=((3*red[x+ypos]) >> 3)-(dispic[x+ypos] << 1);
  1716.           if (dgreen>255) dgreen=255;
  1717.           if (dred<0) dred=0;
  1718.           if (dblue>255) dblue=255;
  1719.           pix[x+ypos]=(255 << 24)+(dred << 16)+(dgreen << 8)+dblue;
  1720.           if (red[x+ypos]>16) difx[x+ypos]=red[x+ypos]; else difx[x+ypos]=noise[(cnt++)%3000];
  1721.           dispic[x+ypos]=0;
  1722.        }
  1723.      }
  1724.      timer++;
  1725.      if (timer>75) partnr=1;
  1726.   }
  1727.  
  1728.  public void Opening_2() {
  1729.     int distort;
  1730.     double y1=(double)cnt1;
  1731.     double xadd=(double)(picxsize-(cnt << 1))/picxsize;
  1732.     double yadd=(double)(picysize-(cnt1 << 1))/picysize;
  1733.     for (int y=0; y < picysize; y++) {
  1734.       double x1=(double)cnt;
  1735.       y1+=yadd;
  1736.       int ypos=y*picxsize;
  1737.       for (int x=0; x < picxsize; x++) {
  1738.     x1+=xadd;
  1739.     int x2=(int)x1;
  1740.     int y2=(int)y1;
  1741.         if (x2>0&&x2<picxsize&&y2>0&&y2<picysize) {
  1742.           int ypos2=y2*picxsize;
  1743.           int xadder=(x2-x) >> 1;
  1744.           int yadder=(y2-y) >> 1;
  1745.           int xadder1=3*(x2-x) >> 2;
  1746.           int yadder1=3*(y2-y) >> 2;
  1747.           int xadder2=(x2-x) >> 2;
  1748.           int yadder2=(y2-y) >> 2;
  1749.           int xadder3=3*(x2-x) >> 3;
  1750.           int yadder3=3*(y2-y) >> 3;
  1751.           int xadder4=5*(x2-x) >> 3;
  1752.           int yadder4=5*(y2-y) >> 3;
  1753.           int xadder5=7*(x2-x) >> 3;
  1754.           int yadder5=7*(y2-y) >> 3;
  1755.           int red1=(red[x+ypos]+red[x+xadder+(y+yadder)*picxsize]+red[x+xadder1+(y+yadder1)*picxsize]+
  1756.             red[x2+ypos2]+red[x+xadder2+(y+yadder2)*picxsize]+red[x+xadder3+(y+yadder3)*picxsize]+red[x+xadder4+(y+yadder4)*picxsize]+
  1757.             red[x+xadder5+(y+yadder5)*picxsize]) >> 3;
  1758.           int green1=(green[x+ypos]+green[x+xadder+(y+yadder)*picxsize]+green[x+xadder1+(y+yadder1)*picxsize]+
  1759.             green[x2+ypos2]+green[x+xadder2+(y+yadder2)*picxsize]+green[x+xadder3+(y+yadder3)*picxsize]+green[x+xadder4+(y+yadder4)*picxsize]+
  1760.             green[x+xadder5+(y+yadder5)*picxsize]) >> 3;
  1761.           int blue1=(blue[x+ypos]+blue[x+xadder+(y+yadder)*picxsize]+blue[x+xadder1+(y+yadder1)*picxsize]+
  1762.             blue[x2+ypos2]+blue[x+xadder2+(y+yadder2)*picxsize]+blue[x+xadder3+(y+yadder3)*picxsize]+blue[x+xadder4+(y+yadder4)*picxsize]+
  1763.             blue[x+xadder5+(y+yadder5)*picxsize]) >> 3;
  1764.           pix[x+y*picxsize]=(255 << 24)+(red1 << 16)+(green1 << 8)+blue1;
  1765.         } else pix[x+y*picxsize]=pix1[x+y*picxsize];
  1766.       }
  1767.     }
  1768.     if (pos==false) {
  1769.      cnt1+=2;
  1770.      xval+=2*xadd;
  1771.     } else {
  1772.      cnt1-=2;
  1773.      xval-=2*xadd;
  1774.    }
  1775.    timer++;
  1776.    if (timer>55) partnr=3;
  1777.    cnt=(int)xval;
  1778.    if (cnt1>25) pos=true;
  1779.    if (cnt1<8) pos=false;
  1780.   }
  1781.  
  1782. public void Opening_3() {
  1783.     int re1=0,bl1=0,gn1=0,nx = 0, ny = 0;
  1784.      for (int y=1; y < picysize-1; y++) {
  1785.         int ypos=y*picxsize;
  1786.         for (int x = 1; x < picxsize-1; x++) {
  1787.          if (cnt2==0) {
  1788.            nx=(difx[(x+1)+ypos]-difx[(x-1)+ypos]) << 1;
  1789.            ny=(difx[x+(y+1)*picxsize]-difx[x+(y-1)*picxsize]) << 1;
  1790.          }
  1791.          if (cnt2==1) {
  1792.            nx=(difx[(x+1)+ypos]-difx[(x-1)+ypos]);
  1793.            ny=(difx[x+(y+1)*picxsize]-difx[x+(y-1)*picxsize]);
  1794.          }
  1795.          if (cnt2>1) {
  1796.            nx=(difx[(x+1)+ypos]-difx[(x-1)+ypos]) >> (cnt2-1);
  1797.            ny=(difx[x+(y+1)*picxsize]-difx[x+(y-1)*picxsize]) >> (cnt2-1);
  1798.          }
  1799.          red[x+ypos]=255-((Math.abs(nx)+Math.abs(ny)));
  1800.          if (red[x+ypos]<0) red[x+ypos]=0;
  1801.       }
  1802.      }
  1803.      for (int y=1; y<picysize-1; y++) {
  1804.        int ypos=y*picxsize;
  1805.        for (int x=1; x<picxsize-1; x++) if (difx[x+ypos]>cnt1) {
  1806.          int x1=x+1;
  1807.          int x2=x+2;
  1808.          int x3=x+3;
  1809.          int y1=y-1;
  1810.          int y2=y-2;
  1811.          int y3=y-3;
  1812.          int x4=x+4;
  1813.          int y4=y-4;
  1814.          if (x1>picxsize-1) x1=picxsize-1;
  1815.          if (x2>picxsize-1) x2=picxsize-1;
  1816.          if (x3>picxsize-1) x3=picxsize-1;
  1817.          if (x4>picxsize-1) x4=picxsize-1;
  1818.          if (y1<0) y1=0;
  1819.          if (y2<0) y2=0;
  1820.          if (y3<0) y3=0;
  1821.          if (y4<0) y4=0;
  1822.          y1*=picxsize; y2*=picxsize; y3*=picxsize; y4*=picxsize;
  1823.          int difx1=(4*red[x+ypos]+red[x1+y1]+red[x2+y2]+red[x3+y3]+red[x4+y4]) >> 3;
  1824.          pix[x+ypos]=(255 << 24)+(difx1 << 16)+(difx1 << 8)+difx1;
  1825.         }
  1826.        else pix[x+ypos]=pix1[x+ypos];
  1827.     }
  1828.     timer++;
  1829.     if (timer>20) cnt1-=8;
  1830.     if (timer>70&&timer%3==0) cnt2++;
  1831.     if (cnt2>8) partnr=5;
  1832.   }
  1833.  
  1834.   public void Opening_4() {
  1835.     if (cnt==0) Pic_1();
  1836.     if (cnt==1) Pic_2();
  1837.     if (cnt==2) Pic_3();
  1838.   }
  1839.  
  1840.  public void Tunnel2() {
  1841.      if (timer>299) {
  1842.        for (int i1=1; i1<11; i1++) {
  1843.         sxpos[i1]=120+(int)(((timer-300) << 1)*Ctab[scnt[i1]]);
  1844.         sypos[i1]=100+(int)(((timer-300) << 1)*Stab[scnt[i1]]);
  1845.         for (int r=0; r<16; r++) {
  1846.           ClearCircle(sxpos[i1],sypos[i1],r,8);
  1847.           ClearCircle(sxpos[i1]+1,sypos[i1],r,8);
  1848.         }
  1849.         scnt[i1]=(scnt[i1]+4)%360;
  1850.        }
  1851.      }
  1852.      if (timer<300) {
  1853.        for (int y=0; y < 200; y++) {
  1854.             int ypos=y*240;
  1855.             for (int x=0; x <120; x++) {
  1856.               i=(dispic[x+ypos]-cnt)&127;
  1857.               i1=(difx[x+ypos]-cnt)&127;
  1858.               red[x+ypos]=(cloud[i1+(i << 7)]);
  1859.               red[(239-x)+ypos]=cloud[i1+(i << 7)];
  1860.             }
  1861.         }
  1862.        for (int y=1; y < 199; y++) {
  1863.           int ypos=y*240;
  1864.           for (int x = 1; x < 239; x++) {
  1865.            int nx=(red[(x+1)+ypos]-red[(x-1)+ypos]) << 1;
  1866.            int ny=(red[x+(y+1)*240]-red[x+(y-1)*240]) << 1;
  1867.            green[x+ypos]=255-((Math.abs(nx)+Math.abs(ny)));
  1868.            if (green[x+ypos]<0) green[x+ypos]=0;
  1869.         }
  1870.        }
  1871.      }
  1872.      for (int y=1; y<199; y++) {
  1873.        int ypos=y*240;
  1874.        for (int x=1; x<239; x++) {
  1875.          int x1=x+1;
  1876.          int x2=x+2;
  1877.          int x3=x+3;
  1878.          int y1=y-1;
  1879.          int y2=y-2;
  1880.          int y3=y-3;
  1881.          int x4=x+4;
  1882.          int y4=y-4;
  1883.          if (x1>239) x1=239;
  1884.          if (x2>239) x2=239;
  1885.          if (x3>239) x3=239;
  1886.          if (x4>239) x4=239;
  1887.          if (y1<0) y1=0;
  1888.          if (y2<0) y2=0;
  1889.          if (y3<0) y3=0;
  1890.          if (y4<0) y4=0;
  1891.          y1*=240; y2*=240; y3*=240; y4*=240;
  1892.          int sum1=(4*green[x+ypos]+green[x1+y1]+green[x2+y2]+green[x3+y3]+green[x4+y4]) >> 3;
  1893.          if (timer>299&&sum1>255) sum1=255;
  1894.          pix[x+ypos]=(255 << 24)+(sum1 << 16)+(sum1 << 8)+sum1;
  1895.         }
  1896.     }
  1897.     if (timer<300) cnt=(cnt+4)%256;
  1898.     if (timer>385) partnr=9;
  1899.   }
  1900.  
  1901.   public void Tunnel1() {
  1902.      for (int y=0; y < 200; y++) {
  1903.           int ypos=y*240;
  1904.           for (int x=0; x <120; x++) {
  1905.             i=(dispic[x+ypos]-cnt)&127;
  1906.             i1=(difx[x+ypos]-cnt)&127;
  1907.             int color=cloud[i1+(i << 7)];
  1908.             int color1=cloud[i+(i1 << 7)];
  1909.             pix[x+ypos]=(255 << 24)+(color << 16)+((color1 >> 1) << 8);
  1910.             pix[(239-x)+ypos]=(255 << 24)+(color << 16)+((color1 >> 1) << 8);
  1911.           }
  1912.       }
  1913.       cnt=(cnt+4)%256;
  1914.   }
  1915.  
  1916.   public void Part1() {
  1917.     if (timer<200) Tunnel1();
  1918.     timer++;
  1919.     if (timer>=200) Tunnel2();
  1920.   }
  1921.  
  1922.   public void Part2() {
  1923.     for (int y=0; y<picysize; y++) {
  1924.       int ypos=y*picxsize;
  1925.       for (int x=0; x<picxsize; x++) red[x+ypos]=0;
  1926.     }
  1927.     Calrotxmat(192,rotx);
  1928.     Calrotymat(0,roty);
  1929.     Calrotzmat(cnt,rotz);
  1930.     for (int i=0; i<maxverts; i++) {
  1931.       int ax=(roty.a1*pointx[i]+roty.a3*pointz2[i]) >> 7;
  1932.       int ay=(rotz.b2*pointy[i]-rotz.b1*ax) >> 7;
  1933.       int az=(roty.c3*pointz2[i]+roty.c1*pointx[i]) >> 7;
  1934.       px[i]=(rotz.a1*ax+rotz.a2*pointy[i]) >> 7;
  1935.       py[i]=(rotx.b2*ay+rotx.b3*az) >> 7;
  1936.       pz[i]=(rotx.c3*az-rotx.c2*ay) >> 7;
  1937.       if (pos==false) pointz[i]-=2; else pointz[i]+=2;
  1938.       pointz2[i]=pointz[i];
  1939.       if (timer<200) {
  1940.         if (pos1[0]==false) pointy[i]--; else pointy[i]++;
  1941.         if (pointz2[i]<-20) pointz2[i]=-20;
  1942.         if (pointz2[i]>60) pointz2[i]=60;
  1943.       }
  1944.     }
  1945.     Calrotxmat(192,rotx);
  1946.     Calrotymat(0,roty);
  1947.     for (int i=maxverts; i<maxverts+10; i++) {
  1948.       Calrotzmat((scnt[i-(maxverts)]+cnt)%256,rotz);
  1949.       int ax=(roty.a1*pointx[i]+roty.a3*pointz[i]) >> 7;
  1950.       int ay=(rotz.b2*pointy[i]-rotz.b1*ax) >> 7;
  1951.       int az=(roty.c3*pointz[i]+roty.c1*pointx[i]) >> 7;
  1952.       px[i]=(rotz.a1*ax+rotz.a2*pointy[i]) >> 7;
  1953.       py[i]=(rotx.b2*ay+rotx.b3*az) >> 7;
  1954.       pz[i]=(rotx.c3*az-rotx.c2*ay) >> 7;
  1955.       if (timer<200) {
  1956.         if (pos==false) pointz[i]-=2; else pointz[i]+=2;
  1957.         if (pos1[0]==false) pointy[i]--; else pointy[i]++;
  1958.       }
  1959.     }
  1960.    if (pos==false) cnter++; else cnter--;
  1961.    if (pos1[0]==false) cnter1++; else cnter1--;
  1962.    if (cnter>20) pos=true;
  1963.    if (cnter1>15) pos1[0]=true;
  1964.    if (cnter<-20) pos=false;
  1965.    if (cnter1<-15) pos1[0]=false;
  1966.   for (int i=0; i<maxface; i++) Tria3d(facelist[i],192);
  1967.   for (int i=8; i<maxverts-1; i++) Line3d(px[i],py[i],pz[i],px[i+1],py[i+1],pz[i+1]);
  1968.   for (int i=maxverts; i<maxverts+10; i++) Lens3d(px[i],py[i],pz[i],128);
  1969.    for (int y=1; y < picysize-1; y++) {
  1970.      int ypos=y*picxsize;
  1971.       for (int x = 1; x < picxsize-1; x++) {
  1972.        int nx=(red[(x+1)+ypos]-red[(x-1)+ypos]) << 2;
  1973.        int ny=(red[x+(y+1)*picxsize]-red[x+(y-1)*picxsize]) << 2;
  1974.        green[x+ypos]=255-((Math.abs(nx)+Math.abs(ny)));
  1975.        if (green[x+ypos]<0) green[x+ypos]=0;
  1976.       }
  1977.      }
  1978.      for (int y=1; y<picysize-1; y++) {
  1979.        int ypos=y*picxsize;
  1980.        for (int x=1; x<picxsize-1; x++) {
  1981.          int x1=x+1;
  1982.          int x2=x+2;
  1983.          int x3=x+3;
  1984.          int y1=y-1;
  1985.          int y2=y-2;
  1986.          int y3=y-3;
  1987.          int x4=x+4;
  1988.          int y4=y-4;
  1989.          if (x1>picxsize-1) x1=picxsize-1;
  1990.          if (x2>picxsize-1) x2=picxsize-1;
  1991.          if (x3>picxsize-1) x3=picxsize-1;
  1992.          if (x4>picxsize-1) x4=picxsize-1;
  1993.          if (y1<0) y1=0;
  1994.          if (y2<0) y2=0;
  1995.          if (y3<0) y3=0;
  1996.          if (y4<0) y4=0;
  1997.          y1*=picxsize; y2*=picxsize; y3*=picxsize; y4*=picxsize;
  1998.          int sum1=(4*green[x+ypos]+green[x1+y1]+green[x2+y2]+green[x3+y3]+green[x4+y4]) >> 3;
  1999.          pix[x+ypos]=(255 << 24)+(sum1 << 16)+(sum1 << 8)+sum1;
  2000.         }
  2001.     }
  2002.    cnt=(cnt+4)%256;
  2003.    timer++;
  2004.    if (timer<60) cameray-=2;
  2005.    if (timer>=200) cameray-=4;
  2006.    if (timer>60&&timer<200) {
  2007.       if (cnt1<360) camerax+=(int)(3*Stab[cnt1]);
  2008.       if (cnt1>360) camerax-=(int)(3*Stab[(cnt1)%360]);
  2009.       cnt1=(cnt1+8)%720;
  2010.    }
  2011.    if (cameray<-120) partnr=11;
  2012.  }
  2013.  
  2014.   public void Part3() {
  2015.     if (cnter<40&&timer<80) {
  2016.       for (int i2=0; i2<5; i2++)
  2017.         for (int i1=0; i1<5; i1++)
  2018.           for (int i=0; i<5; i++) { pointx[i+i1*5+i2*25]=-cnter+i*(cnter >> 1); pointy[i+i1*5+i2*25]=-cnter+i1*(cnter >> 1); pointz[i+i1*5+i2*25]=-cnter+i2*(cnter >> 1);
  2019.       }
  2020.       cnter+=2;
  2021.     }
  2022.     if (timer>80) {
  2023.       for (int i2=0; i2<5; i2++)
  2024.         for (int i1=0; i1<5; i1++)
  2025.           for (int i=0; i<5; i++) { pointx[i+i1*5+i2*25]=-cnter+i*(cnter >> 1); pointy[i+i1*5+i2*25]=-cnter+i1*(cnter >> 1); pointz[i+i1*5+i2*25]=-cnter+i2*(cnter >> 1);
  2026.       }
  2027.       cnter-=2;
  2028.     }
  2029.     Calrotxmat(0,rotx);
  2030.     Calrotymat(cnt,roty);
  2031.     Calrotzmat(cnt3,rotz);
  2032.     for (int i=0; i<125; i++) {
  2033.       int ax1=(roty.a1*pointx[i]+roty.a3*pointz[i]) >> 7;
  2034.       int ay1=(rotz.b2*pointy[i]-rotz.b1*ax1) >> 7;
  2035.       int az1=(roty.c3*pointz[i]+roty.c1*pointx[i]) >> 7;
  2036.       px[i]=(rotz.a1*ax1+rotz.a2*pointy[i]) >> 7;
  2037.       py[i]=(rotx.b2*ay1+rotx.b3*az1) >> 7;
  2038.       pz[i]=(rotx.c3*az1-rotx.c2*ay1) >> 7;
  2039.     }
  2040.     for (int i=0; i<cnt2; i++) {
  2041.       stars[i].setRotx(0);
  2042.       stars[i].setRoty(0);
  2043.       stars[i].setRotz(0);
  2044.       Calrotxmat(stars[i].phix,stars[i].rotx);
  2045.       Calrotymat(stars[i].phiy,stars[i].roty);
  2046.       Calrotzmat(stars[i].phiz,stars[i].rotz);
  2047.       int ax=(stars[i].roty.a1*stars[i].sx+stars[i].roty.a3*stars[i].sz) >> 7;
  2048.       int ay=(stars[i].rotz.b2*stars[i].sy-stars[i].rotz.b1*ax) >> 7;
  2049.       int az=(stars[i].roty.c3*stars[i].sz+stars[i].roty.c1*stars[i].sx) >> 7;
  2050.       stars[i].px=(stars[i].rotz.a1*ax+stars[i].rotz.a2*stars[i].sy) >> 7;
  2051.       stars[i].py=(stars[i].rotx.b2*ay+stars[i].rotx.b3*az) >> 7;
  2052.       stars[i].pz=(stars[i].rotx.c3*az-stars[i].rotx.c2*ay) >> 7;
  2053.       Set3dPixel2(stars[i].px,stars[i].py,stars[i].pz,255-Math.abs(stars[i].pz));
  2054.     }
  2055.     if (cnt2<250) cnt2+=125;
  2056.     cnt=(cnt+2)%256;
  2057.     cnt3=(cnt3+1)%256;
  2058.     for (int i=0; i<125; i++) {
  2059.       stars[cnt1] = new Particle(px[i],py[i],pz[i]);
  2060.       cnt1=(cnt1+1)%250;
  2061.     }
  2062.     for (int y=1; y<166; y++) {
  2063.       int ypos=y*200;
  2064.       for (int x=1; x<199; x++) {
  2065.          int nx=(red[(x+1)+ypos]-red[(x-1)+ypos]) << 1;
  2066.          int ny=(red[x+((y+1)*200)]-red[x+((y-1)*200)]) << 1;
  2067.          green[x+ypos]=255-((Math.abs(nx)+Math.abs(ny)));
  2068.          if (green[x+ypos]<0) green[x+ypos]=0;
  2069.        }
  2070.      }
  2071.     for (int y=1; y<166; y++) {
  2072.        int ypos=y*200;
  2073.        for (int x=1; x<199; x++) {
  2074.          int x1=x+1;
  2075.          int x2=x+2;
  2076.          int x3=x+3;
  2077.          int y1=y-1;
  2078.          int y2=y-2;
  2079.          int y3=y-3;
  2080.          int x4=x+4;
  2081.          int y4=y-4;
  2082.          if (x1>199) x1=199;
  2083.          if (x2>199) x2=199;
  2084.          if (x3>199) x3=199;
  2085.          if (x4>199) x4=199;
  2086.          if (y1<0) y1=0;
  2087.          if (y2<0) y2=0;
  2088.          if (y3<0) y3=0;
  2089.          if (y4<0) y4=0;
  2090.          y1*=200; y2*=200; y3*=200; y4*=200;
  2091.          int sum1=(4*green[x+ypos]+green[x1+y1]+green[x2+y2]+green[x3+y3]+green[x4+y4]) >> 3;
  2092.          pix[x+ypos]=(255 << 24)+(sum1 << 16)+(sum1 << 8)+sum1;
  2093.          red[x+ypos]-=32;
  2094.          if (red[x+ypos]<0) red[x+ypos]=0;
  2095.         }
  2096.     }
  2097. //    if (cameraz>50) cameraz--;
  2098.     timer++;
  2099.     if (timer>105) partnr=13;
  2100.   }
  2101.  
  2102.   public void Part4() {
  2103.     for (int y=0; y<picysize; y++) {
  2104.       int ypos=y*picxsize;
  2105.       for (int x=0; x<picxsize; x++) red[x+ypos]=0;
  2106.     }
  2107.     Calrotxmat(192,rotx);
  2108.     if (timer<100)  Calrotymat(0,roty); else Calrotymat(cnt2,roty);
  2109.     Calrotzmat(cnt,rotz);
  2110.     for (int i=0; i<(maxverts >> 1); i++) {
  2111.       int ax=(roty.a1*pointx[i]+roty.a3*pointz[i]) >> 7;
  2112.       int ay=(rotz.b2*pointy[i]-rotz.b1*ax) >> 7;
  2113.       int az=(roty.c3*pointz[i]+roty.c1*pointx[i]) >> 7;
  2114.       px[i]=(rotz.a1*ax+rotz.a2*pointy[i]) >> 7;
  2115.       py[i]=(rotx.b2*ay+rotx.b3*az) >> 7;
  2116.       pz[i]=(rotx.c3*az-rotx.c2*ay) >> 7;
  2117.     }
  2118.     Calrotxmat(192,rotx);
  2119.     if (timer<100)  Calrotymat(0,roty); else Calrotymat(cnt2,roty);
  2120.     Calrotzmat((cnt << 1)%256,rotz);
  2121.     for (int i=(maxverts >> 1); i<maxverts; i++) {
  2122.       int ax=(roty.a1*pointx[i]+roty.a3*pointz[i]) >> 7;
  2123.       int ay=(rotz.b2*pointy[i]-rotz.b1*ax) >> 7;
  2124.       int az=(roty.c3*pointz[i]+roty.c1*pointx[i]) >> 7;
  2125.       px[i]=(rotz.a1*ax+rotz.a2*pointy[i]) >> 7;
  2126.       py[i]=(rotx.b2*ay+rotx.b3*az) >> 7;
  2127.       pz[i]=(rotx.c3*az-rotx.c2*ay) >> 7;
  2128.     }
  2129.    for (int i=0; i<maxface; i++) {
  2130.      Calcnorm(facelist[i],normx,normy,normz,i);
  2131.    }
  2132.    for (int i=0; i<maxverts; i++) gnormx[i]=gnormy[i]=gnormz[i]=0;
  2133.    for (int i=0; i<maxface; i++) {
  2134.      gnormx[facelist[i].p]+=normx[facelist[i].nr];
  2135.      gnormy[facelist[i].p]+=normy[facelist[i].nr];
  2136.      gnormz[facelist[i].p]+=normz[facelist[i].nr];
  2137.      gnormx[facelist[i].p1]+=normx[facelist[i].nr];
  2138.      gnormy[facelist[i].p1]+=normy[facelist[i].nr];
  2139.      gnormz[facelist[i].p1]+=normz[facelist[i].nr];
  2140.      gnormx[facelist[i].p2]+=normx[facelist[i].nr];
  2141.      gnormy[facelist[i].p2]+=normy[facelist[i].nr];
  2142.      gnormz[facelist[i].p2]+=normz[facelist[i].nr];
  2143.     }
  2144.    for (int i=0; i<maxverts; i++) Normvek(gnormx,gnormy,gnormz,i);
  2145.    int cnt1=0;
  2146.    for (int i=0; i<maxface; i++) {
  2147.       if (normz[i]>0.0f) {
  2148.         double cosa=gnormx[facelist[i].p]*lightx+gnormy[facelist[i].p]*lighty+gnormz[facelist[i].p]*lightz;
  2149.         if (cosa>0.0f) facelist[i].clr=(int)(cosa*255); else facelist[i].clr=0;
  2150.         cosa=gnormx[facelist[i].p1]*lightx+gnormy[facelist[i].p1]*lighty+gnormz[facelist[i].p1]*lightz;
  2151.         if (cosa>0.0f) facelist[i].clr1=(int)(cosa*255); else facelist[i].clr1=0;
  2152.         cosa=gnormx[facelist[i].p2]*lightx+gnormy[facelist[i].p2]*lighty+gnormz[facelist[i].p2]*lightz;
  2153.         if (cosa>0.0f) facelist[i].clr2=(int)(cosa*255); else facelist[i].clr2=0;
  2154.         indx[cnt1].z=(int)(pz[facelist[i].p]+pz[facelist[i].p1]+pz[facelist[i].p2])/3;
  2155.         indx[cnt1].nr=i;
  2156.         cnt1++;
  2157.     }
  2158.   }
  2159.    quicksort(0,cnt1-1);
  2160.    for (int i=0; i<cnt1; i++) Shade_tria3d(facelist[indx[i].nr],120);
  2161.    for (int y=1; y < picysize-1; y++) {
  2162.      int ypos=y*picxsize;
  2163.       for (int x = 1; x < picxsize-1; x++) {
  2164.        int nx=(red[(x+1)+ypos]-red[(x-1)+ypos]) << 2;
  2165.        int ny=(red[x+(y+1)*picxsize]-red[x+(y-1)*picxsize]) << 2;
  2166.        green[x+ypos]=255-((Math.abs(nx)+Math.abs(ny)));
  2167.        if (green[x+ypos]<0) green[x+ypos]=0;
  2168.       }
  2169.      }
  2170.      for (int y=1; y<picysize-1; y++) {
  2171.        int ypos=y*picxsize;
  2172.        for (int x=1; x<picxsize-1; x++) {
  2173.          int x1=x+1;
  2174.          int x2=x+2;
  2175.          int x3=x+3;
  2176.          int y1=y-1;
  2177.          int y2=y-2;
  2178.          int y3=y-3;
  2179.          int x4=x+4;
  2180.          int y4=y-4;
  2181.          if (x1>picxsize-1) x1=picxsize-1;
  2182.          if (x2>picxsize-1) x2=picxsize-1;
  2183.          if (x3>picxsize-1) x3=picxsize-1;
  2184.          if (x4>picxsize-1) x4=picxsize-1;
  2185.          if (y1<0) y1=0;
  2186.          if (y2<0) y2=0;
  2187.          if (y3<0) y3=0;
  2188.          if (y4<0) y4=0;
  2189.          y1*=picxsize; y2*=picxsize; y3*=picxsize; y4*=picxsize;
  2190.          int sum1=(4*green[x+ypos]+green[x1+y1]+green[x2+y2]+green[x3+y3]+green[x4+y4]) >> 3;
  2191.          pix[x+ypos]=(255 << 24)+(sum1 << 16)+(sum1 << 8)+sum1;
  2192.         }
  2193.     }
  2194.     cnt=(cnt+4)%256;
  2195.     if (timer<80) {
  2196.       if (camerax<0) camerax++;
  2197.       if (cameray<0) cameray++;
  2198.     }
  2199.     timer++;
  2200.     if (timer>100) cnt2=(cnt2+2)%256;
  2201.     if (timer>140) { camerax+=2; cameray-=2; }
  2202.     if (timer>190) partnr=15;
  2203.   }
  2204.  
  2205.   public void Part5_1() {
  2206.     for (int y=0; y<picysize; y++) {
  2207.       int ypos=y*picxsize;
  2208.       for (int x=0; x<picxsize; x++) red[x+ypos]=0;
  2209.     }
  2210.     Calrotxmat(63,rotx);
  2211.     if (camerax<0) Calrotymat((127+cnt)%256,roty); else Calrotymat(127,roty);
  2212.     Calrotzmat(cnt,rotz);
  2213.     for (int i=0; i<maxverts; i++) {
  2214.       int ax=(roty.a1*pointx[i]+roty.a3*pointz[i]) >> 7;
  2215.       int ay=(rotz.b2*pointy[i]-rotz.b1*ax) >> 7;
  2216.       int az=(roty.c3*pointz[i]+roty.c1*pointx[i]) >> 7;
  2217.       px[i]=(rotz.a1*ax+rotz.a2*pointy[i]) >> 7;
  2218.       py[i]=(rotx.b2*ay+rotx.b3*az) >> 7;
  2219.       pz[i]=(rotx.c3*az-rotx.c2*ay) >> 7;
  2220.     }
  2221.    for (int i=0; i<maxface; i++) {
  2222.      Calcnorm(facelist[i],normx,normy,normz,i);
  2223.    }
  2224.    for (int i=0; i<maxverts; i++) gnormx[i]=gnormy[i]=gnormz[i]=0;
  2225.    for (int i=0; i<maxface; i++) {
  2226.      gnormx[facelist[i].p]+=normx[facelist[i].nr];
  2227.      gnormy[facelist[i].p]+=normy[facelist[i].nr];
  2228.      gnormz[facelist[i].p]+=normz[facelist[i].nr];
  2229.      gnormx[facelist[i].p1]+=normx[facelist[i].nr];
  2230.      gnormy[facelist[i].p1]+=normy[facelist[i].nr];
  2231.      gnormz[facelist[i].p1]+=normz[facelist[i].nr];
  2232.      gnormx[facelist[i].p2]+=normx[facelist[i].nr];
  2233.      gnormy[facelist[i].p2]+=normy[facelist[i].nr];
  2234.      gnormz[facelist[i].p2]+=normz[facelist[i].nr];
  2235.     }
  2236.    for (int i=0; i<maxverts; i++) Normvek(gnormx,gnormy,gnormz,i);
  2237.    int cnt1=0;
  2238.    for (int i=0; i<maxface; i++) {
  2239.       if (normz[i]>0.0f) {
  2240.         indx[cnt1].z=(int)(pz[facelist[i].p]+pz[facelist[i].p1]+pz[facelist[i].p2])/3;
  2241.         indx[cnt1].nr=i;
  2242.         facelist[i].nx=128+(int)(Math.abs(gnormx[facelist[i].p]*127));
  2243.         facelist[i].ny=128+(int)(Math.abs(gnormy[facelist[i].p]*127));
  2244.         facelist[i].nx1=128+(int)(Math.abs(gnormx[facelist[i].p1]*127));
  2245.         facelist[i].ny1=128+(int)(Math.abs(gnormy[facelist[i].p1]*127));
  2246.         facelist[i].nx2=128+(int)(Math.abs(gnormx[facelist[i].p2]*127));
  2247.         facelist[i].ny2=128+(int)(Math.abs(gnormy[facelist[i].p2]*127));
  2248.         cnt1++;
  2249.     }
  2250.   }
  2251.    quicksort(0,cnt1-1);
  2252.    for (int i=0; i<cnt1; i++) Texture_tria3d(facelist[indx[i].nr]);
  2253.    for (int y=1; y < picysize-1; y++) {
  2254.      int ypos=y*picxsize;
  2255.       for (int x = 1; x < picxsize-1; x++) {
  2256.        int nx=(red[(x+1)+ypos]-red[(x-1)+ypos]) << 2;
  2257.        int ny=(red[x+(y+1)*picxsize]-red[x+(y-1)*picxsize]) << 2;
  2258.        green[x+ypos]=255-((Math.abs(nx)+Math.abs(ny)));
  2259.        if (green[x+ypos]<0) green[x+ypos]=0;
  2260.       }
  2261.      }
  2262.      for (int y=1; y<picysize-1; y++) {
  2263.        int ypos=y*picxsize;
  2264.        for (int x=1; x<picxsize-1; x++) {
  2265.          int x1=x+1;
  2266.          int x2=x+2;
  2267.          int x3=x+3;
  2268.          int y1=y-1;
  2269.          int y2=y-2;
  2270.          int y3=y-3;
  2271.          int x4=x+4;
  2272.          int y4=y-4;
  2273.          if (x1>picxsize-1) x1=picxsize-1;
  2274.          if (x2>picxsize-1) x2=picxsize-1;
  2275.          if (x3>picxsize-1) x3=picxsize-1;
  2276.          if (x4>picxsize-1) x4=picxsize-1;
  2277.          if (y1<0) y1=0;
  2278.          if (y2<0) y2=0;
  2279.          if (y3<0) y3=0;
  2280.          if (y4<0) y4=0;
  2281.          y1*=picxsize; y2*=picxsize; y3*=picxsize; y4*=picxsize;
  2282.          int sum1=(4*green[x+ypos]+green[x1+y1]+green[x2+y2]+green[x3+y3]+green[x4+y4]) >> 3;
  2283.          pix[x+ypos]=(255 << 24)+(sum1 << 16)+(sum1 << 8)+sum1;
  2284.         }
  2285.     }
  2286.     cnt=(cnt+4)%256;
  2287.     if (camerax>0) camerax-=3; else camerax-=2;
  2288.     if (camerax<-160) partnr=17;
  2289.   }
  2290.  
  2291.    public void Part5() {
  2292.      if (timer<75) Cloud_1(); else { Cloud_2(); if (pos==false) cnt3+=4; else cnt3-=4; }
  2293.      if (cnt3>330) pos=true;
  2294.      if (cnt3<0) partnr=19;
  2295.      cnt1=(cnt1+2)%128;
  2296.      cnt2=(cnt2+4)%360;
  2297.      timer++;
  2298.    }
  2299.  
  2300.    public void Cloud_1() {
  2301.     for (int y=0; y<picysize; y++) {
  2302.       int ypos=y*picxsize;
  2303.       for (int x=0; x<picxsize; x++)
  2304.          red[x+ypos]=(int)(cloud[x%128+((y%128) << 7)]+cloud1[x%128+((y%128) << 7)]+cloud1[(x+cnt1)%128+((y%128) << 7)]+cloud1[(x+cnt)%128+(((y+cnt1)%128) << 7)]) >> 2;
  2305.     }
  2306.     for (int y=0; y<64; y++) { int ypos=(y << 6);
  2307.       for (int x=0; x<64; x++) if (pix1[x+ypos]>0) {
  2308.         int sypos=20+(y*3);
  2309.         int sxpos=(x << 2);
  2310.         int ylpos=sypos*picxsize;
  2311.         for (int i1=0; i1<360; i1+=36) {
  2312.           int x1=sxpos+(int)(8*Ctab[(i1+cnt2)%360]);
  2313.           int y1=(int)(8*Stab[(i1+cnt2)%360]);
  2314.           if (red[sxpos+ylpos]<cval) {
  2315.             X_line(sxpos,sypos,x1,sypos+y1,64);
  2316.           }
  2317.         }
  2318.       }
  2319.     }
  2320.     for (int y=0; y<picysize; y++) {
  2321.       int ypos=picxsize*y;
  2322.       for (int x=0; x<picxsize; x++) {
  2323.         int color=dispic[x+ypos];
  2324.         if (color>255) color=255;
  2325.         dispic[x+ypos]=color;
  2326.         int blue1=red[x+ypos];
  2327.         int green1=red[x+ypos];
  2328.         int red1=red[x+ypos];
  2329.         if (dispic[x+ypos]>0) {
  2330.             color=(3*color) >> 2;
  2331.             green1+=color;
  2332.             red1+=color;
  2333.             if (red1>255) red1=255;
  2334.             if (green1>255) green1=255;
  2335.           pix[x+ypos]=(255 << 24)+(red1 << 16)+(green1 << 8)+blue1;
  2336.         } else pix[x+ypos]=(255 << 24)+(red1 << 16)+(green1 << 8)+blue1;
  2337.         dispic[x+ypos]-=96;
  2338.         if (dispic[x+ypos]<0) dispic[x+ypos]=0;
  2339.         red[x+ypos]=0;
  2340.       }
  2341.    }
  2342.    if (cval<300) cval+=4;
  2343.  }
  2344.  
  2345.    public void Cloud_2() {
  2346.     for (int y=1; y<picysize-1; y++) {
  2347.       int ypos=y*picxsize;
  2348.       for (int x=1; x<picxsize-1; x++)   {
  2349.          int cldval=(int)(cloud[x%128+((y%128) << 7)]+cloud1[x%128+((y%128) << 7)]+cloud1[(x+cnt1)%128+((y%128) << 7)]+cloud1[(x+cnt)%128+(((y+cnt1)%128) << 7)]) >> 2;
  2350.          int nx=(difx[x+1+ypos]-difx[x-1+ypos]);
  2351.          int ny=(difx[x+(y+1)*picxsize]-difx[x+(y-1)*picxsize]);
  2352.          int light=Math.abs(cldval-nx)+Math.abs(cldval-ny);
  2353.          if (cldval<cnt3) color=(difx[x+ypos] >> 3)+(light >> 1); else color=cldval;
  2354.          if (color<0) color=0;
  2355.          if (color>255) color=255;
  2356.          pix[x+ypos]=(255 << 24)+(color << 16)+(color << 8)+color;
  2357.       }
  2358.     }
  2359.  }
  2360.  
  2361.    public void CheckPoint() {
  2362.      for (int i=0; i<25; i++) {
  2363.      if (sxpos[i]>0&&sxpos[i]<picxsize-1&&sypos[i]>0&&sypos[i]<picysize-1) {
  2364.        if (green[sxpos[i]+sypos[i]*picxsize]==0&&(green[sxpos[i]+1+sypos[i]*picxsize]>0||green[sxpos[i]-1+sypos[i]*picxsize]>0||green[sxpos[i]+(sypos[i]-1)*picxsize]>0||
  2365.         green[sxpos[i]+(sypos[i]-1)*picxsize]>0)) green[sxpos[i]+sypos[i]*picxsize]=223;
  2366.         sxpos[i]=(int)(Math.random()*240); sypos[i]=(int)(Math.random()*140);
  2367.      } else {
  2368.        sxpos[i]+=(-1+(int)(Math.random()*4));
  2369.        sypos[i]+=(-1+(int)(Math.random()*4));
  2370.      }
  2371.      if (sxpos[i]<0||sxpos[i]>picxsize-1) sxpos[i]=(int)(Math.random()*240);
  2372.      if (sypos[i]<0||sypos[i]>picysize-1) sypos[i]=(int)(Math.random()*140);
  2373.     }
  2374.   }
  2375.  
  2376.   public void Part6() {
  2377.      CheckPoint();
  2378.      for (int i=0; i<20; i++) { pointx[i]+=-1+(int)(Math.random()*3); pointy[i]-=py[i];
  2379.        int r1=pointz[i]+(200-pointy[i]) >> 4;
  2380.        Bubble(pointx[i],pointy[i],r1,128);
  2381.        if (pointy[i]<-20) {
  2382.         pointx[i]=(int)(Math.random()*240); pointy[i]=200+(int)(Math.random()*30);
  2383.         pointz[i]=(int)(Math.random()*5); py[i]=3+(int)(Math.random()*3);
  2384.        }
  2385.      }
  2386.      for (int y=0; y < picysize; y++) {
  2387.         int ypos=y*picxsize;
  2388.         for (int x = 0; x < picxsize; x++) {
  2389.             int cldvl=(int)(cloud[x%128+((y%128) << 7)]+cloud1[x%128+((y%128) << 7)]+cloud1[(x+cnt1)%128+((y%128) << 7)]+cloud1[(x+cnt)%128+(((y+cnt1)%128) << 7)]) >> 2;
  2390.             int brnfak = cldvl >> 1;
  2391.             int green1=green[x+ypos]-brnfak;
  2392.             int blue1=blue[x+ypos]+((3*cldvl) >> 2);
  2393.             if (blue1>255) blue1=255;
  2394.             if (blue1<0) blue1=0;
  2395.             if (green1<0) green1=0;
  2396.             int distort=-16+(int)(cldvl >> 4);
  2397.             int x1=x+distort;
  2398.             if (x1<0) x1=0;
  2399.             if (x1>picxsize-1) x1=picxsize-1;
  2400.             int y1=(y+distort);
  2401.             if (y1<0) y1=0;
  2402.             if (y1>picysize-1) y1=picysize-1;
  2403.             y1*=picxsize;
  2404.             pix1[x+ypos]=(255 << 24)+(green1 << 8)+blue1;
  2405.             blue[x+ypos]=0;
  2406.             pix[x+ypos]=pix1[x1+y1];
  2407.           }
  2408.      }
  2409.     cnt=(cnt+2)%256;
  2410.     cnt1=(cnt1+3)%256;
  2411.     timer++;
  2412.     if (timer>200) partnr=21;
  2413.   }
  2414.  
  2415.   public void EndPart() {
  2416.     for (int r=0; r<100; r++) {
  2417.       if (pos==false) cnt+=8; else cnt-=8;
  2418.       if (cnt>64) pos=true;
  2419.       if (cnt<0) pos=false;
  2420.       for (int i=0; i<2; i++) {
  2421.         int sx=sxpos[i]+(int)(30*Stab[scnt[i]]);
  2422.         int sy=sypos[i]+(int)(30*Ctab[scnt[i]]);
  2423.         Circle1(sx,sy,r,cnt);
  2424.         Circle1(sx,sy,r,cnt);
  2425.       }
  2426.     }
  2427.     scnt[0]=(scnt[0]+2)%360;
  2428.     scnt[1]=(scnt[1]+2)%360;
  2429.     for (int y=1; y<picysize-1; y++) {
  2430.       int ypos=y*picxsize;
  2431.       for (int x=1; x<picxsize-1; x++) {
  2432.         int nx=(red[x+1+ypos]-red[x-1+ypos]) << 1;
  2433.         int ny=(red[x+(y+1)*picxsize]-red[x+(y-1)*picxsize]) << 1;
  2434.         int color=pix1[x+ypos]-nx+pix1[x+ypos]-ny;
  2435.         if (color<0) color=0;
  2436.         if (color>255) color=255;
  2437.         blue[x+ypos]=color;
  2438.       }
  2439.     }
  2440.      for (int y=1; y<picysize-1; y++) {
  2441.       int ypos=y*picxsize;
  2442.       for (int x=1; x<picxsize-1; x++) {
  2443.          int nx=(blue[(x+1)+ypos]-blue[(x-1)+ypos]) << 1;
  2444.          int ny=(blue[x+((y+1)*picxsize)]-blue[x+((y-1)*picxsize)]) << 1;
  2445.          green[x+ypos]=255-((Math.abs(nx)+Math.abs(ny)));
  2446.          if (green[x+ypos]<0) green[x+ypos]=0;
  2447.        }
  2448.      }
  2449.     for (int y=1; y<picysize-1; y++) {
  2450.        int ypos=y*picxsize;
  2451.        for (int x=1; x<picxsize-1; x++) {
  2452.          int x1=x+1;
  2453.          int x2=x+2;
  2454.          int x3=x+3;
  2455.          int y1=y-1;
  2456.          int y2=y-2;
  2457.          int y3=y-3;
  2458.          int x4=x+4;
  2459.          int y4=y-4;
  2460.          if (x1>picxsize-1) x1=picxsize-1;
  2461.          if (x2>picxsize-1) x2=picxsize-1;
  2462.          if (x3>picxsize-1) x3=picxsize-1;
  2463.          if (x4>picxsize-1) x4=picxsize-1;
  2464.          if (y1<0) y1=0;
  2465.          if (y2<0) y2=0;
  2466.          if (y3<0) y3=0;
  2467.          if (y4<0) y4=0;
  2468.          y1*=picxsize; y2*=picxsize; y3*=picxsize; y4*=picxsize;
  2469.          int sum1=(4*green[x+ypos]+green[x1+y1]+green[x2+y2]+green[x3+y3]+green[x4+y4]) >> 3;
  2470.          pix[x+ypos]=(255 << 24)+(sum1 << 16)+(sum1 << 8)+sum1;
  2471.         }
  2472.     }
  2473.   }
  2474.  
  2475.   public void TextPart2() {
  2476.     offGraphics.setColor(Color.yellow);
  2477.     offGraphics.drawString(text[cnter],20,150);
  2478.   }
  2479.  
  2480.   public void TextPart1() {
  2481.     offGraphics.setColor(Color.blue);
  2482.     if (timer<200) text[2]=text[0];
  2483.     if (timer>=200) {
  2484.        text[2]=text[1].substring(0,cnt2);
  2485.        if (cnt2<15) text[3]=text[0].substring(cnt2,16); else text[3]="";
  2486.        text[2]=text[2]+text[3];
  2487.        if (cnt2<16) cnt2++;
  2488.     }
  2489.     if (timer<300) offGraphics.drawString(text[2],sxpos[0],60);
  2490.     if (pos1[0]==false) sxpos[0]-=4;
  2491.     if (sxpos[0]<=4) pos1[0]=true;
  2492.     if (pos1[0]==true) { sxpos[0]+=(int)(Stab[cnt1]*2); cnt1=(cnt1+8)%360; }
  2493.   }
  2494.  
  2495.   public void ShowEndPart() {
  2496.     for (int i=0; i<7; i++) {
  2497.      int sx=80+(int)(90*Ctab[scnt[i+2]]);
  2498.      int sy=80+(int)(90*Stab[scnt[i+2]]);
  2499.      offGraphics.drawImage(Shows[i],sx,sy,this);
  2500.      scnt[i+2]=(scnt[i+2]+4)%360;
  2501.    }
  2502.    offGraphics.drawImage(Img,sxpos[2],sypos[2],sxpos[3],sypos[3],Color.black,this);
  2503.    if (sxpos[2]<60) { sxpos[2]++; sypos[2]++; sxpos[3]-=2; sypos[3]-=2; }
  2504.    offGraphics.setColor(Color.green);
  2505.    for (int i=0; i<49; i++) if (pointy[i]>-10) {
  2506.      if (pointy[i]<220) offGraphics.drawString(text[i],1,pointy[i]);
  2507.      pointy[i]--;
  2508.    }
  2509.  }
  2510.   public void update(Graphics g) {
  2511.      Dimension d = size();
  2512.      if ( ( offGraphics == null) || (d.width !=offDimension.width) || (d.height!=offDimension.height) ) {
  2513.        offDimension = d;
  2514.        offImage = createImage(d.width,d.height);
  2515.        offGraphics = offImage.getGraphics();
  2516.       }
  2517.       offGraphics.setColor(c);
  2518.       offGraphics.fillRect(0,0,d.width,d.height);
  2519.       offGraphics.setColor(c);
  2520.      if (partnr!=6) Img.flush();
  2521.      switch (partnr) {
  2522.        case 0 : Opening_1();
  2523.        break;
  2524.        case 1 : LoadOp_2();
  2525.        break;
  2526.        case 2 : Opening_2();
  2527.        break;
  2528.        case 3 : LoadOp_3();
  2529.        break;
  2530.        case 4 : Opening_3();
  2531.        break;
  2532.        case 5 : Load_Op4();
  2533.        break;
  2534.        case 6 : Opening_4();
  2535.        break;
  2536.        case 7 : Load_Part1();
  2537.        break;
  2538.        case 8 : Part1();
  2539.        break;
  2540.        case 9 : Load_Part2();
  2541.        break;
  2542.        case 10 : Part2();
  2543.        break;
  2544.        case 11 : Load_Part3();
  2545.        break;
  2546.        case 12 : Part3();
  2547.        break;
  2548.        case 13 : Load_Part4();
  2549.        break;
  2550.        case 14 : Part4();
  2551.        break;
  2552.        case 15 : Load_Part5_1();
  2553.        break;
  2554.        case 16 : Part5_1();
  2555.        break;
  2556.        case 17 : Load_Part5();
  2557.        break;
  2558.        case 18 : Part5();
  2559.        break;
  2560.        case 19 : Load_Part6();
  2561.        break;
  2562.        case 20 : Part6();
  2563.        break;
  2564.        case 21 : Load_EndPart();
  2565.        break;
  2566.        case 22 : EndPart();
  2567.      }
  2568.      if (partnr!=6) Img = createImage(source);
  2569.      if (partnr==2) offGraphics.drawImage(Img,0,50,this);
  2570.      if (partnr>9&&partnr<18) offGraphics.drawImage(Img,0,0,240,200,Color.white,this);
  2571.      if (partnr!=2&&partnr!=3&&partnr!=6&&partnr!=7&&(partnr<10||partnr>17)&&partnr!=22) offGraphics.drawImage(Img,0,0,this);
  2572.      if (partnr==8) TextPart1();
  2573.      if (partnr==22) ShowEndPart();
  2574.      getAppletContext().showStatus("Coal from OtakInc");
  2575.      g.drawImage(offImage,0,0,this);
  2576.   }
  2577.  
  2578.   public void run() {
  2579.     long startTime = System.currentTimeMillis();
  2580.     while (killme != null) {
  2581.       frameNumber++;
  2582.       repaint();
  2583.       try {
  2584.      startTime+=delay;
  2585.      Thread.sleep(Math.max(0,startTime-System.currentTimeMillis()));
  2586.      } catch (InterruptedException e) { break; }
  2587.     }
  2588.   }
  2589.  
  2590.  public void stop() {
  2591.     killme.stop();
  2592.     offGraphics = null;
  2593.     offImage = null;
  2594. //    killme.destroy();
  2595.     killme = null;
  2596.   }
  2597.  
  2598. }
  2599.