Advertisement
pierrotdu18

Untitled

Aug 23rd, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. #include <math.h>
  2. #include <time.h>
  3. #include "class_complex.h"
  4.  
  5. #define X_MIN -2
  6. #define X_MAX 2.1
  7. #define Y_MIN -1.6
  8. #define Y_MAX 2
  9. #define ZOOM 80
  10. #define ITERATIONS 50
  11.  
  12.  
  13. #define IMAGE_X (X_MAX - X_MIN) * ZOOM
  14. #define IMAGE_Y (Y_MAX - Y_MIN) * ZOOM
  15.  
  16. using namespace std;
  17.  
  18. int rand_int_a_b(int a, int b)
  19. {
  20.     return rand()%(b-a) +a;
  21. }
  22.  
  23. static int revertedScreen = 0;
  24.  
  25. inline void setPixel(int x, int y, int r, int g, int b) {
  26.     if(revertedScreen)
  27.         x = 319-x, y = 239-y;
  28.     if(is_cx) { /* Inverted color for CX since it is ugly and sharpen */
  29.         unsigned short* p = (unsigned short*)(SCREEN_BASE_ADDRESS + (x << 1) + (y << 9) + (y << 7));
  30.         *p = (((255-r) >> 3) << 11) | (((255-g) >> 2) << 5) | ((255-b) >> 3);
  31.     }
  32.     else {
  33.         unsigned char* p = (unsigned char*)(SCREEN_BASE_ADDRESS  + ((x >> 1) + (y << 7) + (y << 5)));
  34.         char c = (r>>4)/3 + (g>>4)/3 + (b>>4)/3;
  35.         *p = (x & 1) ? ((*p & 0xF0) | c) : ((*p & 0x0F) | (c << 4));
  36.     }
  37. }
  38.  
  39. void fillRect(int x1, int y1, int x2, int y2, int c) {
  40.     for(; x1 < x2; ++x1)
  41.         for(; y1 < y2; ++y1)
  42.             setPixel(x1, y1, c, c, c);
  43. }
  44.  
  45. int main()
  46. {  
  47.     srand(time(NULL));
  48.     int R,G,B;
  49.     int x, y, i;
  50.     int re, im;
  51.    
  52.     bool reMustBeZero = false;
  53.     bool imMustBeZero = false;
  54.     while (true)
  55.     {
  56.         R = rand_int_a_b(5,30);
  57.         G = rand_int_a_b(5,30);
  58.         B = rand_int_a_b(5,30);
  59.        
  60.         re = reMustBeZero?0:rand_int_a_b(-25000,25000);
  61.         im = imMustBeZero?0:rand_int_a_b(-25000,25000);
  62.        
  63.         complex C(((double)re/10000), ((double)im/10000));
  64.  
  65.         x = 0;
  66.         i = 0;
  67.         while (x < IMAGE_X)
  68.         {
  69.             y = 0;
  70.            
  71.             while (y < IMAGE_Y)
  72.             {
  73.                 complex z((double)x / ZOOM + X_MIN,(double)y / ZOOM + Y_MIN);
  74.                
  75.                 i = 0;
  76.                 do
  77.                 {
  78.                     z = z*z + C;
  79.                     i++;
  80.                 }
  81.                 while (z.norm() < 100 && i < ITERATIONS);
  82.                
  83.                 if ((x>0 && x<=320) && (y>0 && y<=240))
  84.                     i==ITERATIONS?setPixel(x-1,y-1, 0, 0, 0):setPixel(x-1, y-1, (int)(R*i)%256,(int)(G*i)%256,(int)(B*i)%256);
  85.                 y++;
  86.             }
  87.             x++;
  88.         }
  89.         bool end = false;
  90.         imMustBeZero = false;
  91.         reMustBeZero = false;
  92.         while (!end)
  93.         {  
  94.             if (isKeyPressed(KEY_NSPIRE_RIGHT))
  95.             {  
  96.                 end = true;
  97.             }
  98.             else if (isKeyPressed(KEY_NSPIRE_ESC))
  99.             {  
  100.                 return 0;
  101.             }
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement