Italiano
HOME | PROGETTI | CLASSI C++ | Sorgenti c\c++ | Galleria | Guestbook | Server BW | Contattami | Login

<< Burning Ship Fractal >>

visiste: 2826


Questo č un generatore della Burning Ship. La Burning Ship č l'insieme dei numeri complessi per cui la serie numerica Z non diverge, c č costante ed č uguale al numero complesso analizzato.






  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. //*** strumenti gestione file bmp ***//
  11. char *** crea_bmp(char *nome, long x, long y);
  12. void disegna_bmp(char *nome, char *** array, long x, long y);
  13.  
  14. //*** strumenti genstione numeri complessi ***//
  15. struct complesso
  16. {
  17. double r;
  18. double i;
  19. };
  20.  
  21. //*** strumenti gestione colori ***//
  22. struct rgb {
  23. int red;
  24. int green;
  25. int blue;
  26. };
  27. struct rgb_d {
  28. double red;
  29. double green;
  30. double blue;
  31. };
  32. struct hsv {
  33. int hue;
  34. int saturation;
  35. int value;
  36. };
  37. struct rgb hsv_rgb(struct hsv hsv_map);
  38.  
  39. //*** MAIN ***//
  40. int main (void){
  41.  
  42. char immagine_name[]="out_HSV.bmp";
  43. //*********** PARAMETRI *************//
  44. long larghezza = 1500;
  45. long altezza = 1500;
  46. long deep = 2000;
  47.  
  48. double y1 = 0.100;
  49. double x0 = -1.800, x1 = -1.675;
  50. double y0 = -0.025;
  51. //**********************************//
  52. //aggiustamento parametri
  53. double agg_temp;
  54. agg_temp=y1;
  55. y1=y0*(-1);
  56. y0=agg_temp*(-1);
  57. //**********************************//
  58.  
  59. char *** matrice;
  60. matrice = crea_bmp(immagine_name,larghezza,altezza);
  61.  
  62. //inizio elaborazione immagine
  63. long x,y,d,i;
  64. double real_x,real_y, colore;
  65. struct complesso z,c,temp;
  66.  
  67. for(x=0;x<larghezza;x++){
  68. real_x = ((x1-x0)/larghezza)*x+x0;
  69. for(y=0;y<altezza;y++){
  70. real_y = ((y1-y0)/altezza)*y+y0;
  71. struct rgb rgb;
  72. struct hsv hsv;
  73. //analisi di mendelbrot
  74. c.r = real_x;
  75. c.i = real_y;
  76. z.r = 0;
  77. z.i = 0;
  78. d = 0;
  79. for(i=0;i<deep;i++){
  80. if((z.r*z.r)+(z.i*z.i) > 4) {
  81. d = i;
  82. break;
  83. }
  84. temp.r = z.r;
  85. temp.i = z.i;
  86. if(temp.r<0)temp.r=temp.r*(-1);if(temp.i<0)temp.i=temp.i*(-1); //condizione burningship
  87.  
  88. z.r = (temp.r*temp.r) - (temp.i*temp.i) + c.r;
  89. z.i = (temp.r*temp.i)*2 + c.i;
  90. }
  91.  
  92. //calcolo del colore
  93. colore = ((double)d/(double)deep);
  94. colore = (int)((double)colore*360);
  95.  
  96. hsv.hue = colore*5;
  97. hsv.saturation = 255;
  98. hsv.value = 255;
  99.  
  100. //if(hsv.hue > 360) hsv.hue = 360;
  101. //if(hsv.saturation > 255) hsv.saturation = 255;
  102. //if(hsv.value > 255) hsv.value = 255;
  103.  
  104. rgb = hsv_rgb(hsv);
  105.  
  106. //controllo punto dell'insieme di mendelbrot
  107. if(d==0) {
  108. matrice[x][y][0]=0;
  109. matrice[x][y][1]=0;
  110. matrice[x][y][2]=0;
  111. }
  112. else {
  113. //scrittura del colore
  114. matrice[x][y][0]=rgb.blue; //blu: colore
  115. matrice[x][y][1]=rgb.green; //verde: comportamento opposto al blu
  116. matrice[x][y][2]=rgb.red; //rosso: costante
  117. }
  118. }
  119. printf("%d%%\n",x*100/larghezza);
  120. }
  121.  
  122. disegna_bmp(immagine_name,matrice,larghezza,altezza);
  123. printf("fine!");
  124.  
  125. system(immagine_name);
  126. //getchar();
  127. return 0;
  128. }
  129.  
  130. //****** FUNZIONI *******//
  131. char *** crea_bmp(char *nome, long x, long y){
  132.  
  133. FILE *stream, *cavia;
  134. stream = fopen(nome,"wb");
  135. cavia = fopen("cavia","rb");
  136.  
  137. char *buffer;
  138. buffer = (char *)malloc(54 * sizeof(char));
  139. long b = fread( buffer, 1, 54, cavia);
  140.  
  141. buffer[18] = x%256;//asse x
  142. buffer[19] = x/256;
  143. buffer[22] = y%256;//asse y
  144. buffer[23] = y/256;
  145.  
  146. fwrite(buffer, 1, b, stream);
  147. fclose(stream);
  148.  
  149. char *** array;
  150. int i, j, h;
  151. array = (char***)malloc(x * sizeof(char *));
  152. for(i=0; i<x; i++) {
  153. array[i] = (char**)malloc(y * sizeof(char *));
  154. for (j=0; j<y; j++)
  155. array[i][j] = (char*)malloc(3 * sizeof(char *));
  156. }
  157.  
  158. int i1,i2,i3;
  159. for(i1=0; i1<x; i1++)
  160. for (i2=0; i2<y; i2++)
  161. for (i3=0; i3<3; i3++)
  162. array[i1][i2][i3] = 0;
  163.  
  164. return array;
  165. }
  166.  
  167. void disegna_bmp(char *nome, char *** array, long x, long y){
  168.  
  169. FILE *stream;
  170. stream = fopen(nome,"ab");
  171.  
  172. int i1,i2;
  173. for (i2=y-1; i2>=0; i2--)
  174. for(i1=0; i1<x; i1++)
  175. fwrite(array[i1][i2], 1, 3, stream);
  176.  
  177. fclose(stream);
  178. }
  179.  
  180. struct rgb hsv_rgb(struct hsv hsv_map){
  181.  
  182. struct rgb_d rgb_map;
  183. struct rgb rgb_int;
  184.  
  185. double H = ((double)hsv_map.hue);
  186. double S = ((double)hsv_map.saturation)/255;
  187. double V = ((double)hsv_map.value)/255;
  188.  
  189. double hi = ((int)(H/60))%6;
  190. double f = (H/60) - (double)hi;
  191. double p = V*(1-S);
  192. double q = V*(1-(f*S));
  193. double t = V*(1-(1-f)*S);
  194.  
  195. if (hi == 0){ rgb_map.red=V; rgb_map.green=t; rgb_map.blue=p;}
  196. else if (hi == 1){ rgb_map.red=q*255; rgb_map.green=V; rgb_map.blue=p;}
  197. else if (hi == 2){ rgb_map.red=p*255; rgb_map.green=V; rgb_map.blue=t;}
  198. else if (hi == 3){ rgb_map.red=p*255; rgb_map.green=q; rgb_map.blue=V;}
  199. else if (hi == 4){ rgb_map.red=t*255; rgb_map.green=p; rgb_map.blue=V;}
  200. else if (hi == 5){ rgb_map.red=V*255; rgb_map.green=p; rgb_map.blue=q;}
  201. else printf("ERRORE!");
  202.  
  203. rgb_int.red = (int)(rgb_map.red*255);
  204. rgb_int.green = (int)(rgb_map.green*255);
  205. rgb_int.blue = (int)(rgb_map.blue*255);
  206.  
  207. return rgb_int;
  208. }
  209.  
Versione sito: 1.03.01 by mamo139. - Tutti i sorgenti presenti su questo sito sono rilasciati sotto licenza "GNU GPL version 3".