📄 sample4_6.c
字号:
#include <ansi_c.h>#include <cvirte.h> /* Needed if linking in external compiler; harmless otherwise */#include <userint.h>#include "sample4_6.h"#define PI 3.14159 #define MYEVENT 1000int panelHandle;static double waveData[100];void GenerateSineWave (double amplitude, double cycles, double *waveData);int main (int argc, char *argv[]){ int ControlorMenuID; int quit_flag = 1,event; double cycles=1,amplitude=5; if (InitCVIRTE (0, argv, 0) == 0) /* Needed if linking in external compiler; harmless otherwise */ return -1; /* out of memory */ panelHandle = LoadPanel (0, "sample4_6.uir", PANEL); DisplayPanel (panelHandle); while (quit_flag ) { event=GetUserEvent (0,NULL, &ControlorMenuID); if(event==1) switch (ControlorMenuID) { case PANEL_GENERATESINE: GenerateSineWave (amplitude, cycles, waveData); PlotY (panelHandle, PANEL_GRAPH, waveData, 100, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED); break; case PANEL_CYCLES: GetCtrlVal (panelHandle, PANEL_CYCLES, &cycles); break; case PANEL_AMPLITUDE: GetCtrlVal (panelHandle, PANEL_AMPLITUDE, &litude); break; case PANEL_DELETEPLOTS: DeleteGraphPlot (panelHandle, PANEL_GRAPH, -1, 1); break; case PANEL_QUIT: QueueUserEvent (MYEVENT, 0, 0);/*quit_flag = 0; */ break; } else if(event>=1000&&event<=10000) switch (event) { case MYEVENT: quit_flag = 0; break; } } DiscardPanel (panelHandle); return 0;} void GenerateSineWave (double amplitude, double cycles, double *waveData){ double x, dx; int i; x = 0.0; dx = (2.0 * PI) / (double)(100 - 1); for (i = 0 ; i < 100 ; i++) { waveData[i] = sin (cycles * x)*amplitude; x += dx; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -