Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // std headers
- #include <stdlib.h>
- #include <stdio.h>
- #include <assert.h>
- // logic defines
- #define TRUE 1
- #define FALSE 0
- // ascii-brot size
- #define HEIGHT 64
- #define WIDTH 64
- #define MAX_ITERATIONS 255
- int escapeSteps(int pixelX, int pixelY, int zoom);
- int main(int argc, char * argv[]) {
- printf(" UNSW Computing 1 - ASCII-BROT\n");
- int pixelX = 0;
- int pixelY = 0;
- int zoom = 7;
- int iterations = 0;
- while (pixelY < HEIGHT) {
- // iterate through each column
- while (pixelX < WIDTH) {
- // iterate through the whole row, until it reaches the end
- iterations = mandelbrot(pixelX, pixelY, zoom);
- if (iterations == MAX_ITERATIONS) {
- printf("*");
- } else {
- printf(" ");
- }
- pixelX++;
- }
- // where it then goes back to the beginning and moves up a pixel
- printf("\n");
- pixelX = 0;
- pixelY++;
- }
- return EXIT_SUCCESS;
- }
- // Finish off the function below, let me know if you have any questions =)
- int escapeSteps(int pixelX, int pixelY, int zoom) {
- // For now, just to keep things simple, just say that we are going off
- // (0,0) as the centre. Later on, you will have to pass centreX and
- // centreY into the function since you get it from input
- int centreX = 0;
- int centreY = 0;
- // So zoom is the distance between each point on the cartesian plane,
- // so if it was zoom = 1, distance is 2^-1, which is 0.5, so that means
- // that the furthest point to the left or right that you will be testing
- // must be whatever size you want to print (e.g. for hte BMP that will
- // be 512), times the distance; and exact same concept for up and down.
- // So in this case, xIncrements is the distance between each x point,
- // and same for y. We'll just say that they are 1/2^7 for now. Unfortunately,
- // you will need to make your own function which calculates 2^x for you =P
- double xDistance = 1/128.00;
- double yDistance = 1/128.00;
- // Now to get the distance to the up/down/left/right you will go from the centre, think about
- // how the xIncrements and the image size relate to this
- double width = 0;
- double height = 0;
- // Using the height and the width, you can get the points which are your
- // minimums
- double minX = 0;
- double minY = 0;
- // And similarly, get the position of the point, from the pixel ( hint:
- // think about how many xIncrements there will be between the minX and
- // the pixel point
- double x = 0;
- double y = 0;
- // Since you're algorithm for finding number of steps was perfect, I'll just
- // put it here, but it turns out that the first point that you check before
- // updating the point is (0,0), so just I'm also going to just set that
- int iterations = 0;
- double originalX = x;
- double originalY = y;
- double temp = 0;
- x = 0;
- y = 0;
- while (x*x + y*y < 4 && iterations < MAX_ITERATIONS){
- temp = x;
- x = x*x - y*y + originalX;
- y = 2*temp*y + originalY;
- iterations++;
- }
- return iterations;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement