English
HOME | PROJECTS | C++ CLASSES | c\c++ source code | Gallery | Guestbook | BW Servers | Contact me | Login

<< Julia sets >>

visits: 3787


Questo è un generatore dell'insieme di Julia. L'insieme di Julia è l'insieme dei numeri complessi per cui la serie numerica Z non diverge. La differenza dall'insieme di Mandelbrot è che c è costante per tutti i numeri complessi ed è uguale ad un numero complesso arbitrario.
Gli insiemi di Julia piu belli si hanno prendendo punti che sono sul bordo dell'inisieme di Mandelbrot.



questo insieme di julia ha c = -0.835-2321i


  1. //*************************************//
  2. //******** created by mamo139 *********//
  3. //*** http://mamo139.altervista.org ***//
  4. //*************************************//
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. char *** crea_bmp(char *nome, long x, long y);
  10. void disegna_bmp(char *nome, char *** array, long x, long y);
  11.  
  12. struct complesso
  13. {
  14. double r;
  15. double i;
  16. };
  17. struct complesso julia;
  18.  
  19. int main (void){
  20.  
  21. char immagine_name[]="out_julia.bmp";
  22. //*********** PARAMETRI *************//
  23. long larghezza = 1500;
  24. long altezza = 1500;
  25. long deep = 1000;
  26.  
  27. julia.r = -0.835;
  28. julia.i = -0.2321;
  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. char *** matrice;
  42. matrice = crea_bmp(immagine_name,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. for(x=0;x<larghezza;x++){
  49. real_x = ((x1-x0)/larghezza)*x+x0;
  50. for(y=0;y<altezza;y++){
  51. real_y = ((y1-y0)/altezza)*y+y0;
  52.  
  53. //analisi di mendelbrot
  54. c.r = julia.r;
  55. c.i = julia.i;
  56. z.r = real_x;
  57. z.i = real_y;
  58. d = 0;
  59. for(i=0;i<deep;i++){
  60. if((z.r*z.r)+(z.i*z.i) > 4) {
  61. d = i;
  62. break;
  63. }
  64. temp.r = z.r;
  65. temp.i = z.i;
  66. //if(temp.r<0)temp.r=temp.r*(-1);if(temp.i<0)temp.i=temp.i*(-1); //condizione burningship
  67.  
  68. z.r = (temp.r*temp.r) - (temp.i*temp.i) + c.r;
  69. z.i = (temp.r*temp.i)*2 + c.i;
  70. }
  71.  
  72. //calcolo del colore
  73. colore = ((double)d/deep)*255;
  74. colore = colore*30; //amplificazione
  75. if(colore>255) colore=255;
  76.  
  77. //controllo punto dell'insieme di mendelbrot
  78. if(d==0) {
  79. matrice[x][y][0]=0;
  80. matrice[x][y][1]=0;
  81. matrice[x][y][2]=0;
  82. }
  83. else {
  84. //scrittura del colore
  85. matrice[x][y][0]=colore; //blu: colore
  86. matrice[x][y][1]=255-matrice[x][y][0]; //verde: comportamento opposto al blu
  87. matrice[x][y][2]=255; //rosso: costante
  88. }
  89. }
  90. printf("%d%%\n",x*100/larghezza);
  91. }
  92.  
  93. disegna_bmp(immagine_name,matrice,larghezza,altezza);
  94. printf("fine!");
  95.  
  96. system(immagine_name);
  97. //getchar();
  98. return 0;
  99. }
  100.  
  101. char *** crea_bmp(char *nome, long x, long y){
  102.  
  103. FILE *stream, *cavia;
  104. stream = fopen(nome,"wb");
  105. cavia = fopen("cavia","rb");
  106.  
  107. char *buffer;
  108. buffer = (char *)malloc(54 * sizeof(char));
  109. long b = fread( buffer, 1, 54, cavia);
  110.  
  111. buffer[18] = x%256;//asse x
  112. buffer[19] = x/256;
  113. buffer[22] = y%256;//asse y
  114. buffer[23] = y/256;
  115.  
  116. fwrite(buffer, 1, b, stream);
  117. fclose(stream);
  118.  
  119. char *** array;
  120. int i, j, h;
  121. array = (char***)malloc(x * sizeof(char *));
  122. for(i=0; i<x; i++) {
  123. array[i] = (char**)malloc(y * sizeof(char *));
  124. for (j=0; j<y; j++)
  125. array[i][j] = (char*)malloc(3 * sizeof(char *));
  126. }
  127.  
  128. int i1,i2,i3;
  129. for(i1=0; i1<x; i1++)
  130. for (i2=0; i2<y; i2++)
  131. for (i3=0; i3<3; i3++)
  132. array[i1][i2][i3] = 0;
  133.  
  134. return array;
  135. }
  136.  
  137. void disegna_bmp(char *nome, char *** array, long x, long y){
  138.  
  139. FILE *stream;
  140. stream = fopen(nome,"ab");
  141.  
  142. int i1,i2;
  143. for (i2=y-1; i2>=0; i2--)
  144. for(i1=0; i1<x; i1++)
  145. fwrite(array[i1][i2], 1, 3, stream);
  146.  
  147. fclose(stream);
  148. }
  149.  
Website version: 1.03.01 by mamo139. - All the source codes are intended to be released under "GNU GPL version 3".