Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <opencv/cv.h>
- #include <opencv/highgui.h>
- #include <math.h>
- int floatsign(double x, double y)
- {
- double px = (0.5 + x * pow(2, -53));
- double py = (0.5 + y * pow(2, -53));
- double value = (12 - px)*(24 - py) - (12 - py)*(24 - px);
- if(value == 0)
- return 0;
- else if(value > 0)
- return 1;
- else if(value < 0)
- return -1;
- }
- int main(int argc, char** argv)
- {
- IplImage* image = cvCreateImage(cvSize(256,256), IPL_DEPTH_8U, 3);
- for(int x = 0; x < 256; ++x)
- {
- for(int y = 0; y < 256; ++y)
- {
- int sign = floatsign(x, y);
- switch(sign)
- {
- case -1:
- image->imageData[x*256*3 + y*3 + 0] = 255;
- image->imageData[x*256*3 + y*3 + 1] = 0;
- image->imageData[x*256*3 + y*3 + 2] = 0;
- break;
- case 1:
- image->imageData[x*256*3 + y*3 + 0] = 0;
- image->imageData[x*256*3 + y*3 + 1] = 0;
- image->imageData[x*256*3 + y*3 + 2] = 255;
- break;
- case 0:
- image->imageData[x*256*3 + y*3 + 0] = 0;
- image->imageData[x*256*3 + y*3 + 1] = 255;
- image->imageData[x*256*3 + y*3 + 2] = 255;
- break;
- }
- }
- }
- cvFlip(image, image, 0);
- std::cout<<"write"<<std::endl;
- cvSaveImage("image.png", image);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement