Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 代码编译正确,但图像不正确';我没有出现_C++ - Fatal编程技术网

C++ 代码编译正确,但图像不正确';我没有出现

C++ 代码编译正确,但图像不正确';我没有出现,c++,C++,我正在尝试测试一些Clifford吸引子并使其动画化 如图所示: 我试着从这里编译代码。 代码已编译,但未生成图像文件 我正在使用: Visual Studio代码 版本:1.38.0 提交:3db7e09f3b61f915d03bbfa58e258d6eee843f35 日期:2019-09-03T21:51:09.716Z 电子:4.2.10 铬:69.0.3497.128 Node.js:10.11.0 V8:6.9.427.31-electron.0 操作系统:Linux x64 4.

我正在尝试测试一些Clifford吸引子并使其动画化 如图所示:

我试着从这里编译代码。 代码已编译,但未生成图像文件

我正在使用: Visual Studio代码 版本:1.38.0 提交:3db7e09f3b61f915d03bbfa58e258d6eee843f35 日期:2019-09-03T21:51:09.716Z 电子:4.2.10 铬:69.0.3497.128 Node.js:10.11.0 V8:6.9.427.31-electron.0 操作系统:Linux x64 4.15.0-60-generic snap

/*
        xn+1 = sin(a yn) + c cos(a xn)
        yn+1 = sin(b xn) + d cos(b yn)
*/

#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

// Change params only in this block
namespace {
    const int width = 1600;
    const int height = 1200;
    const int frames = 10000;
    const int iters = 10000;
    const int skipIters = 10;

    double sensitivity = 0.02;

    const double minX = -4.0;
    const double minY = minX * height / width;

    const double maxX = 4.0;
    const double maxY = maxX * height / width;

    const double minA = acos( 1.6 / 2.0 );
    const double maxA = acos( 1.3 / 2.0 );

    const double minB = acos( -0.6 / 2.0 );
    const double maxB = acos( 1.7 / 2.0 );

    const double minC = acos( -1.2 / 2.0 );
    const double maxC = acos( 0.5 / 2.0 );

    const double minD = acos( 1.6 / 2.0 );
    const double maxD = acos( 1.4 / 2.0 );
};




class Color {
    public:

    double r, g, b;

    Color(const double &red = 0, const double &green = 0, const double &blue = 0) : r(red), g(green), b(blue) {
    }

    Color& operator+=(const Color &rhs) {
        r += rhs.r;
        g += rhs.g;
        b += rhs.b;
        return *this;
    }

    static Color createHue( double h ) {
        h *= 6.0;
        int hi = static_cast<int>( h );
        double hf = h - hi;


        switch( hi % 6 ) {
            case 0:
            return Color( 1.0 , hf, 0.0 );
            case 1:
            return Color( 1.0 - hf, 1.0, 0.0 );
            case 2:
            return Color( 0.0 , 1.0, hf );
            case 3:
            return Color( 0.0, 1.0 - hf, 1.0 );
            case 4:
            return Color( hf, 0.0, 1.0 );
            case 5:
            return Color( 1.0, 0.0, 1.0 - hf );
        }

        return Color();
    }


    Color operator+(const Color &rhs) const {
        return Color(*this) += rhs;
    }


};

int main(void) {

    vector<Color> image( width * height );

    for (int i = 0; i < frames; i++) {

        const double p = static_cast<double>(i) / frames;
        const double a = cos( minA + p * (maxA - minA) ) * 2.0;
        const double b = cos( minB + p * (maxB - minB) ) * 2.0;
        const double c = cos( minC + p * (maxC - minC) ) * 2.0;
        const double d = cos( minD + p * (maxD - minD) ) * 2.0;

        const Color curCol = Color::createHue( p ); 

        double x = 0.0, y = 0.0;

        for (int j = 0; j < iters; j++) {

            double xn = sin(a * y) + c * cos(a * x);
            double yn = sin(b * x) + d * cos(b * y);
            x = xn;
            y = yn;

            if ( j < skipIters )
                continue;


            int xi = static_cast<int>( (x - minX) * width / (maxX - minX) );
            int yi = static_cast<int>( (y - minY) * height / (maxY - minY) );
            if ( xi >= 0 && xi < width &&
                 yi >= 0 && yi < height ) {

                 image[ xi + yi * width ] += curCol;

            }

        }
        clog << "\r" << i;

    }
    clog << "\n";

    cout
        << "P6\n"
        << width << " " << height << "\n"
        << "255\n";

    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            Color &c = image[ x + y * width ];

            unsigned char r = static_cast<unsigned char>( (1.0 - exp( -sensitivity * c.r )) * 255.0 );
            unsigned char g = static_cast<unsigned char>( (1.0 - exp( -sensitivity * c.g )) * 255.0 );
            unsigned char b = static_cast<unsigned char>( (1.0 - exp( -sensitivity * c.b )) * 255.0 );

            cout << r << g << b;
        }
    }


    return 0;
}
/*
xn+1=sin(a yn)+c cos(a xn)
yn+1=sin(bxn)+d cos(byn)
*/
#包括
#包括
#包括
使用名称空间std;
//仅在此块中更改参数
名称空间{
const int width=1600;
const int height=1200;
const int frames=10000;
常数=10000;
滑雪者常数=10;
双灵敏度=0.02;
constdoubleminx=-4.0;
const double minY=minX*高度/宽度;
常数double maxX=4.0;
const double maxY=maxX*高度/宽度;
常数双minA=acos(1.6/2.0);
const double maxA=acos(1.3/2.0);
常数双minB=acos(-0.6/2.0);
const double maxB=acos(1.7/2.0);
const double minC=acos(-1.2/2.0);
const double maxC=acos(0.5/2.0);
const double minD=acos(1.6/2.0);
常数双最大值=acos(1.4/2.0);
};
类颜色{
公众:
双r,g,b;
颜色(常数双色&红色=0,常数双色&绿色=0,常数双色&蓝色=0):r(红色),g(绿色),b(蓝色){
}
颜色和运算符+=(常量颜色和rhs){
r+=rhs.r;
g+=rhs.g;
b+=rhs.b;
归还*这个;
}
静态颜色创建色调(双h){
h*=6.0;
int hi=静态铸件(h);
双hf=h-hi;
开关(高%6){
案例0:
返回颜色(1.0,hf,0.0);
案例1:
返回颜色(1.0-hf,1.0,0.0);
案例2:
返回颜色(0.0、1.0、hf);
案例3:
返回颜色(0.0,1.0-hf,1.0);
案例4:
返回颜色(hf,0.0,1.0);
案例5:
返回颜色(1.0,0.0,1.0-hf);
}
返回颜色();
}
颜色运算符+(常量颜色和rhs)常量{
返回颜色(*this)+=rhs;
}
};
内部主(空){
矢量图像(宽度*高度);
对于(int i=0;i=0&&yi<高度){
图象[席+益*宽] +曲线;
}
}

clog您确定您没有错误地使用它吗?它将PPM文件内容输出到
cout
,从命令行运行它,将应用程序输出输出到文件,然后使用PPM查看器或首先转换为PNG来查看它。(我得到的输出是您提供的代码中的参数)控制台应用程序创建了一个dat文件,你应该在窗口中看到它。一个
app.exe>>文件。dat
,你可以将它发送到一个文件。我在网站上看了一点,但没有看到任何关于查看器的内容。但我确信它确实存在。这个问题需要重写。虽然我很清楚它试图做什么,但它不会是obvi这对很多人来说是很明显的。这显然是在创建一个PPM文件。在这个问题中,它解释了什么?没有地方。如果这里发生的是你从一个引用的链接中复制了原始代码,但是不理解它,也许最好先把C++基础知识集中在尝试复制和破解随机C++。在Internet上找到的代码。请阅读ppm规范,然后查看创建的文件。问题应该很明显。需要有关编译代码的信息。它仍然可能无法工作。这种情况经常发生。