home *** CD-ROM | disk | FTP | other *** search
/ Rat's Nest 1 / ratsnest1.iso / prgmming / c / rot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-08  |  2.1 KB  |  141 lines

  1. #include <time.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <math.h>
  5.  
  6. #define MAXS 300
  7.  
  8. void open(void);
  9. void close(void);
  10. void pset(int x,int y,unsigned char c);
  11. void putp(unsigned int ad,unsigned char c);
  12. void initpal(void);
  13. void inittables(void);
  14.  
  15. int sint[256],cost[256]; // sin & cos tables
  16.  
  17. void main(void)
  18. {
  19.  int x[MAXS],y[MAXS],z[MAXS];
  20.  unsigned char angle=0;
  21.  
  22.  unsigned int ids[MAXS]={0};
  23.  
  24.  int apu;
  25.  
  26.  randomize();
  27.  inittables();
  28.  
  29.  for(apu=0;apu<MAXS;apu++)
  30.   {
  31.    x[apu] = -750 + random(1500);
  32.    y[apu] = -750 + random(1500);
  33.    z[apu] = 1+random(255);
  34.   }
  35.  open();     // open-graphics 320x200
  36.  initpal();  // palette..
  37.  
  38.  apu=0;
  39.  while(!kbhit())
  40.  {
  41.   int xx,yy,xxx,yyy;
  42.   if(ids[apu]!=65000)
  43.      putp(ids[apu],0);
  44.  
  45.   z[apu]--;
  46.  
  47.   if(z[apu])
  48.   {
  49.  
  50.   xxx = (x[apu]/z[apu]);
  51.   yyy = (y[apu]/z[apu]);
  52.  
  53.   // rotation
  54.   xx = (xxx*cost[angle]-yyy*sint[angle]) / 256;
  55.   yy = (xxx*sint[angle]+yyy*cost[angle]) / 256;
  56.  
  57.   xx += 160;
  58.   yy += 100;
  59.  
  60.   if((xx<320 && xx >= 0) && (yy<200 && yy>=0))
  61.      { ids[apu] = yy*320+xx;
  62.        putp(ids[apu],z[apu]);
  63.      }
  64.      else
  65.      {
  66.       ids[apu] = 65000;
  67.      }
  68.   }
  69.   else
  70.   {
  71.    x[apu] = -750+random(1500);
  72.    y[apu] = -750+random(1500);
  73.    z[apu] = 100+random(400);
  74.   }
  75.   apu++;
  76.   if(apu==MAXS){
  77.         apu=0;
  78.         angle++;
  79.         angle++;
  80.         }
  81.  
  82.  }
  83.  
  84.  
  85.  close();    // close & set 80x25 mode..
  86. }
  87.  
  88. void open(void)
  89. {
  90.  asm mov ax,0x13
  91.  asm int 0x10
  92. }
  93.  
  94. void close(void)
  95. {
  96.  asm mov ax,0x3
  97.  asm int 0x10
  98. }
  99.  
  100. void pset(int x,int y,unsigned char c)
  101. {
  102.  char far * paikka = (char far *)(0xa0000000 + y*320 +x);
  103.  *paikka = c;
  104. }
  105.  
  106. void putp(unsigned int ad,unsigned char c)
  107. {
  108.  char far *paikka = (char far *)(0xa0000000+ad);
  109.  
  110.  *paikka = c;
  111. }
  112.  
  113. void initpal(void)
  114. {
  115.  int x;
  116.  
  117.  asm mov al,1     // valitse ensimmäinen rgb..
  118.  asm mov dx,0x3c8
  119.  asm out dx,al
  120.  asm inc dx
  121.  // aseta koko paletti uusix, harmaasävy..
  122.  for(x=256;x>0;x--)
  123.   {
  124.    asm mov ax,x
  125.    asm shr al,2
  126.    asm out dx,al
  127.    asm out dx,al
  128.    asm out dx,al
  129.   }
  130. }
  131.  
  132. void inittables(void)
  133. {
  134.  int i;
  135.  
  136.  for(i=0;i<256;i++)
  137.   {
  138.    sint[i] = sin(2*3.14*i/256)*256;
  139.    cost[i] = cos(2*3.14*i/256)*256;
  140.   }
  141. }