Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to run the code

include <graphics.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>
    #include <math.h>
    #define Pi 3.1415926536
    // this function initializes graphics mode
    // it will work only if you're using Borland C++ compiler & BGI drivers
    // if you're using another compiler you should overwrite body of this function
    void init_gr(void)
    {
    /* request autodetection */
    int gdriver = DETECT, gmode, errorcode;
    /* initialize graphics mode */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s
", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* return with error code */
    }
    }
    // this function shuts graphics mode down
    // it will work only if you're using Borland C++ compiler & BGI drivers
    // if you're using another compiler you should overwrite body of this function
    void end_gr(void)
    {
    closegraph();
    }
    // this function moves CP to (x,y) position
    // it will work only if you're using Borland C++ compiler & BGI drivers
    // if you're using another compiler you should overwrite body of this function
    void MoveTo(int x, int y)
    {
    moveto(x,y);
    }
    // this function draws a line to (x,y) position
    // it will work only if you're using Borland C++ compiler & BGI drivers
    // if you're using another compiler you should overwrite body of this function
    void LineTo(int x, int y)
    {
    lineto(x,y);
    }
    const N=6; // number of points in the figure
    // coordinates of all given points
    enum actions {MOVE,DRAW};
    struct
    {
    actions action;
    int x;
    int y;
    } figure[N]={{MOVE,360,270},{DRAW,360,260},{DRAW,355,260},{DRAW,360,250},
    {DRAW,365,260},{DRAW,360,260}};
    int x0,y0,dx,dy;
    float phi;
    int main(void)
    {
    // initializing graphics mode
    init_gr();
    // rotating about (x0,y0)
    x0=300;
    y0=260;
    // by 10 degrees
    phi=45.0*Pi/180.0;
    // main loop
    for(int i=0;i<8;i++)
    {
    // rotating the figure
    for (int j=0;j<N;j++)
    {
    dx=figure[j].x-x0;
    dy=figure[j].y-y0;
    figure[j].x=x0+dx*cos(phi)-dy*sin(phi);
    figure[j].y=y0+dx*sin(phi)+dy*cos(phi);
    }
    // drawing rotated figure
    for (j=0;j<N;j++)
    if (figure[j].action==MOVE)
    MoveTo(figure[j].x,figure[j].y);
    else
    LineTo(figure[j].x,figure[j].y);
    }
    // clean up
    getch();
    end_gr();
    return 0;
    }
Comment

PREVIOUS NEXT
Code Example
Cpp :: last index of array c++ 
Cpp :: && in cpp 
Cpp :: cin une énumération 
Cpp :: Write a CPP program to calculate sum of first N natural numbers 
Cpp :: how to modify set C++ 
Cpp :: product of array in cpp 
Cpp :: input many numbers to int c++ 
Cpp :: hamming c++ 
Cpp :: c++ multiple if conditions 
Cpp :: cocos2d c++ linux 
Cpp :: segment tree lazy propogation 
Cpp :: stack using cpp 
Cpp :: left margin c++ 
Cpp :: what is vector capacity in c++ 
Cpp :: operator overloading prefix postfix c++ 
Cpp :: online compiler c++ with big O calculatorhttps://www.codegrepper.com/code-examples/cpp/how+to+convert+string+to+wchar_t+in+c%2B%2B 
Cpp :: C++ if...else 
Cpp :: esp8266 wifi.localip() to string 
Cpp :: two dimensional matrix using oops concept 
Cpp :: variabili in c++ 
Cpp :: # in c++ 
Cpp :: ue4 foreach loop c++ 
Cpp :: c++ loop 
Cpp :: deadlock detection in c++coding ninjas 
Cpp :: convert c++ code to exe 
Cpp :: nested loop c++ program example 
Cpp :: what is the format specifier for dword c++ 
Cpp :: amusia 
Cpp :: how to pass arrays by reference c++ 
Cpp :: conditions in c++ 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =