Advertisement
Guest User

Untitled

a guest
Jun 5th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <opencv/cv.h>
  3. #include <opencv/highgui.h>
  4. #include <math.h>
  5.  
  6. int floatsign(double x, double y)
  7. {  
  8.     double px = (0.5 + x * pow(2, -53));
  9.     double py = (0.5 + y * pow(2, -53));
  10.     double value = (12 - px)*(24 - py) - (12 - py)*(24 - px);
  11.  
  12.     if(value == 0)
  13.         return 0;
  14.     else if(value > 0)
  15.         return 1;
  16.     else if(value < 0)
  17.         return -1;
  18. }
  19.  
  20. int main(int argc, char** argv)
  21. {
  22.     IplImage* image = cvCreateImage(cvSize(256,256), IPL_DEPTH_8U, 3);
  23.    
  24.     for(int x = 0; x < 256; ++x)
  25.     {
  26.         for(int y = 0; y < 256; ++y)
  27.         {
  28.             int sign = floatsign(x, y);
  29.             switch(sign)
  30.             {
  31.                 case -1:
  32.                     image->imageData[x*256*3 + y*3 + 0] = 255;
  33.                     image->imageData[x*256*3 + y*3 + 1] = 0;
  34.                     image->imageData[x*256*3 + y*3 + 2] = 0;
  35.                     break;
  36.                 case 1:
  37.                     image->imageData[x*256*3 + y*3 + 0] = 0;
  38.                     image->imageData[x*256*3 + y*3 + 1] = 0;
  39.                     image->imageData[x*256*3 + y*3 + 2] = 255;
  40.                     break;
  41.                 case 0:
  42.                     image->imageData[x*256*3 + y*3 + 0] = 0;
  43.                     image->imageData[x*256*3 + y*3 + 1] = 255;
  44.                     image->imageData[x*256*3 + y*3 + 2] = 255;
  45.                     break;
  46.             }
  47.         }
  48.     }
  49.     cvFlip(image, image, 0);
  50.     std::cout<<"write"<<std::endl;
  51.     cvSaveImage("image.png", image);
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement