|
|
Регистрация Восстановить пароль |
Регистрация | Задать вопрос |
Заплачу за решение |
Новые сообщения |
Сообщения за день |
Расширенный поиск |
Правила |
Всё прочитано |
|
Опции темы | Поиск в этой теме |
07.12.2011, 21:23 | #1 |
Регистрация: 05.07.2011
Сообщений: 7
|
графика на с++
выполнить расчет экранных координат первых десяти точек для одной из диагональных линий (по алгоритму Брезенхейма).на экране буква Х!
Текст программы: #include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <dos.h> void drawline ( int x1, int y1, int x2, int y2, int color ) { int dx = abs ( x2 - x1 ); int dy = abs ( y2 - y1 ); int sx = x2 >= x1 ? 1 : -1; int sy = y2 >= y1 ? 1 : -1; if ( dy <= dx ) { int d = ( dy << 1 ) - dx; int d1 = dy << 1; int d2 = ( dy - dx ) << 1; putpixel ( x1, y1, color ); for ( int x = x1 + sx, y = y1, i = 1; i <= dx; i++, x += sx ) { if ( d > 0 ) { d += d2; y += sy; } else d += d1; putpixel ( x, y, color ); } } else { int d = ( dx << 1 ) - dy; int d1 = dx << 1; int d2 = ( dx - dy ) << 1; putpixel ( x1, y1, color ); for ( int x = x1, y = y1 + sy, i = 1; i <= dy; i++, y += sy ) { if ( d > 0 ) { d += d2; x += sx; } else d += d1; putpixel ( x, y, color ); } } } int main(void) { int X1,Y1,Y2,X2,c; /* request auto detection */ int gdriver = VGA, gmode=2, errorcode; int low,hight; /* initialize graphics mode */ initgraph(&gdriver, &gmode, ""); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* return with error code */ } /*output parameters */ printf("Driver Name:%s\n", getdrivername()); printf("Max [X]x[Y]:%d x %d\n", getmaxx(),getmaxy()); /* Background lines*/ Y2=getmaxy(); Y1=getmaxy(); X2=getmaxx(); while (Y2>0) { drawline(0,Y1,X2,Y2,random(getmaxco lor())); Y2=Y2-5; } Y2=getmaxy(); X2=getmaxx(); while (X2>=0) { drawline(0,Y1,X2,0,random(getmaxcol or())); X2=X2-5; } /*Bukva*/ Y1= getmaxy()/2+40; c=15; drawline(220,100,270,100,c); drawline(350,100,400,100,c); drawline(220,370,270,370,c); drawline(220,100,280,235,c); drawline(220,370,280,235,c); drawline(350,370,400,370,c); drawline(350,100,313,200,c); drawline(270,100,313,200,c); drawline(400,100,347,230,c); drawline(270,370,315,270,c); drawline(315,270,350,370,c); drawline(400,370,347,230,c); /*Ramka*/ Y1=getmaxy(); X1=getmaxx(); Y2=getmaxy(); drawline(0,0,X1,0,c); drawline(X1,0,X1,Y1,c); drawline(X1,Y2,0,Y2,c); drawline(0,0,0,Y2,c); /* clean up */ getch(); closegraph(); return 0; } Последний раз редактировалось екатерина новикова; 07.12.2011 в 21:28. |
Похожие темы | ||||
Тема | Автор | Раздел | Ответов | Последнее сообщение |
3d графика | 555shiro | WPF, UWP, WinRT, XAML | 1 | 17.03.2011 22:44 |
Графика на c#!!! | Mclaren | Помощь студентам | 2 | 26.02.2010 10:08 |
Графика!!! | kykysya | Общие вопросы C/C++ | 1 | 17.12.2008 20:18 |
Графика в си | Scate | Помощь студентам | 6 | 25.11.2008 23:31 |