visiste: 1793
//*************************************// //******** created by mamo139 *********// //*** http://mamo139.altervista.org ***// //*************************************// #include <stdio.h> #include <windows.h> #include <stdlib.h> #include <conio.h> #include <math.h> int main (void){ FILE *stream; stream = fopen("output.bmp","wb"); unsigned char buffer1[19]="\x42\x4d\x26\xec\x00\x00\x00\x00\x00\x00\x36\x00\x00\x00\x28\x00\x00\x00"; unsigned char buffer2[5]="\xE8\x03\x00\x00"; unsigned char buffer3[5]="\xE8\x03\x00\x00"; unsigned char buffer4[28]="\x01\x00\x18\x00\x00\x00\x00\x00\xf0\xeb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; fwrite(buffer1,sizeof(buffer1)-1,1,stream); fwrite(buffer2,sizeof(buffer2)-1,1,stream); fwrite(buffer3,sizeof(buffer3)-1,1,stream); fwrite(buffer4,sizeof(buffer4),1,stream); printf("header: %d bytes, scritto!\n",(sizeof(buffer1)+sizeof(buffer2)+sizeof(buffer3)+sizeof(buffer4)-3)); long x=0,end=(buffer2[0]+buffer2[1]*256)*(buffer3[0]+buffer3[1]*256); long bytes = end*3; printf("immagine %dx%d\nbyte da scrivere: %d\npartenza ciclo %d\n",(buffer2[0]+buffer2[1]*256),(buffer3[0]+buffer3[1]*256),end*3,x); long latox = (buffer2[0]+buffer2[1]*256),latoy=(buffer3[0]+buffer3[1]*256); long middlex=latox/2, middley=latoy/2; unsigned char *mappa; mappa=(unsigned char *)malloc((end*3) * sizeof(unsigned char)); //disegna mappa bianca e poi il grafico, tarato per 1000x1000 grafico 10x10 for(x=0;x<bytes;x++){//mappa bianca if( (x/3)/latox == middley || (x/3)%latox == middlex ){ mappa[x]=01; mappa[x+1]=01; mappa[x+2]=255; x=x+2; } else mappa[x]=255; } //system("pause"); //***************************************************** CICLO DISEGNO FUNZIONE 1 ***// for(x=0;x<latox;x++){ double graficox = (double) (x-(latox/2))/100; //*** FUNZIONE ***// double graficoy = graficox*graficox; long realy = (long)( (graficoy)*100 + latoy/2 ); if (realy < 1000 && realy > 0 ){ mappa[(latox*realy+x)*3]=00; mappa[((latox*realy+x)*3) +1]=00; mappa[((latox*realy+x)*3) +2]=00; printf("graficox:%f graficoy:%f realx:%d realy:%d scrittura:%d \n",graficox,graficoy,x,realy,((latox*realy+x)*3)); } } //****************************************************** CICLO DISEGNO FUNZIONE 2 ***// for(x=0;x<latox;x++){ double graficox = (double) (x-(latox/2))/100; //*** FUNZIONE ***// double graficoy = graficox*graficox*graficox; long realy = (long)( (graficoy)*100 + latoy/2 ); if (realy < 1000 && realy > 0 ){ mappa[(latox*realy+x)*3]=255; mappa[((latox*realy+x)*3) +1]=00; mappa[((latox*realy+x)*3) +2]=00; printf("graficox:%f graficoy:%f realx:%d realy:%d scrittura:%d \n",graficox,graficoy,x,realy,((latox*realy+x)*3)); } } //****************************************************** CICLO DISEGNO FUNZIONE 3 ***// for(x=0;x<latox;x++){ double graficox = (double) (x-(latox/2))/100; //*** FUNZIONE ***// double graficoy = sin(graficox); long realy = (long)( (graficoy)*100 + latoy/2 ); if (realy < 1000 && realy > 0 ){ mappa[(latox*realy+x)*3]=00; mappa[((latox*realy+x)*3) +1]=255; mappa[((latox*realy+x)*3) +2]=00; printf("graficox:%f graficoy:%f realx:%d realy:%d scrittura:%d \n",graficox,graficoy,x,realy,((latox*realy+x)*3)); } } //****************************************************** CICLO DISEGNO FUNZIONE 4 ***// for(x=0;x<latox;x++){ double graficox = (double) (x-(latox/2))/100; //*** FUNZIONE ***// double graficoy = cos(graficox); long realy = (long)( (graficoy)*100 + latoy/2 ); if (realy < 1000 && realy > 0 ){ mappa[(latox*realy+x)*3]=255; mappa[((latox*realy+x)*3) +1]=255; mappa[((latox*realy+x)*3) +2]=00; printf("graficox:%f graficoy:%f realx:%d realy:%d scrittura:%d \n",graficox,graficoy,x,realy,((latox*realy+x)*3)); } } unsigned char bufff[3]; for(x=0;x<bytes;x++){ bufff[0]=mappa[x]; bufff[1]='\0'; fwrite(bufff,1,1,stream); } /* for(x=0;x<end;x++){ unsigned char buff[3]; long xc = x%(buffer2[0]+buffer2[1]*256); long yc = x/(buffer2[0]+buffer2[1]*256); if( (xc >= (yc-2) && xc <= (yc+2)) || (xc >= (latoy-yc-2) && xc <= (latoy-yc+2))) buff[0] = 255; else buff[0] = 0; if(xc<middlex+2 && xc>middlex-2) buff[1] = 255; else buff[1] = 0; if(yc<middley+2 && yc>middley-2) buff[2] = 255; else buff[2] = 0; fwrite(buff,3,1,stream); } */ fclose(stream); system("output.bmp"); return 1; }