نمایش نتایج 1 تا 2 از 2

نام تاپیک: Cohen_Suterland

  1. #1
    کاربر جدید
    تاریخ عضویت
    دی 1385
    محل زندگی
    تهران
    پست
    2

    Cool Cohen_Suterland

    [LEFT]سلام دوستان این برنامه cohen خودم نوشتم که از شانسم نتونستم به استاد تحویل بدم براش سنگ تموم گذاشتم هتمن اجراش کنید مثل این گیرتون نمیاد
    // Programer: Iman Mohammadi iman_ison@yahoo.com
    #include<stdio.h>
    #include<graphics.h>
    #include<math.h>
    #include<conio.h>
    #include<stdlib.h>
    #include<iostream.h>
    #include<iomanip.h>
    #include<dos.h>

    //******************* Type Variables ***********************
    enum{LEFT,RIGHT,BOTTOM,TOP};
    char code1[]={0,0,0,0};
    char code2[]={0,0,0,0};
    int xmin,ymin,xmax,ymax;
    double x1,y1,x2,y2;
    //************************************************** ********


    //******************* Declarations *************************
    void graphic(void);
    void convert(double,double,int&,int&);
    void setline(void);
    void display(void);
    void encode(char*,double,double);
    unsigned char accept(void);
    unsigned char reject(void);
    unsigned char pointinside();
    void cohen_suterland(void);
    //************************************************** ********


    //*********************** MAIN *****************************
    void main()
    {
    graphic();
    display();
    setline();
    cohen_suterland();
    getch();
    }
    //************************************************** *******************

    //*********************** Graphic Detection ***************************
    void graphic(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int x, y, color;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "..\\bgi");
    /* read result of initialization */
    errorcode = graphresult();
    /* an error occurred */
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    /* terminate with an error code */
    exit(1);
    }
    }
    //************************************************** *********************
    ///////////////////////////////////////////////////////////////////////////
    //********************************************
    void convert(double x,double y,int &xr,int &yr)
    {
    xr=50+(x*25);
    yr=400-(y*25);
    }
    //*********************************************
    void display(void)
    {
    setcolor(RED);
    line(20,150,600,150);
    line(20,250,600,250);
    line(150,20,150,450);
    line(300,20,300,450);
    setcolor(WHITE);
    char str[2];
    line(50,50,50,400);
    line(51,400,500,400);
    for(int i=50;i<=375;i+=25)
    {
    itoa(15-((i/25)-1),str,10);
    outtextxy(20,i,str);
    line(47,i,53,i);
    itoa((i/25)-1,str,10);
    outtextxy(i+25,410,str);
    line(i+25,397,i+25,403);
    }
    xmin=4; ymin=6;
    xmax=10; ymax=10;
    int xrmin,yrmin,xrmax,yrmax;
    convert(xmin,ymin,xrmin,yrmin);
    convert(xmax,ymax,xrmax,yrmax);
    rectangle(xrmin,yrmin,xrmax,yrmax);
    }
    //********************************************
    void setline(void)
    {
    int xr1,yr1,xr2,yr2;
    outtextxy(10,10,"Enter points (X1,Y1,X2,Y2) :");
    cin>>x1>>y1>>x2>>y2;
    convert(x1,y1,xr1,yr1);
    convert(x2,y2,xr2,yr2);
    line(xr1,yr1,xr2,yr2);
    }

    //********************************************

    void encode(char *code,double x,double y)
    {
    code[LEFT] = (x<xmin) ? 1 : 0;
    code[RIGHT] = (x>xmax) ? 1 : 0;
    code[BOTTOM]= (y<ymin) ? 1 : 0;
    code[TOP] = (y>ymax) ? 1 : 0;
    }
    //********************************************
    unsigned char accept(void)
    {
    for(int i=LEFT;i<=TOP;i++)
    if (code1[i]|code2[i])
    return 0;
    return 1;
    }
    //********************************************
    unsigned char reject(void)
    {
    for(int i=LEFT;i<=TOP;i++)
    {
    if (code1[i]&code2[i])
    return 1;
    }
    getch();
    return 0;
    }
    //********************************************
    unsigned char pointinside()
    {
    for(int i=LEFT;i<=TOP;i++)
    if (code1[i]==1)
    return 0;
    return 1;
    }
    //********************************************
    void cohen_suterland(void)
    {
    double m;
    int done=0 ,draw=0;
    int xr1,yr1,xr2,yr2;
    while(! done)
    {
    encode(code1,x1,y1);
    encode(code2,x2,y2);
    getch();
    if(accept())
    {done=1; draw=1;}
    else
    if(reject())
    {done=1;}
    else
    {
    if (pointinside())
    {
    double tem;
    tem=x1;
    x1=x2;
    x2=tem;
    tem=y1;
    y1=y2;
    y2=tem;
    for (int i=LEFT;i<=TOP;i++)
    {
    tem=code1[i];
    code1[i]=code2[i];
    code2[i]=tem;
    }
    }
    m=(y2-y1)/(x2-x1);
    if (code1
    )
    {
    y1+=(xmin-x1)*m;
    x1=xmin;
    convert(x1,y1,xr1,yr1);
    circle(xr1,yr1,5);
    }
    else
    if (code1[RIGHT])
    {
    y1+=(xmax-x1)*m;
    x1=xmax;
    setcolor(YELLOW);
    convert(x1,y1,xr1,yr1);
    circle(xr1,yr1,5);
    }
    else
    if (code1[BOTTOM])
    {
    x1+=(ymin-y1)/m;
    y1=ymin;
    convert(x1,y1,xr1,yr1);
    circle(xr1,yr1,5);
    }
    else
    if( code1[TOP])
    {
    x1+=(ymax-y1)/m;
    y1=ymax;
    convert(x1,y1,xr1,yr1);
    circle(xr1,yr1,5);
    }

    }
    }
    if (draw)
    setcolor(GREEN);
    else
    setcolor(RED);
    convert(x1,y1,xr1,yr1);
    convert(x2,y2,xr2,yr2);
    line(xr1,yr1,xr2,yr2);
    getch();
    }
    //********************************************

  2. #2
    لطفا پستتون رو ویرایش کنید و بین تگهای کد(CODE) قرار بدید تا خواناتر بشه.

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •