visiste: 3221
//*************************************// //******** created by mamo139 *********// //*** http://mamo139.altervista.org ***// //*************************************// #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> //*** strumenti gestione file bmp ***// char *** crea_bmp(char *nome, long x, long y); void disegna_bmp(char *nome, char *** array, long x, long y); //*** strumenti gestione colori ***// struct rgb { int red; int green; int blue; }; struct rgb_d { double red; double green; double blue; }; struct hsv { int hue; int saturation; int value; }; struct rgb hsv_rgb(struct hsv hsv_map); //*** MAIN ***// int main (void){ char nomefiledb[100]; printf("nome del database (la matrice deve essere quadrata):"); scanf("%s",nomefiledb); printf("lettura file: %s!\n",nomefiledb); getchar(); long x,y,d,i; FILE * st; st = fopen(nomefiledb,"rb"); fseek(st,0,SEEK_END); long filesize = ftell(st); rewind(st); long numero_dati=0, altezza, larghezza; char * number; number = (char *) malloc (100 * sizeof(char)); char * buffer; buffer = (char *) malloc (filesize * sizeof(char)); long readed = fread(buffer,1,filesize,st); rewind(st); printf("filesize: %d letto:%d\n",filesize,readed); for(x=0;x<filesize;x++){ if(buffer[x] == '\x00') numero_dati++; } printf("numero dati: %d\n",numero_dati); long xy = (long) sqrt(numero_dati); printf("base matrice quadrata: %d\n",xy); larghezza = xy; altezza = xy; long ** matrice_input; matrice_input = (long **) malloc ( xy * sizeof(long) ); for(x=0;x<larghezza;x++) matrice_input[x] = (long *) malloc (xy * sizeof(long) ); printf("\n\nmatrice per dati del file creata!\n"); printf("\nlettura del file in corso...\n"); int se1=0,nump=0; x=0;y=0; for(i=0;i<filesize;i++){ if(buffer[i] != '\x00'){ number[nump] = buffer[i]; nump++; }else{ number[nump] = '\0'; matrice_input[x][y] = atoi(number); nump = 0; if(y<altezza-1) y++; else { y=0;x++; } } } printf("matrice caricata!\n"); printf("\nlarghezza: %d\naltezza: %d\n",larghezza,altezza); //************** INIZIO SCRITTURA BMP char image_name[] = "out_image.bmp"; printf("\nCaricamento matrice bmp in corso...\n"); char *** matrice; matrice = crea_bmp(image_name,larghezza,altezza); //inizio elaborazione immagine double real_x,real_y, colore; struct hsv hsv; struct rgb rgb; printf("\nOperazioni di caricamento completate.\n"); //printf("\nPremere INVIO per inizio elaborazione colori.\n"); //getchar(); printf("\nInizio ciclo di disegno.\n"); for(x=0;x<larghezza;x++){ for(y=0;y<altezza;y++){ d = matrice_input[x][y]/4; //calcolo del colore if(d>255) d=255; colore = d; /* rgb.blue = colore; rgb.green = colore; rgb.red = colore; */ hsv.hue = (int) 300-colore; hsv.saturation = 200; hsv.value = colore; rgb = hsv_rgb(hsv); //controllo punto dell'insieme di mendelbrot if(d==0) { matrice[x][y][0]=0; matrice[x][y][1]=0; matrice[x][y][2]=0; } else { //scrittura del colore matrice[x][y][0]=rgb.blue; //blu: colore matrice[x][y][1]=rgb.green; //verde: comportamento opposto al blu matrice[x][y][2]=rgb.red; //rosso: costante } } //printf("%d%%\n",x*100/larghezza); } printf("Fine ciclo di disegno.\n\nScrittura file in corso...\n"); disegna_bmp(image_name,matrice,larghezza,altezza); printf("fine!"); system(image_name); //getchar(); return 0; } //****** FUNZIONI *******// char *** crea_bmp(char *nome, long x, long y){ FILE *stream, *cavia; stream = fopen(nome,"wb"); cavia = fopen("cavia","rb"); char *buffer; buffer = (char *)malloc(54 * sizeof(char)); long b = fread( buffer, 1, 54, cavia); buffer[18] = x%256;//asse x buffer[19] = x/256; buffer[22] = y%256;//asse y buffer[23] = y/256; fwrite(buffer, 1, b, stream); fclose(stream); char *** array; int i, j, h; array = (char***)malloc(x * sizeof(char *)); for(i=0; i<x; i++) { array[i] = (char**)malloc(y * sizeof(char *)); for (j=0; j<y; j++) array[i][j] = (char*)malloc(3 * sizeof(char *)); } int i1,i2,i3; for(i1=0; i1<x; i1++) for (i2=0; i2<y; i2++) for (i3=0; i3<3; i3++) array[i1][i2][i3] = 0; return array; } void disegna_bmp(char *nome, char *** array, long x, long y){ FILE *stream; stream = fopen(nome,"ab"); int i1,i2; for (i2=y-1; i2>=0; i2--) for(i1=0; i1<x; i1++) fwrite(array[i1][i2], 1, 3, stream); fclose(stream); } struct rgb hsv_rgb(struct hsv hsv_map){ struct rgb_d rgb_map; struct rgb rgb_int; double H = ((double)hsv_map.hue); double S = ((double)hsv_map.saturation)/255; double V = ((double)hsv_map.value)/255; double hi = ((int)(H/60))%6; double f = (H/60) - (double)hi; double p = V*(1-S); double q = V*(1-(f*S)); double t = V*(1-(1-f)*S); if (hi == 0){ rgb_map.red=V; rgb_map.green=t; rgb_map.blue=p;} else if (hi == 1){ rgb_map.red=q*255; rgb_map.green=V; rgb_map.blue=p;} else if (hi == 2){ rgb_map.red=p*255; rgb_map.green=V; rgb_map.blue=t;} else if (hi == 3){ rgb_map.red=p*255; rgb_map.green=q; rgb_map.blue=V;} else if (hi == 4){ rgb_map.red=t*255; rgb_map.green=p; rgb_map.blue=V;} else if (hi == 5){ rgb_map.red=V*255; rgb_map.green=p; rgb_map.blue=q;} else printf("ERRORE!"); rgb_int.red = (int)(rgb_map.red*255); rgb_int.green = (int)(rgb_map.green*255); rgb_int.blue = (int)(rgb_map.blue*255); return rgb_int; }
//*************************************// //******** created by mamo139 *********// //*** http://mamo139.altervista.org ***// //*************************************// #include <stdio.h> #include <stdlib.h> #include <string.h> //*** strumenti genstione numeri complessi ***// struct complesso { double r; double i; }; //*** strumenti gestione db int ** crea_matrice(long x, long y); void scrivi_matrice(char * file_name, int ** matrice, long xl, long yl); //*** MAIN ***// int main (void){ char db_name[]="ma"; //*********** PARAMETRI *************// long larghezza = 2000; long altezza = 2000; long deep = 10000; double y1 = 2; double x0 = -2, x1 = 2; double y0 = -2; //**********************************// //aggiustamento parametri double agg_temp; agg_temp=y1; y1=y0*(-1); y0=agg_temp*(-1); //**********************************// int ** matrice; matrice = crea_matrice(larghezza,altezza); //inizio elaborazione immagine long x,y,d,i; double real_x,real_y, colore; struct complesso z,c,temp; for(x=0;x<larghezza;x++){ real_x = ((x1-x0)/larghezza)*x+x0; for(y=0;y<altezza;y++){ real_y = ((y1-y0)/altezza)*y+y0; //analisi di mendelbrot c.r = real_x; c.i = real_y; z.r = 0; z.i = 0; d = 0; for(i=0;i<deep;i++){ if((z.r*z.r)+(z.i*z.i) > 4) { d = i; break; } temp.r = z.r; temp.i = z.i; z.r = (temp.r*temp.r) - (temp.i*temp.i) + c.r; z.i = (temp.r*temp.i)*2 + c.i; } matrice[x][y] = d; } printf("%d%%\n",x*100/larghezza); } scrivi_matrice(db_name,matrice,larghezza,altezza); printf("fine!"); getchar(); return 0; } //****** FUNZIONI *******// int ** crea_matrice(long x, long y){ int ** array; int i, j; array = (int**)malloc(x * sizeof(int *)); for(i=0; i<x; i++) { array[i] = (int*)malloc(y * sizeof(int *)); } int i1,i2; for(i1=0; i1<x; i1++) for (i2=0; i2<y; i2++) array[i1][i2] = 0; return array; } void scrivi_matrice(char * file_name, int ** matrice, long xl, long yl){ FILE *s; s = fopen(file_name,"wb"); int i1,i2; for(i1=0; i1<xl; i1++) for (i2=0; i2<yl; i2++) fprintf(s,"%d%c",matrice[i1][i2],0); fclose(s); }
//*************************************// //******** created by mamo139 *********// //*** http://mamo139.altervista.org ***// //*************************************// #include <stdio.h> #include <stdlib.h> #include <string.h> //*** strumenti genstione numeri complessi ***// struct complesso { double r; double i; }; //*** strumenti gestione db int ** crea_matrice(long x, long y); void scrivi_matrice(char * file_name, int ** matrice, long xl, long yl); //*** MAIN ***// int main (void){ char db_name[]="burn"; //*********** PARAMETRI *************// long larghezza = 2000; long altezza = 2000; long deep = 2000; double y1 = 2; double x0 = -2, x1 = 2; double y0 = -2; //**********************************// //aggiustamento parametri double agg_temp; agg_temp=y1; y1=y0*(-1); y0=agg_temp*(-1); //**********************************// int ** matrice; matrice = crea_matrice(larghezza,altezza); //inizio elaborazione immagine long x,y,d,i; double real_x,real_y, colore; struct complesso z,c,temp; for(x=0;x<larghezza;x++){ real_x = ((x1-x0)/larghezza)*x+x0; for(y=0;y<altezza;y++){ real_y = ((y1-y0)/altezza)*y+y0; //analisi di mendelbrot c.r = real_x; c.i = real_y; z.r = 0; z.i = 0; d = 0; for(i=0;i<deep;i++){ if((z.r*z.r)+(z.i*z.i) > 4) { d = i; break; } temp.r = z.r; temp.i = z.i; if(temp.r<0)temp.r=temp.r*(-1);if(temp.i<0)temp.i=temp.i*(-1); //condizione burningship z.r = (temp.r*temp.r) - (temp.i*temp.i) + c.r; z.i = (temp.r*temp.i)*2 + c.i; } matrice[x][y] = d; } printf("%d%%\n",x*100/larghezza); } scrivi_matrice(db_name,matrice,larghezza,altezza); printf("fine!"); getchar(); return 0; } //****** FUNZIONI *******// int ** crea_matrice(long x, long y){ int ** array; int i, j; array = (int**)malloc(x * sizeof(int *)); for(i=0; i<x; i++) { array[i] = (int*)malloc(y * sizeof(int *)); } int i1,i2; for(i1=0; i1<x; i1++) for (i2=0; i2<y; i2++) array[i1][i2] = 0; return array; } void scrivi_matrice(char * file_name, int ** matrice, long xl, long yl){ FILE *s; s = fopen(file_name,"wb"); int i1,i2; for(i1=0; i1<xl; i1++) for (i2=0; i2<yl; i2++) fprintf(s,"%d%c",matrice[i1][i2],0); fclose(s); }
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> struct complesso { double r; double i; }; //****** MAIN *******// int main (void){ char immagine_name[]="bu"; //*********** PARAMETRI *************// long larghezza = 3000; long altezza = 3000; long deep = 5000; long buddha = 1000000000; double y1 = 2; double x0 = -2, x1 = 2; double y0 = -2; //**********************************// //aggiustamento parametri double agg_temp; agg_temp=y1; y1=y0*(-1); y0=agg_temp*(-1); //**********************************// time_t t; srand((unsigned) time(&t)); long b=0; long x,y; long ** buddha_value; buddha_value = (long**) malloc(larghezza * sizeof(long *)); for(b=0; b<larghezza; b++) buddha_value[b] = (long*) malloc(altezza * sizeof(long)); for(x=0;x<larghezza;x++)for(y=0;y<altezza;y++)buddha_value[x][y]=0; struct complesso *history; history = (struct complesso*)malloc(deep * sizeof(struct complesso)); printf("operazioni iniziali effettuate, inizio cicli!\n"); for(b=0;b<buddha;b++){ //ciclo buddhabrot //inizio elaborazione immagine long x,y,d,i,a; double real_x, real_y, colore; struct complesso z,c,temp; x=(rand())%larghezza; y=(rand())%altezza; real_x = ((x1-x0)/larghezza)*x+x0; real_y = ((y1-y0)/altezza)*y+y0; //analisi di mendelbrot c.r = real_x; c.i = real_y; z.r = 0; z.i = 0; d = 0; for(i=1;i<deep;i++){ if((z.r*z.r)+(z.i*z.i) > 4) { d = i; break; } temp.r = z.r; temp.i = z.i; z.r = (temp.r*temp.r) - (temp.i*temp.i) + c.r; z.i = (temp.r*temp.i)*2 + c.i; history[i].r = z.r; history[i].i = z.i; } //controllo punto dell'insieme di mendelbrot if(d!=0) { for(a=0;a<d;a++){ //disegno la strada del punto x=(long) ((double)(history[a].r-x0)*larghezza/(x1-x0)); y=(long) ((double)(history[a].i-y0)*altezza/(y1-y0)); if(x>0 && x<larghezza && y>0 && y<altezza){ buddha_value[x][y]++; } } } if(b%1000000==0)printf("%d su %d gruppi da 1000.000 cicli completati!\n",b/1000000,buddha/1000000); } //fine buddha //creo db printf("\nCreazione db in corso...\n"); FILE *s; s = fopen(immagine_name,"wb"); for(x=0;x<larghezza;x++) for(y=0;y<altezza;y++){ fprintf(s,"%d%c",buddha_value[x][y],0); } fclose(s); printf("db creato.\n"); printf("fine!"); getchar(); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> struct complesso { double r; double i; }; //****** MAIN *******// int main (void){ char immagine_name[]="bu"; //*********** PARAMETRI *************// long larghezza = 2000; long altezza = 2000; long deep = 1000; long buddha = 10000000; double y1 = 2; double x0 = -2, x1 = 2; double y0 = -2; //**********************************// //aggiustamento parametri double agg_temp; agg_temp=y1; y1=y0*(-1); y0=agg_temp*(-1); //**********************************// time_t t; srand((unsigned) time(&t)); long b=0; long x,y; long ** buddha_value; buddha_value = (long**) malloc(larghezza * sizeof(long *)); for(b=0; b<larghezza; b++) buddha_value[b] = (long*) malloc(altezza * sizeof(long)); for(x=0;x<larghezza;x++)for(y=0;y<altezza;y++)buddha_value[x][y]=0; struct complesso *history; history = (struct complesso*)malloc(deep * sizeof(struct complesso)); printf("operazioni iniziali effettuate, inizio cicli!\n"); for(b=0;b<buddha;b++){ //ciclo buddhabrot //inizio elaborazione immagine long x,y,d,i,a; double real_x, real_y, colore; struct complesso z,c,temp; x=(rand())%larghezza; y=(rand())%altezza; real_x = ((x1-x0)/larghezza)*x+x0; real_y = ((y1-y0)/altezza)*y+y0; //analisi di mendelbrot c.r = real_x; c.i = real_y; z.r = 0; z.i = 0; d = 0; for(i=1;i<deep;i++){ if((z.r*z.r)+(z.i*z.i) > 4) { d = i; break; } temp.r = z.r; temp.i = z.i; z.r = (temp.r*temp.r) - (temp.i*temp.i) + c.r; z.i = (temp.r*temp.i)*2 + c.i; history[i].r = z.r; history[i].i = z.i; } //controllo punto dell'insieme di mendelbrot if(d==0) { for(a=0;a<deep;a++){ //disegno la strada del punto x=(long) ((double)(history[a].r-x0)*larghezza/(x1-x0)); y=(long) ((double)(history[a].i-y0)*altezza/(y1-y0)); if(x>0 && x<larghezza && y>0 && y<altezza){ buddha_value[x][y]++; } } } if(b%1000000==0)printf("%d su %d gruppi da 1000.000 cicli completati!\n",b/1000000,buddha/1000000); } //fine buddha //creo db printf("\nCreazione db in corso...\n"); FILE *s; s = fopen(immagine_name,"wb"); for(x=0;x<larghezza;x++) for(y=0;y<altezza;y++){ fprintf(s,"%d%c",buddha_value[x][y],0); } fclose(s); printf("db creato.\n"); printf("fine!"); getchar(); return 0; }