「メモ1」の編集履歴(バックアップ)一覧に戻る

メモ1 - (2007/01/10 (水) 13:57:30) のソース

 #include <math.h>
 #include <GrWin.h>
 #define MAG 50
 void func(double *x,double *y,double th){
    *x = cos(th) * (4 * sin(17 * th));
    *y = sin(th) * (4 * sin(6 * th));
 }
 void main(){
        int width = 640,height = 480;
        int xhome = width / 2,yhome = height / 2;
        double x,y,th,x0,y0,x1,y1;
        
        GWopen(0);
        GWsize( -5 , &width , &height );
        GWsize( -3 , NULL , NULL );
        GWvport(0.0 , 0.0 , (float)width / (float)height , 1.0);
        GWindow(0.0 , (float)height-1.0 , (float)width-1.0 , 0.0);
        
        GWclear(GWC_WHITE);
        GWsetpen(GWC_BLUE,GWL_SOLID,1,GWX_COPYPEN);
        GWline( 0 , yhome , width , yhome );    //x軸
        GWline( xhome , 0 , xhome , height);    //y軸
        
        GWsetpen(GWC_BLACK,GWL_SOLID,1,GWX_COPYPEN);
        
        func(&x,&y,0);
        x0 = xhome + MAG * x;
        y0 = yhome - MAG * y;
        
        for(th = 0 ; th <= 1080.0 / 180.0 * 3.141592 ; th += 1.0 / 180.0 * 3.141592){
                func(&x,&y,th);
                x1 = xhome + MAG * x;
                y1 = yhome - MAG * y;
                
                GWline(x0,y0,x1,y1);
                
                x0 = x1;
                y0 = y1;
        }
        return ;
 }