Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h> // rand()
- #include <math.h> // rint()
- #include <jpeglib.h>
- //fixed. should be parsed from commandline or defaulted to max screen dimensions
- #define xmax 1024
- #define ymax 768
- //unused yet. should be parsed from chaos.conf file somewhere in /local/share/ or smth.
- //dimensions of vga screen
- #define dxmax 320
- #define dymax 240
- #define vgamode 'G640x480x16'
- unsigned char ns=12;
- int xnn=0,ynn=0,xp=0,yp=0,xk=0,yk=0,dx=0,dy=0,x=0,y=0;
- float s11[50], p[50],
- s12[50],
- s13[50],
- s23[50],
- s22[50],
- s21[50],
- s31[50],
- s41[50];
- unsigned char ekran[xmax+1][ymax+1];
- unsigned char image_buffer[xmax*ymax+1]; /*JSAMPLE*/
- //char vgamode[20]="G640x480x256";
- int it ;
- double my_rand(float a) {
- return (1+(1.0*a*rand()/(RAND_MAX+1.0)));
- }
- double my_frand() {
- return (rand()/(RAND_MAX+1.0));
- }
- void plot(int a, int b) {
- ekran[a][b]++;
- }
- void cls() { int i,j;
- for(i=0;i<xmax;i++){
- for(j=0;j<ymax;j++){
- ekran[i][j]=0;
- }
- }
- }
- //extern JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */
- //JSAMPLE * ekran; /* Points to large array of R,G,B-order data */
- //int image_height=xmax; /* Number of rows in image */
- //int image_width=ymax; /* Number of columns in image */
- void write_JPEG_file (char filename[255], int quality)
- { struct jpeg_compress_struct cinfo;
- struct jpeg_error_mgr jerr;
- FILE * outfile; /* target file */
- JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
- int row_stride; /* physical row width in image buffer */
- cinfo.err = jpeg_std_error(&jerr);
- jpeg_create_compress(&cinfo);
- if ((outfile = fopen(filename, "wb")) == NULL) {
- fprintf(stderr, "can't open", filename,".jpg\n"); exit(1);
- }
- jpeg_stdio_dest(&cinfo, outfile);
- cinfo.image_width = xmax; /* image width and height, in pixels */
- cinfo.image_height = ymax;
- cinfo.input_components = 1; /* # of color components per pixel */
- cinfo.in_color_space = JCS_GRAYSCALE; /* colorspace of input image */
- jpeg_set_defaults(&cinfo);
- //jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
- jpeg_start_compress(&cinfo, TRUE);
- row_stride = xmax * 1; /* JSAMPLEs per row in image_buffer */
- while (cinfo.next_scanline < cinfo.image_height) {
- row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
- (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
- }
- jpeg_finish_compress(&cinfo);
- fclose(outfile);
- jpeg_destroy_compress(&cinfo);
- }
- void dump(char filename[255]) { int i,j; unsigned char a;
- for(j=0;j<ymax;j++) {
- for(i=0;i<xmax;i++) {
- image_buffer[i+j*xmax]=ekran[i][j];
- }
- }
- write_JPEG_file ("/dev/stdout", 50);
- }
- void g545() { double a;
- if (xp>xk) { a=xp; xp=xk; xk=a; a=yp; yp=yk; yk=a; }
- dx=fabs(xk-xp); dy=fabs(yk-yp);
- if (dy>dx) {
- if (yp>yk) { a=xp; xp=xk; xk=a; a=yp; yp=yk; yk=a; }
- a=(xk-xp)/(yk-yp);
- for (y=yp;y<=yk;y+=5) {
- x=xp+a*(y-yp);
- } /* next y */
- }
- else {
- if (xp>xk) { a=xp; xp=xk; xk=a; a=yp; yp=yk; yk=a; }
- a=(yk-yp)/(xk-xp);
- for (x=xp;x<=xk;x+=8) { y=yp+a*(x-xp);} /* next x */
- }
- }
- void g360(){ int i; double r1,r2,r3,xx[5],yy[5];
- for (i=1;i<=ns;i++){
- r1=my_frand()*(xmax);
- r2=my_frand()*(xmax);
- r3=my_frand()*(xmax);
- s11[i]=(r2-r1)/(xmax);
- s12[i]=(r3-r1)/(ymax);
- s13[i]=r1;
- r1=my_frand()*(ymax);
- r2=my_frand()*(ymax);
- r3=my_frand()*(ymax);
- s21[i]=(r2-r1)/(xmax);
- s22[i]=(r3-r1)/(ymax);
- s23[i]=r1;
- xx[0]= 0*s11[i]+ 0*s12[i]+s13[i];
- yy[0]= 0*s21[i]+ 0*s22[i]+s23[i];
- xx[1]=xmax*s11[i]+ 0*s12[i]+s13[i];
- yy[1]=xmax*s21[i]+ 0*s22[i]+s23[i];
- xx[2]=xmax*s11[i]+ymax*s12[i]+s13[i];
- yy[2]=xmax*s21[i]+ymax*s22[i]+s23[i];
- xx[3]= 0*s11[i]+ymax*s12[i]+s13[i];
- yy[3]= 0*s21[i]+ymax*s22[i]+s23[i];
- xp=xx[0];
- yp=yy[0];
- xk=xx[1];
- yk=yy[1];
- g545();
- xp=xx[2];
- yp=yy[2];
- xk=xx[1];
- yk=yy[1];
- g545();
- xp=xx[2];
- yp=yy[2];
- xk=xx[3];
- yk=yy[3];
- g545();
- xp=xx[0];
- yp=yy[0];
- xk=xx[3];
- yk=yy[3];
- g545();
- } /* next i */
- }
- void iteration() {
- }
- void randomize() {
- ns=2+(int)(15*my_frand());
- it=it*ns;
- }
- int main(){ int i=0,k=0,a=0,h=0,q=0; float z=0 ; double pp=0,r=0; char filename[16] ;
- srand((int)time(NULL));
- cls();
- q=0;
- it=10000;
- randomize();
- g360();
- cls();
- pp=0;
- for (i=1;i<=ns;i++) {
- p[i]=fabs(s11[i]*s22[i]-s21[i]*s12[i])+0.3;
- pp+=p[i];
- }
- z=0;
- for (i=1;i<=ns;i++) {
- z=z+p[i];
- p[i]=z/pp;
- }
- x=0;
- ynn=0;
- xnn=0;
- z=0;
- for (r=1;r<(10*ns)*100000;r++) {
- z=rand()/(RAND_MAX+1.0);
- i=1;
- // while (z>=p[i] && i!=ns) {i++;}
- switch(ns%8){
- case 0: if (z>=p[i]) {i++;};
- case 32: if (z>=p[i]) {i++;};
- case 31: if (z>=p[i]) {i++;};
- case 30: if (z>=p[i]) {i++;};
- case 29: if (z>=p[i]) {i++;} else goto found;
- case 28: if (z>=p[i]) {i++;};
- case 27: if (z>=p[i]) {i++;};
- case 26: if (z>=p[i]) {i++;};
- case 25: if (z>=p[i]) {i++;};
- case 24: if (z>=p[i]) {i++;};
- case 23: if (z>=p[i]) {i++;};
- case 22: if (z>=p[i]) {i++;} else goto found;
- case 21: if (z>=p[i]) {i++;};
- case 20: if (z>=p[i]) {i++;};
- case 19: if (z>=p[i]) {i++;};
- case 18: if (z>=p[i]) {i++;};
- case 17: if (z>=p[i]) {i++;};
- case 16: if (z>=p[i]) {i++;};
- case 15: if (z>=p[i]) {i++;} else goto found;
- case 14: if (z>=p[i]) {i++;};
- case 13: if (z>=p[i]) {i++;};
- case 12: if (z>=p[i]) {i++;};
- case 11: if (z>=p[i]) {i++;};
- case 10: if (z>=p[i]) {i++;};
- case 9: if (z>=p[i]) {i++;};
- case 8: if (z>=p[i]) {i++;};
- case 7: if (z>=p[i]) {i++;} else goto found;
- case 6: if (z>=p[i]) {i++;};
- case 5: if (z>=p[i]) {i++;};
- case 4: if (z>=p[i]) {i++;};
- case 3: if (z>=p[i]) {i++;};
- case 2: if (z>=p[i]) {i++;};
- found: }
- x=xnn;
- xnn=xnn*s11[i]+ynn*s12[i]+s13[i];
- ynn= x*s21[i]+ynn*s22[i]+s23[i];
- //moved x=xnn;
- if (xnn<xmax && xnn>0 & ynn>0 && ynn<ymax) { ekran[(int)xnn][(int)ynn]++; }
- }
- q++; sprintf (filename, "%d.jpg",q) ;dump(filename);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement