[QNX]绘制一个正弦波

效果图
绘制一个正弦波

实现代码

#define N_SAMPLE 100 // 波长最大值
#define AMP_MAX 50 // 振幅最大值

/* * amplitude —— 振幅 * wavelength —— 波长 */
int sin_wave(int amplitude, int wavelength) {
    int i = 0;
    int value_array[N_SAMPLE] = { 0 };

    if (wavelength > N_SAMPLE)  wavelength = N_SAMPLE;
    if (amplitude > AMP_MAX)  amplitude = AMP_MAX;

    for (i = 0; i < N_SAMPLE; i++) {
        value_array[i] = (int) amplitude * sin((atan(1) * 8 * (i % wavelength)) / wavelength) + AMP_MAX;
    }

    PtMTrendAddData(ABW_PtMTrend_data, 0, value_array, N_SAMPLE );

    return 0;
}

int mtrend_init(void) {
    PtMTrendAttr_t graph1_attr = { Pt_MTREND_STATE_SHOWN, Pg_RED, 3, Pg_MITER_JOIN, 0, AMP_MAX*2, NULL, { 0, 0, 0, 0 } };
    PtArg_t args[4];

    int i = 0;
    PtSetArg( &args[i++], Pt_ARG_MTREND_N_GRAPHS, 1, 0 );
    PtSetArg( &args[i++], Pt_ARG_MTREND_N_SAMPLES, N_SAMPLE, 0 );
    PtSetArg( &args[i++], Pt_ARG_MTREND_FLAGS, Pt_TRUE, Pt_MTREND_BLIT );
    PtSetArg( &args[i++], Pt_ARG_MTREND_GRAPH_ATTR, &graph1_attr, 0 );

    PtSetResources(ABW_PtMTrend_data, 4, args);
}
相关文章

相关标签/搜索