fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. const int WIDTH = 800;
  9. const int HEIGHT = 600;
  10. const int MAX_ITER = 1000;
  11.  
  12. double xmin = -2.0, xmax = 1.5;
  13. double ymin = -2.0, ymax = 1.5;
  14.  
  15. ofstream img("burning_ship.ppm");
  16. img << "P3\n" << WIDTH << " " << HEIGHT << "\n255\n";
  17.  
  18. for (int y = 0; y < HEIGHT; y++) {
  19. for (int x = 0; x < WIDTH; x++) {
  20.  
  21. // mapare pixel -> plan complex
  22. double a = xmin + x * (xmax - xmin) / WIDTH;
  23. double b = ymin + y * (ymax - ymin) / HEIGHT;
  24.  
  25. double zx = 0, zy = 0;
  26. int iter = 0;
  27.  
  28. while (zx*zx + zy*zy <= 4 && iter < MAX_ITER) {
  29. double xtemp = zx*zx - zy*zy + a;
  30. zy = 2 * abs(zx) * abs(zy) + b;
  31. zx = xtemp;
  32. iter++;
  33. }
  34.  
  35. // colorare
  36. int color = (int)(255.0 * iter / MAX_ITER);
  37. img << color << " " << 0 << " " << (255 - color) << " ";
  38. }
  39. img << "\n";
  40. }
  41.  
  42. img.close();
  43. cout << "Imaginea a fost generata: burning_ship.ppm\n";
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0.31s 5324KB
stdin
Standard input is empty
stdout
Imaginea a fost generata: burning_ship.ppm