space.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * ALGO : PROJ. : Volume
  3. * RESEARCH : File : space.c
  4. * : Date : 20100531.0725UTC
  5. * : Email : mail@algoresearch.net
  6. */
  7. #include "main.h"
  8. #include "space.h"
  9. int adds(SYS_TABLE *sys, int x, int y, int z)
  10. {
  11. if (x < 0) x += sys->space_w;
  12. if (y < 0) y += sys->space_h;
  13. if (z < 0) z += sys->space_d;
  14. if (x >= sys->space_w) x -= sys->space_w;
  15. if (y >= sys->space_h) y -= sys->space_h;
  16. if (z >= sys->space_d) z -= sys->space_d;
  17. return sys->size_plane * z + sys->space_h * y + x;
  18. }
  19. void cell_overlap(SYS_TABLE *sys, int v, int x, int y, int z)
  20. {
  21. }
  22. void cell_set(SYS_TABLE *sys, int v, int x, int y, int z)
  23. {
  24. sys->space_i[adds(sys,x,y,z)] = v;
  25. }
  26. int cell_get(SYS_TABLE *sys, int x, int y, int z)
  27. {
  28. return sys->space_i[adds(sys, x, y, z)];
  29. }
  30. void init_space(SYS_TABLE *sys)
  31. {
  32. int x, y, z;
  33. for(z=0; z<sys->space_d; z++)
  34. for(y=0; y<sys->space_h; y++)
  35. for(x=0; x<sys->space_w; x++)
  36. {
  37. sys->space_i[adds(sys,x,y,z)] = 2;
  38. sys->space_o[adds(sys,x,y,z)] = sys->space_i[adds(sys,x,y,z)];
  39. }
  40. }
  41. void create_space(SYS_TABLE *sys, int w, int h, int d)
  42. {
  43. sys->space_w = w;
  44. sys->space_h = h;
  45. sys->space_d = d;
  46. sys->size_plane = w * h;
  47. sys->size_space = w * h * d;
  48. sys->space_i = malloc(sys->size_space * sizeof(int));
  49. sys->space_o = malloc(sys->size_space * sizeof(int));
  50. init_space (sys);
  51. }
  52. void julia_set(SYS_TABLE *sys)
  53. {
  54. int c, x, y, z;
  55. float d, dx, dy, x0, y0, z0, q = 0.1, radius, zr, zi;
  56. d = 2 / 320.0;
  57. for (z=0; z<320; z++)
  58. {
  59. z0 = z * d - 1.5;
  60. for (y = 0; y < 320; y++)
  61. {
  62. y0 = y * d - 1;
  63. for(x = 0; x < 320; x++)
  64. {
  65. x0 = x * d - 1;
  66. dx = x0; dy = y0, c = 0;
  67. do
  68. {
  69. zr = dx * dx - dy * dy + z0;
  70. zi = 2.0 * dx * dy + q;
  71. dx = zr; dy = zi;
  72. radius = zr * zr + zi * zi;
  73. c++;
  74. }while(radius < 64 && c < 64);
  75. sys->space_i[adds(sys, x, y, z)] = c * 4 -1;
  76. }
  77. }
  78. }
  79. }
  80. void iterative_space (SYS_TABLE *sys)
  81. {
  82. sys->iter = 0;
  83. julia_set(sys);
  84. sys->mapping = 1;
  85. while(sys->main)
  86. {
  87. usleep(1200);
  88. }
  89. }