ПРИЕМ ПРОГРАММЫ ВЫСТУПЛЕНИЯ КОНТАКТЫ
 
 
-

-

-
-

-
доцент Хайдаров
Геннадий Гасимович

 
 

Январь

Задание 9.1


    // Графические примитивы. Большинство из них благополучно
    // перешли в графику Windiws с небольшими изменениями 
    // line, circle, rectangle, outtextxy... 
    // Из примеров Borland С++ можно взять много полезного! 
    // Например - Example: setfillstyle 
    // graph.cpp 
    #include <graphics.h> 
    #include <stdlib.h> 
    #include <string.h> 
    #include <stdio.h> 
    #include <conio.h> 
    
    /* Имена стилей заливки */
    char *fname[] = { "EMPTY_FILL","SOLID_FILL","LINE_FILL","LTSLASH_FILL", 
    "SLASH_FILL","BKSLASH_FILL","LTBKSLASH_FILL","HATCH_FILL","XHATCH_FILL", 
    "INTERLEAVE_FILL","WIDE_DOT_FILL","CLOSE_DOT_FILL","USER_FILL"}; 
    
    int main(void) 
    {/*DETECT автоматическое тестирование графических режимов*/ 
    int gdriver = DETECT, gmode, errorcode; 
    int style, midx, midy; char stylestr[40]; 
    
    /* Инициализация графической части программы */ 
    initgraph(&gdriver, &gmode, ""); 
    errorcode = graphresult();
    if (errorcode != grOk) { 
    /* Если имеется ошибка графического режима */ 
    printf("Ошибка: %s\n", grapherrormsg(errorcode)); 
    printf("Нажми любую клавишу (Press any key )"); 
    getch(); exit(1); /* выход при ошибке */ } 
    
    midx = getmaxx() / 2; midy = getmaxy() / 2; 
    for (style = EMPTY_FILL; style < USER_FILL; style++) 
    { /* выбор стиля */ 
    setfillstyle(style, getmaxcolor()); 
    /* название стиля заливки */ 
    strcpy(stylestr, fname[style]); 
    bar3d(30, 30, midx-10, midy,10,10); 
    /* сообщения */ 
    outtextxy(midx, midy, stylestr); 
    outtextxy(midx, midy+30, "Press any key"); 
    getch(); /* подождать нажатия клавиши */ 
    cleardevice(); 
    } 
    closegraph(); return 0;} 
    

Задание 9.2


    //frame8.cpp 
    //Смена графических страниц 
    //Отскакивание мячика от стенок 
    #include <graphics.h> 
    #include <conio.h> 
    #include <stdlib.h> 
    
    void DrawFrame(void); 
    void main(void){ //Смена графических страниц 
    int gd=EGA,gm=EGAHI; //640x350 
    initgraph(&gd,&gm,""); 
    DrawFrame();setactivepage(1); 
    for (int frame=1;;frame++){ 
    clearviewport(); 
    if(frame>301){closegraph();exit(1);}; 
    
    DrawFrame(); 
    setactivepage(frame&1); 
    setvisualpage(1-(frame&1)); } } 
    void DrawFrame(void) //Отскакивание мячика от стенок 
    { int r=10;
    static int x0=100,y0=200, stepx=5,stepy=5; 
    static int col=0;col++;if(col>15)col=3; 
    setbkcolor (BLUE);setcolor(col);setfillstyle(1,col); 
    circle(x0,y0,r);floodfill(x0,y0,col); 
    
    if(x0 < r+5||x0 > (640-r-5))stepx=-stepx; 
    if(y0 < r+5||y0 > (350-r-5))stepy=-stepy; 
    x0+=stepx;y0+=stepy; 
    } 
    

Задание 10


    //Графика Visual C++ 
    //CLR Windows Forms 
    private: System::Void button1_Click(System::Object^ sender, 
    System::EventArgs^ e) 
    { 
    //Graphics* g = this->CreateGraphics(); 
    Graphics^ g = this->CreateGraphics(); 
    //Pen* myPen = new Pen(Color::Blue); 
    Pen^ myPen = gcnew Pen(Color::Blue); myPen->Width = 10; 
    g->DrawLine(myPen, 45, 1, 45, 20); 
    g->DrawBezier(myPen, 15, 90, 30, 30, 45, 130, 90, 20); 
    g->DrawEllipse(myPen, Rectangle(50, 170, 200, 40)); 
    
    //SolidBrush* myBrush = new SolidBrush(Color::Green); 
    SolidBrush^ myBrush = gcnew SolidBrush(Color::Green); 
    g->FillRectangle(myBrush, RectangleF(180, 50, 70, 50)); 
    g->FillPie(myBrush, Rectangle(180, 100, 70, 50), 0, 90); 
    } 
    private: System::Void Form1_Paint(System::Object^ sender, 
    System::Windows::Forms::PaintEventArgs^ e) 
    { 
    Color c1=Color::Red; Color c2=Color::FromArgb(100,255,0,0);	
    Pen^ pen2 = gcnew Pen( c1,5.0f ); 
    Point point1 = Point(100,100); Point point2 = Point(400,100); 
    e->Graphics->DrawLine(pen2,100,20,150,100); 
    e->Graphics->DrawLine(pen2, Point(10,20),Point(30,20)); 
    
    /*System::Drawing::Font *ft = 
    new System::Drawing::Font(S"Garamond", 24, FontStyle::Bold); */
    String^ s="DrawString - AAA"; 
    System::Drawing::Font^ textFontA = 
    gcnew System::Drawing::Font("Arial", 16); 
    System::Drawing::SolidBrush^ textBrushA =
    gcnew System::Drawing::SolidBrush(c2); 
    e->Graphics->DrawString(s, textFontA, textBrushA, 30, 120); 
    } 
    
Графика

Рекомендуемые видео уроки и информационные ссылки

Основные:  Дополнительные: 

   Рейтинг@Mail.ru