//*************************************// //******** created by mamo139 *********// //*** http://mamo139.altervista.org ***// //*************************************// #include #include #include #include //*** strumenti gestione file bmp ***// struct bmpfile { long x; long y; char *** matrice; }; char *** crea_bmp(char *nome, long x, long y); struct bmpfile carica_bmp(char *nome); void disegna_bmp(char *nome, char *** array, long x, long y); //************************// struct punto2d { double x; double y; }; long combinazione(long n,long i); long fattoriale(long x); //*** MAIN ***// int main (void){ char img_name[]="out.bmp"; long x = 1000; long y = 1000; long grado_curva = 10; double numero_punti = 30000; struct punto2d * punti; punti = (struct punto2d *) malloc((grado_curva+1) * sizeof(struct punto2d)); punti[0].x=50; punti[0].y=50; punti[1].x=900; punti[1].y=100; punti[2].x=900; punti[2].y=900; punti[3].x=100; punti[3].y=900; punti[4].x=100; punti[4].y=800; punti[5].x=100; punti[5].y=300; punti[6].x=100; punti[6].y=200; punti[7].x=100; punti[7].y=100; punti[8].x=100; punti[8].y=50; punti[9].x=500; punti[9].y=100; punti[10].x=900; punti[10].y=900; char *** mappa = crea_bmp(img_name,x,y); double t = 0; long i; double spread = 1/numero_punti; double comb,pow1,pow2; struct punto2d b; for(t=0;t<=1;t=t+spread){ b.x=0; b.y=0; for(i=0;i<=grado_curva;i++){ comb = combinazione(grado_curva,i); pow1 = pow(t,i); pow2 = pow((1-t),(grado_curva-i)); b.x = b.x + comb*punti[i].x*pow1*pow2; b.y = b.y + comb*punti[i].y*pow1*pow2; } if(b.x>0&&b.x0&&b.y0){ result = result * x; x--; } return result; } //****** FUNZIONI *******// char *** crea_bmp(char *nome, long x, long y){ char buffer [55] = "\x42\x4d\x36\x39\xb1\x00\x00\x00\x00\x00" \ "\x36\x00\x00\x00\x28\x00\x00\x00\xe0\x08\x00\x00\xa8\x06" \ "\x00\x00\x01\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00" \ "\xc4\x0e\x00\x00\xc4\x0e\x00\x00\x00\x00\x00\x00\x00\x00" \ "\x00\x00"; buffer[18] = x%256;//asse x buffer[19] = x/256; buffer[22] = y%256;//asse y buffer[23] = y/256; FILE *stream; stream = fopen(nome,"wb"); fwrite(buffer, 1, 54, stream); fclose(stream); char *** array; int i, j, h; array = (char***)malloc(x * sizeof(char *)); for(i=0; i