bearbear12345

Untitled

Apr 15th, 2014
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. /*
  2. *
  3. *
  4. */
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <assert.h>
  9. #include <math.h>
  10. #include "mandelbrot.h"
  11.  
  12. #define MAX_ESCAPESTEPS 256
  13.  
  14. int main (int argc, char *argv[]) {
  15.  
  16. double xcentre = 0;
  17. double ycentre = 0;
  18. int z = 8;
  19.  
  20. double pixeldistance = pow(2, -z);
  21.  
  22. // start from the top left of the region
  23. double firstX = (xcentre - 256); //* pixeldistance;
  24. double lastX = (xcentre + 256);
  25. double firstY = (ycentre + 256);
  26. double lastY = (ycentre - 256);
  27. double middleX = (firstX + lastX);
  28. double middleY = (firstY + lastY);
  29.  
  30. printf("midpoint: (%lf,%lf)\n", middleX, middleY);
  31. printf("firstX = %lf\n", firstX);
  32. printf("lastX = %lf\n", lastX);
  33. printf("firstY = %lf\n", firstY);
  34. printf("lastY = %lf\n", lastY);
  35.  
  36. int x;
  37. for (x = -256; x <= 256; x++) {
  38. double y;
  39.  
  40. // printf("%i\n", escapeSteps(x, y));
  41.  
  42.  
  43. for (y = -256*pixeldistance; y <= 256*pixeldistance; y+=pixeldistance) {
  44. printf("(%f,%f)", x, y);
  45.  
  46. // printf("%i\n", escapeSteps(x, y));
  47.  
  48. if (escapeSteps(x, y) < MAX_ESCAPESTEPS) {
  49. printf("*");
  50. } else {
  51. printf(" ");
  52. }
  53. }
  54. printf("\n");
  55. }
  56.  
  57. return EXIT_SUCCESS;
  58. }
  59.  
  60. int escapeSteps (double x, double y) {
  61. int steps = 0;
  62. double real = 0;
  63. double imaginary = 0;
  64. double modSquared = ((real * real) + (imaginary * imaginary));
  65. double newImaginary;
  66. double newReal;
  67. while (modSquared < 4 && steps < MAX_ESCAPESTEPS) {
  68. newImaginary = (2 * imaginary * real)+y;
  69. newReal = ((real * real) - (imaginary * imaginary))+x;
  70. imaginary = newImaginary;
  71. real = newReal;
  72. modSquared = ((newReal * newReal) + (newImaginary * newImaginary));
  73. steps++;
  74. }
  75.  
  76. return steps;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment