home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2000 December / VPR0012A.BIN / OLS / CMKT111 / cmkt111.lzh / Cmachine / sample / graphic.c < prev    next >
C/C++ Source or Header  |  2000-09-27  |  792b  |  46 lines

  1.  
  2. /*
  3.  * C machine サンプル ~ グラフィックス出力
  4.  *
  5.  * 「sin、cosカーブ出力」
  6.  *
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <graphic.h>
  11. #include <math.h>
  12.  
  13. #define X0    320        // 原点X
  14. #define Y0    240        // 原点Y
  15. #define X_R 50        // X倍率
  16. #define Y_R -150    // Y倍率
  17.  
  18. int main(void)
  19. {
  20.     double x, sy, cy;
  21.     double pre_x, pre_sy, pre_cy;
  22.  
  23.     printf("描画スタート!");
  24.  
  25.     /* 座標軸を描画 */
  26.     setline(0, Y0, 640, Y0, 1, 9);
  27.     setline(X0, 0, X0, 480, 1, 9);
  28.  
  29.     /* sin, cosカーブを描画 */
  30.     for(x = 0; x<=640; x+=10) {
  31.         sy = Y_R * sin((x-X0)/X_R) + Y0;
  32.         cy = Y_R * cos((x-X0)/X_R) + Y0;
  33.  
  34.         if(x != 0) {
  35.             setline(pre_x, pre_sy, x, sy, 1, 13);
  36.             setline(pre_x, pre_cy, x, cy, 1, 11);
  37.         }
  38.  
  39.         pre_x = x; pre_sy = sy; pre_cy = cy;
  40.     }
  41.  
  42.     printf("\n描画エンド!\n");
  43.  
  44.     return 0;
  45. }
  46.