1
0

makepal.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <windows.h>
  2. #include <math.h>
  3. extern int (*warand)(void);
  4. static double rsc[3], rv[3];
  5. static double drand(void)
  6. {
  7. return (warand()%4096)/(double)4096;
  8. }
  9. static void startgen(void)
  10. {
  11. for (int x = 0; x < 3; x ++)
  12. {
  13. rsc[x]=drand()*256.0+256.0;
  14. rv[x]=drand()*0.25+0.25;
  15. }
  16. if ((warand()&0xf)==5) rv[0]+=drand()*4.0;
  17. if ((warand()&0xf)==2) rv[1]+=drand()*4.0;
  18. if ((warand()&0xf)==3) rv[2]+=drand()*4.0;
  19. }
  20. static int getv(int i, int w)
  21. {
  22. double d=sin((double)i*3.14159/256.0*rv[w])*rsc[w];
  23. int v;
  24. __asm
  25. {
  26. fld d
  27. fistp v
  28. }
  29. if (v<0)v=0;
  30. if (v>0xff)v=0xff;
  31. return v;
  32. }
  33. static int lreversed;
  34. unsigned char *getnewpalette()
  35. {
  36. static unsigned char thispal[256][3];
  37. int x;
  38. startgen();
  39. for (x = 0; x < 768; x ++)
  40. {
  41. thispal[x/3][x%3]=getv(x/3,x%3);
  42. }
  43. int lr=warand()%21;
  44. if (lreversed)
  45. {
  46. if (warand()&1) lreversed=0;
  47. lr=4;
  48. }
  49. else if (lr == 4)
  50. {
  51. lreversed=1;
  52. }
  53. switch (lr)
  54. {
  55. case 3:
  56. for (x = 0; x < 128; x ++)
  57. {
  58. thispal[x][0]=thispal[x*2][0];
  59. thispal[x][1]=thispal[x*2][1];
  60. thispal[x][2]=thispal[x*2][2];
  61. }
  62. for (; x < 256; x ++)
  63. {
  64. thispal[x][0]=thispal[255-x][0];
  65. thispal[x][1]=thispal[255-x][1];
  66. thispal[x][2]=thispal[255-x][2];
  67. }
  68. break;
  69. case 4:
  70. for (x = 0; x < 128; x ++)
  71. {
  72. int q;
  73. for (q = 0; q < 3; q ++)
  74. {
  75. unsigned char t;
  76. t=thispal[x][q];
  77. thispal[x][q]=thispal[255-x][q];
  78. thispal[255-x][q]=t;
  79. }
  80. }
  81. break;
  82. }
  83. return &thispal[0][0];
  84. }