Scarica il sorgente database/15-burningship_file_generator.cpp
  1. //*************************************//
  2. //******** created by mamo139 *********//
  3. //*** http://mamo139.altervista.org ***//
  4. //*************************************//
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10.  
  11. //*** strumenti genstione numeri complessi ***//
  12. struct complesso
  13. {
  14. double r;
  15. double i;
  16. };
  17. //*** strumenti gestione db
  18. int ** crea_matrice(long x, long y);
  19. void scrivi_matrice(char * file_name, int ** matrice, long xl, long yl);
  20.  
  21. //*** MAIN ***//
  22. int main (void){
  23.  
  24. char db_name[]="burn";
  25. //*********** PARAMETRI *************//
  26. long larghezza = 2000;
  27. long altezza = 2000;
  28. long deep = 2000;
  29.  
  30. double y1 = 2;
  31. double x0 = -2, x1 = 2;
  32. double y0 = -2;
  33. //**********************************//
  34. //aggiustamento parametri
  35. double agg_temp;
  36. agg_temp=y1;
  37. y1=y0*(-1);
  38. y0=agg_temp*(-1);
  39. //**********************************//
  40.  
  41. int ** matrice;
  42. matrice = crea_matrice(larghezza,altezza);
  43.  
  44. //inizio elaborazione immagine
  45. long x,y,d,i;
  46. double real_x,real_y, colore;
  47. struct complesso z,c,temp;
  48.  
  49. for(x=0;x<larghezza;x++){
  50. real_x = ((x1-x0)/larghezza)*x+x0;
  51. for(y=0;y<altezza;y++){
  52. real_y = ((y1-y0)/altezza)*y+y0;
  53.  
  54. //analisi di mendelbrot
  55. c.r = real_x;
  56. c.i = real_y;
  57. z.r = 0;
  58. z.i = 0;
  59. d = 0;
  60. for(i=0;i<deep;i++){
  61. if((z.r*z.r)+(z.i*z.i) > 4) {
  62. d = i;
  63. break;
  64. }
  65. temp.r = z.r;
  66. temp.i = z.i;
  67. if(temp.r<0)temp.r=temp.r*(-1);if(temp.i<0)temp.i=temp.i*(-1); //condizione burningship
  68.  
  69. z.r = (temp.r*temp.r) - (temp.i*temp.i) + c.r;
  70. z.i = (temp.r*temp.i)*2 + c.i;
  71. }
  72.  
  73. matrice[x][y] = d;
  74. }
  75. printf("%d%%\n",x*100/larghezza);
  76. }
  77.  
  78. scrivi_matrice(db_name,matrice,larghezza,altezza);
  79. printf("fine!");
  80.  
  81.  
  82. getchar();
  83. return 0;
  84. }
  85. //****** FUNZIONI *******//
  86. int ** crea_matrice(long x, long y){
  87.  
  88. int ** array;
  89. int i, j;
  90. array = (int**)malloc(x * sizeof(int *));
  91. for(i=0; i<x; i++) {
  92. array[i] = (int*)malloc(y * sizeof(int *));
  93. }
  94.  
  95. int i1,i2;
  96. for(i1=0; i1<x; i1++)
  97. for (i2=0; i2<y; i2++)
  98. array[i1][i2] = 0;
  99.  
  100. return array;
  101. }
  102. void scrivi_matrice(char * file_name, int ** matrice, long xl, long yl){
  103. FILE *s;
  104. s = fopen(file_name,"wb");
  105.  
  106. int i1,i2;
  107. for(i1=0; i1<xl; i1++)
  108. for (i2=0; i2<yl; i2++)
  109. fprintf(s,"%d%c",matrice[i1][i2],0);
  110.  
  111. fclose(s);
  112.  
  113. }
  114.