예제 #1
0
	static bits8 blackOrWhite (int position, double x, double y, int z) {

	   bits8 byte = 0;
	   double xPosition = (position % (SIZE));// BYTES_PER_PIXEL)
	   double yPosition = (position / (SIZE));
	   double xPoint = (xPosition - CENTREPOINT + (x / pow(2,-z))) * pow(2, -z);
	   double yPoint = (yPosition - CENTREPOINT + (y / pow(2,-z))) * pow(2, -z);
	   if (escapeSteps(xPoint, yPoint) == 256) {
	      byte = WHITE;
	   } else {
	      byte = escapeSteps(xPoint,yPoint);
	   }

	   return byte;
	}
예제 #2
0
void mandelBitmap(char *image, double x, double y, int zoom) {
    double pixelDistance = pow(2, -zoom);
    double bottom = y - pixelDistance * (IMAGE_HEIGHT / 2);
    double left = x - pixelDistance * (IMAGE_WIDTH / 2);

    bitmapHeader(image);
    int offset = BMP_HEADER_SIZE;

    int row = 0;
    while (row < IMAGE_HEIGHT) {
        int col = 0;
        while (col < IMAGE_WIDTH) {
            int steps = escapeSteps(
                left + pixelDistance * col,
                bottom + pixelDistance * row);

            image[offset] = stepsToBlue(steps);
            image[offset + 1] = stepsToGreen(steps);
            image[offset + 2] = stepsToRed(steps);

            offset += 3;
            col += 1;
        }

        row += 1;
    }
}
예제 #3
0
int main (int argc, char *argv[]) {
   printf ("Testing mandelbrot.c\n");
   printf("%d\n", escapeSteps (-0.825, -0.825));
   testEscapeSteps();
   printf ("All tests passed.  You are Awesome!\n\n");

   printmandle();
   
   return EXIT_SUCCESS;
}
예제 #4
0
void serveBMP (int socket, char * request) {
 
   char* message;
   // the http response header
   message = "HTTP/1.0 200 OK\r\n"
                "Content-Type: image/bmp\r\n"
                "\r\n";
   printf ("about to send=> %s\n", message);
   write (socket, message, strlen (message));
   
   int numBytes = (SIZE * SIZE * BYTES_PER_PIXEL);
   unsigned char bmp[(SIZE * BYTES_PER_PIXEL * SIZE)] = {0,};

   writeHeader (socket);
   triordinate input;
   input = extract (request);
//   printf("centre: %lf, %lf. zoom %d\n", input.x, input.y, input.z);

//   unsigned char byte = 0; 
   int height = 0;
   int width = 0;
   double increment;
   increment = 1.0 / (positivePower(2.0, input.z));
//   printf("zoom: %d\n", input.z);
//   printf("increment: %lf\n", increment);

   double x = input.x - 256 * increment; // far left side
   double y = input.y - 256 * increment; // bottom level
//   printf("lower left corner: %lf, %lf\n", x, y);
   int steps = 0;
   double xCounter = x;
   int counter = 0;
   while (height < SIZE) {
      width = 0;
      xCounter = x;
      while (width < SIZE) {
         steps = escapeSteps(xCounter, y);
         bmp[counter] = stepsToBlue(steps);
         counter ++;
         bmp[counter] = stepsToGreen(steps);
         counter ++;
         bmp[counter] = stepsToRed(steps);
         counter ++;
         width ++;
         xCounter = xCounter + increment;
      }
   y = y + increment;  
   height ++;
   }

   assert (sizeof(bmp) == numBytes);
   write (socket, bmp, sizeof(bmp));
}
예제 #5
0
void serveBMP (int socket, double x, double y, double zoom, int valuesScanned) {
   char* message;
   // first send the http response header

   // (if you write stings one after another like this on separate
   // lines the c compiler kindly joins them togther for you into
   // one long string)
   if (valuesScanned != 3) {
      message =
         "HTTP/1.0 200 Found\n"
         "Content-Type: text/html\n"
         "\n";
      printf ("about to send=> %s\n", message);
      write (socket, message, strlen (message));

      message =
         "<!DOCTYPE html>\n"
         "<script src=\"https://almondbread.cse.unsw.edu.au/tiles.js\"></script>"
         "\n";
      write (socket, message, strlen (message));
   } else {
      message = "HTTP/1.0 200 OK\r\n"
                  "Content-Type: image/bmp\r\n"
                  "\r\n";
      printf ("about to send=> %s\n", message);
      write (socket, message, strlen (message));

   // now send the BMP
   writeHeader (socket);
   double zoom_x = x - 1.5/zoom;
   double zoom_y = y - 2.0/zoom;
//   double seed[2] = {zoom_x,zoom_y};
   int colPos = 0;
   int colRow = 0;
   while (colPos < SIZE) {
      while (colRow < SIZE) {
         int steps = escapeSteps(zoom_x, zoom_y);
         unsigned char colour[3] =
         {0, steps, 0};
         write (socket, colour, sizeof(colour));
         zoom_x = zoom_x + 2.0/zoom/256.0;
         colRow ++;
      }
      zoom_y = zoom_y + 2.0/zoom/256.0;
      zoom_x = x - 1.5/zoom;
      colPos ++;
      colRow = 0;
   }
   }
}
예제 #6
0
//--------Delivers BMP Image---------//
void serveBMP (int socket, char request[]) {
    int row = -SIZE/2;    //Defines where each row should start
    int col = -SIZE/2;    //Defines where first column should start

    int iterations = 0;   //Count the amount of iterations needed
                          //to escape the set
    
    complex current;      //The current coodinates of the point
                          //being tested

    int colCounter = 0;   //Current collum
    int rowCounter = 0;   //Current row
    
    int zoom = 0;         //The zoom level of the image
    double xMiddle = 0;   //The x (real) component of the 
                          //center of the image
    double yMiddle = 0;   //The y (imaginary) component of the 
                          //center of the image

    bits8 byte = 0;       //Intensity of color from each sub-pixel
    
    writeHTTPHeader(socket);
    writeBMPHeader(socket);

    //get coordinates from URL
    sscanf (request, "GET /tile_x%lf_y%lf_z%d.bmp",
            &xMiddle,&yMiddle,&zoom);

    //print each pixel out
    while (rowCounter < SIZE){
        current.y = yMiddle + row*exp2(-1*zoom) + exp2(-1*zoom)/2;
        while (colCounter < SIZE){
            current.x = xMiddle + col*exp2(-1*zoom) + exp2(-1*zoom)/2;

            iterations = escapeSteps(current.x,current.y);

            writePixel (socket,iterations, byte);

            col++;
            colCounter++;
        }
        col = -SIZE/2;
        colCounter = 0;

        row++;
        rowCounter++;
    }

}
예제 #7
0
void printmandle(void) {
//x: (-2.5, 1)
//y: (-1, 1)
	Coordinate draw;
	for ( draw.y = -1; draw.y <= 1; draw.y+=0.02) {
		for ( draw.x = -2.5; draw.x <= 1; draw.x+=0.02) {
			if( escapeSteps(draw.x, draw.y) < MAX_STEPS ) {
				printf(" ");
			}
			else {
				printf("*");
			}
		}
		printf("\n");
	}
}
예제 #8
0
void generateBitmapImage(unsigned char bmpData[],
                         double centreX, double centreY, int zoom) {
    int drawingX;
    int drawingY;

    // The index of the desired row
    int bitmapRow;
    // The index of the desired column
    int bitmapColumn;

    double scaledX, scaledY;
    double scale;

    int iterations;

    scale = 1 / power(2, zoom);

    drawingY = 0;
    while (drawingY < BITMAP_HEIGHT) {
        drawingX = 0;
        while (drawingX < BITMAP_WIDTH) {
            // centering
            scaledX = centreX -(BITMAP_WIDTH / 2) * scale;
            scaledY = centreY -(BITMAP_HEIGHT / 2) * scale;

            // calculate current point
            scaledX += drawingX * scale;
            scaledY += drawingY * scale;

            bitmapRow = drawingY *
                            (BITMAP_WIDTH * BITMAP_BYTES_PER_PIXEL);
            bitmapColumn = drawingX * BITMAP_BYTES_PER_PIXEL;
            iterations = escapeSteps(scaledX, scaledY);
            bmpData[bitmapRow + bitmapColumn] = stepsToBlue(iterations);
            bmpData[bitmapRow + bitmapColumn + 1] = stepsToGreen(iterations);;
            bmpData[bitmapRow + bitmapColumn + 2] = stepsToRed(iterations);;

            drawingX++;
        }
        drawingY++;
    }
}
예제 #9
0
static void serveBMP (int socket, triordinate dat) {
    char* message;
    
    // first send the http response header
    // (if you write stings one after another like this on separate
    // lines the c compiler kindly joins them togther for you into
    // one long string)
    message = "HTTP/1.0 200 OK\r\n"
    "Content-Type: image/bmp\r\n"
    "\r\n";
    printf ("about to send=> %s\n", message);
    if(write(socket, message, strlen (message)) == 1){};
    
    writeHeader(socket);
    
    int counterX = 0;
    int counterY = -1;
    unsigned char byte[1];
    int steps = 0;
    double dBetweenPixels = pow(2, (-1*dat.z));
    double currentX = dat.x - 0.5*dBetweenPixels*(SIZE+1);
    double currentY = dat.y - 0.5*dBetweenPixels*(SIZE+1);
    
    while (counterY < SIZE) {
        currentX = dat.x - 0.5*dBetweenPixels*(SIZE+1);
        while (counterX < SIZE){
            steps = escapeSteps(currentX, currentY);
            byte[0] = stepsToBlue(steps);
            if(write(socket, byte, sizeof byte) == 1){};
            byte[0] = stepsToGreen(steps);
            if(write(socket, byte, sizeof byte) == 1){};
            byte[0] = stepsToRed(steps);
            if(write(socket, byte, sizeof byte) == 1){};
            
            currentX += dBetweenPixels;
            counterX++;
        }
        counterX = 0;
        currentY += dBetweenPixels;
        counterY++;
    }
}
예제 #10
0
int main(int argc, char *argv[]){
while(overall<80){

        count = 0;
        x= -2;
    while( count < 80 ){
            if (( escapeSteps(x,y) == 256)){
               printf("*");
            }
           else{
            printf(" ");
           }

           x+= 0.05;
           count ++;

        }
   overall++;
   y-=0.05;
   printf("\n");
}
return EXIT_SUCCESS;
}
예제 #11
0
int main (int argc, char *argv[]) {

    assert (sizeof(bits8)  == 1);
    assert (sizeof(bits16) == 2);
    assert (sizeof(bits32) == 4);

    FILE *outputFile;
    outputFile = fopen(BMP_FILE, "wb");
    assert ((outputFile!=NULL) && "Cannot open file");
    writeHeader(outputFile);

    printf ("generating mandelbrot picture");

    int numBytes = (SIZE * SIZE * BYTES_PER_PIXEL);
    int pos = 0;
    bits8 byte;
    byte = BLACK;

    int xcoord = -256;
    int ycoord = -256;
    double zre;
    double zim;
    int escape;
    int red = 0;
    int green = 0;
    int blue = 0;

    while (pos < numBytes) {
        int printno;

        zre = xcoord/256.000000000000000 - 0.5;
        zim = ycoord/256.000000000000000;
        escape = escapeSteps(zre, zim);

        if(escape < BOUNDED) {
            red = BLACK;
            green = BLACK;
            blue = BLACK;
        } else {
            red = stepsToRed(escape);
            green = stepsToGreen(escape);
            blue = stepsToBlue(escape);
        }

        for (printno = 0; printno < BYTES_PER_PIXEL; printno++) {
            if (printno == 0) {
                byte = red;
            } else if (printno == 1){
                byte = green;
            } else if (printno == 2){
                byte = blue;
            }
            fwrite (&byte, sizeof byte, 1, outputFile);
            pos++;
        }

        xcoord = xcoord + 1;
        if (pos%SIZE == 0) {
             xcoord = -256;
            ycoord = ycoord + 1;
        }
    }

    fclose(outputFile);


    return EXIT_SUCCESS;
}
예제 #12
0
void serveBMP (int socket) {
   char* message;

   // first send the http response header

   // (if you write stings one after another like this on separate
   // lines the c compiler kindly joins them togther for you into
   // one long string)
   message = "HTTP/1.0 200 OK\r\n"
                "Content-Type: image/bmp\r\n"
                "\r\n";
   printf ("about to send=> %s\n", message);
   write (socket, message, strlen (message));

   // now send the BMP
   unsigned char bmp[FILE_SIZE] = {
     0x42,0x4d,0x63,0x00,0x0c,0x00,0x00,0x00,
     0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
     0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x02,
     0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x0c,0x00,0xc3,0x0e,
     0x00,0x00,0xc3,0x0e,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00};

    int numBytes = (SIZE * SIZE * BYTES_PER_PIXEL);
    int pos = 0;

    int xcoord = -256;
    int ycoord = -256;
    double zre;
    double zim;
    int escape;
    int bmpcount = 54;
    int zoom = 1;

    while (zurl != 0) {
      zoom = 2*zoom;
      zurl = zurl - 1;
    }
    zoom = zoom*256.000000000000000;

    while (pos < numBytes) {

        zre = xcoord/zoom + xurl;
        zim = ycoord/zoom + yurl;
        escape = escapeSteps(zre, zim);

        if(escape == BOUNDED) {
           bmp[bmpcount] = BLACK;
           bmp[bmpcount + 1] = BLACK;
           bmp[bmpcount + 2] = BLACK;
        } else {
           bmp[bmpcount] = stepsToRed(escape);
           bmp[bmpcount + 1] = stepsToGreen(escape);
           bmp[bmpcount + 2] = stepsToBlue(escape);
        }

        pos +=3;
        bmpcount +=3;

        xcoord = xcoord + 1;
        if (pos%SIZE == 0) {
             xcoord = -256;
            ycoord = ycoord + 1;
        }
    }
    write (socket, bmp, sizeof(bmp));
}
예제 #13
0
static void testEscapeSteps(void) {
   printf (" Testing escapeTests ...\n");
   printf (
     "  (using a few sample unit tests only - the automarker "
     "will use more tests)\n"
   );

   assert (escapeSteps (100.0, 100.0) == 1);
   assert (escapeSteps (0.0, 0.0)     == 256);

   assert (escapeSteps (-1.5000000000000, -1.5000000000000) == 1);
   assert (escapeSteps (-1.4250000000000, -1.4250000000000) == 1);
   assert (escapeSteps (-1.3500000000000, -1.3500000000000) == 2);
   assert (escapeSteps (-1.2750000000000, -1.2750000000000) == 2);
   assert (escapeSteps (-1.2000000000000, -1.2000000000000) == 2);
   assert (escapeSteps (-1.1250000000000, -1.1250000000000) == 3);
   assert (escapeSteps (-1.0500000000000, -1.0500000000000) == 3);
   assert (escapeSteps (-0.9750000000000, -0.9750000000000) == 3);
   assert (escapeSteps (-0.9000000000000, -0.9000000000000) == 3);
   assert (escapeSteps (-0.8250000000000, -0.8250000000000) == 4);
   assert (escapeSteps (-0.7500000000000, -0.7500000000000) == 4);
   assert (escapeSteps (-0.6750000000000, -0.6750000000000) == 6);
   assert (escapeSteps (-0.6000000000000, -0.6000000000000) == 12);
   assert (escapeSteps (-0.5250000000000, -0.5250000000000) == 157);
   assert (escapeSteps (-0.4500000000000, -0.4500000000000) == 256);
   assert (escapeSteps (-0.3750000000000, -0.3750000000000) == 256);
   assert (escapeSteps (-0.3000000000000, -0.3000000000000) == 256);
   assert (escapeSteps (-0.2250000000000, -0.2250000000000) == 256);
   assert (escapeSteps (-0.1500000000000, -0.1500000000000) == 256);
   assert (escapeSteps (-0.0750000000000, -0.0750000000000) == 256);
   assert (escapeSteps (-0.0000000000000, -0.0000000000000) == 256);

   assert (escapeSteps (-0.5400000000000, 0.5600000000000) == 256);
   assert (escapeSteps (-0.5475000000000, 0.5650000000000) == 58);
   assert (escapeSteps (-0.5550000000000, 0.5700000000000) == 28);
   assert (escapeSteps (-0.5625000000000, 0.5750000000000) == 22);
   assert (escapeSteps (-0.5700000000000, 0.5800000000000) == 20);
   assert (escapeSteps (-0.5775000000000, 0.5850000000000) == 15);
   assert (escapeSteps (-0.5850000000000, 0.5900000000000) == 13);
   assert (escapeSteps (-0.5925000000000, 0.5950000000000) == 12);
   assert (escapeSteps (-0.6000000000000, 0.6000000000000) == 12);

   assert (escapeSteps (0.2283000000000, -0.5566000000000) == 20);
   assert (escapeSteps (0.2272500000000, -0.5545000000000) == 19);
   assert (escapeSteps (0.2262000000000, -0.5524000000000) == 19);
   assert (escapeSteps (0.2251500000000, -0.5503000000000) == 20);
   assert (escapeSteps (0.2241000000000, -0.5482000000000) == 20);
   assert (escapeSteps (0.2230500000000, -0.5461000000000) == 21);
   assert (escapeSteps (0.2220000000000, -0.5440000000000) == 22);
   assert (escapeSteps (0.2209500000000, -0.5419000000000) == 23);
   assert (escapeSteps (0.2199000000000, -0.5398000000000) == 26);
   assert (escapeSteps (0.2188500000000, -0.5377000000000) == 256);
   assert (escapeSteps (0.2178000000000, -0.5356000000000) == 91);
   assert (escapeSteps (0.2167500000000, -0.5335000000000) == 256);

   assert (escapeSteps (-0.5441250000000, 0.5627500000000) == 119);
   assert (escapeSteps (-0.5445000000000, 0.5630000000000) == 88);
   assert (escapeSteps (-0.5448750000000, 0.5632500000000) == 83);
   assert (escapeSteps (-0.5452500000000, 0.5635000000000) == 86);
   assert (escapeSteps (-0.5456250000000, 0.5637500000000) == 74);
   assert (escapeSteps (-0.5460000000000, 0.5640000000000) == 73);
   assert (escapeSteps (-0.5463750000000, 0.5642500000000) == 125);
   assert (escapeSteps (-0.5467500000000, 0.5645000000000) == 75);
   assert (escapeSteps (-0.5471250000000, 0.5647500000000) == 60);
   assert (escapeSteps (-0.5475000000000, 0.5650000000000) == 58);

   assert (escapeSteps (0.2525812510000, 0.0000004051626) == 60);
   assert (escapeSteps (0.2524546884500, 0.0000004049095) == 61);
   assert (escapeSteps (0.2523281259000, 0.0000004046564) == 63);
   assert (escapeSteps (0.2522015633500, 0.0000004044033) == 65);
   assert (escapeSteps (0.2520750008000, 0.0000004041502) == 67);
   assert (escapeSteps (0.2519484382500, 0.0000004038971) == 69);
   assert (escapeSteps (0.2518218757000, 0.0000004036441) == 72);
   assert (escapeSteps (0.2516953131500, 0.0000004033910) == 74);
   assert (escapeSteps (0.2515687506000, 0.0000004031379) == 77);
   assert (escapeSteps (0.2514421880500, 0.0000004028848) == 81);
   assert (escapeSteps (0.2513156255000, 0.0000004026317) == 85);
   assert (escapeSteps (0.2511890629500, 0.0000004023786) == 89);
   assert (escapeSteps (0.2510625004000, 0.0000004021255) == 94);
   assert (escapeSteps (0.2509359378500, 0.0000004018724) == 101);
   assert (escapeSteps (0.2508093753000, 0.0000004016193) == 108);
   assert (escapeSteps (0.2506828127500, 0.0000004013662) == 118);
   assert (escapeSteps (0.2505562502000, 0.0000004011132) == 131);
   assert (escapeSteps (0.2504296876500, 0.0000004008601) == 150);
   assert (escapeSteps (0.2503031251000, 0.0000004006070) == 179);
   assert (escapeSteps (0.2501765625500, 0.0000004003539) == 235);
   assert (escapeSteps (0.2500500000000, 0.0000004001008) == 256);

   assert (escapeSteps (0.3565670191423, 0.1094322101123) == 254);
   assert (escapeSteps (0.3565670191416, 0.1094322101120) == 255);
   assert (escapeSteps (0.3565670191409, 0.1094322101118) == 256);
   assert (escapeSteps (0.3565670950000, 0.1094322330000) == 222);
   assert (escapeSteps (0.3565670912300, 0.1094322318625) == 222);
   assert (escapeSteps (0.3565670874600, 0.1094322307250) == 222);
   assert (escapeSteps (0.3565670836900, 0.1094322295875) == 222);
   assert (escapeSteps (0.3565670799200, 0.1094322284500) == 222);
   assert (escapeSteps (0.3565670761500, 0.1094322273125) == 222);
   assert (escapeSteps (0.3565670723800, 0.1094322261750) == 222);
   assert (escapeSteps (0.3565670686100, 0.1094322250375) == 223);
   assert (escapeSteps (0.3565670648400, 0.1094322239000) == 223);
   assert (escapeSteps (0.3565670610700, 0.1094322227625) == 224);
   assert (escapeSteps (0.3565670573000, 0.1094322216250) == 225);
   assert (escapeSteps (0.3565670535300, 0.1094322204875) == 256);
   assert (escapeSteps (0.3565670497600, 0.1094322193500) == 256);
   assert (escapeSteps (0.3565670459900, 0.1094322182125) == 237);
   assert (escapeSteps (0.3565670422200, 0.1094322170750) == 233);
   assert (escapeSteps (0.3565670384500, 0.1094322159375) == 232);
   assert (escapeSteps (0.3565670346800, 0.1094322148000) == 232);
   assert (escapeSteps (0.3565670309100, 0.1094322136625) == 232);
   assert (escapeSteps (0.3565670271400, 0.1094322125250) == 233);
   assert (escapeSteps (0.3565670233700, 0.1094322113875) == 234);
   assert (escapeSteps (0.3565670196000, 0.1094322102500) == 243);


   printf (" ... escapeSteps tests passed!\n");
}