-- 作者:admin
-- 发布时间:2015/12/12 9:07:50
-- 课上练习代码——EGE高级绘图操作
绘制太极双鱼图 #include "graphics.h"
main() { int driver=VGA,model=VGAHI; int i=0,j=0; int x,y; initgraph(&driver,&model,""); ege::initgraph(600,600);
setbkcolor(WHITE); setcolor(BLACK); setfillstyle(SOLID_FILL,BLACK); sector(300,300,90,270,200,200); setcolor(YELLOW); setfillstyle(SOLID_FILL,YELLOW); sector(300,300,270,450,200,200); sector(300,200,90,270,100,100); setcolor(BLACK); setfillstyle(SOLID_FILL,BLACK); sector(300,400,270,450,100,100); setcolor(YELLOW); setfillstyle(SOLID_FILL,YELLOW); sector(300,400,0,360,20,20); setcolor(RED); setfillstyle(SOLID_FILL,RED); sector(300,200,0,360,20,20); getch();
}
更为灵活的版本 #include "graphics.h" #define WIDTH 1600 #define HEIGHT 1200
main() { int driver=VGA,model=VGAHI; int i=0,j=0; int x,y; initgraph(&driver,&model,""); ege::initgraph(WIDTH,HEIGHT);
setbkcolor(WHITE); setcolor(BLACK); setfillstyle(SOLID_FILL,BLACK); sector(WIDTH/2,HEIGHT/2,90,270,WIDTH/3,HEIGHT/3); setcolor(YELLOW); setfillstyle(SOLID_FILL,YELLOW); sector(WIDTH/2,HEIGHT/2,270,450,WIDTH/3,HEIGHT/3); sector(WIDTH/2,HEIGHT/3,90,270,WIDTH/6,HEIGHT/6); setcolor(BLACK); setfillstyle(SOLID_FILL,BLACK); sector(WIDTH/2,HEIGHT*2/3,270,450,WIDTH/6,HEIGHT/6); setcolor(YELLOW); setfillstyle(SOLID_FILL,YELLOW); sector(WIDTH/2,HEIGHT*2/3,0,360,WIDTH/30,HEIGHT/30); setcolor(RED); setfillstyle(SOLID_FILL,RED); sector(WIDTH/2,HEIGHT/3,0,360,WIDTH/30,HEIGHT/30); getch();
}
渐变色: #include "graphics.h" #define WIDTH 1600 #define HEIGHT 1200
main() { int driver=VGA,model=VGAHI; initgraph(&driver,&model,""); ege::initgraph(WIDTH,HEIGHT);
setbkcolor(WHITE);
int i=0; for(;i<256;i++) { setcolor(RGB(i,0,i)); setlinestyle(SOLID_FILL,0,4); line(0,i*4,WIDTH,i*4); } getch();
}
#include "math.h" #include "graphics.h" #define WIDTH 1600 #define HEIGHT 1200
main() { int driver=VGA,model=VGAHI; initgraph(&driver,&model,""); ege::initgraph(WIDTH,HEIGHT); setbkcolor(WHITE); setlinestyle(SOLID_FILL,0,4); int c; double a; int x, y, r=600; for(a=0; a<PI*2; a+=0.0001) { x=(int)(r*cos(a) + WIDTH/2 + 0.5); y=(int)(r*sin(a) + HEIGHT/2 + 0.5); c=(int)(a*255/(2*PI) + 0.5); setcolor(RGB(c,0,0)); line(WIDTH/2, HEIGHT/2, x, y); } getch();
}
鼠标绘图操作 直线矩形绘图 #include "graphics.h" #include "stdio.h" #include "stdlib.h"
main() { int driver=VGA,model=VGAHI; initgraph(&driver,&model,""); ege::initgraph(800,800); setbkcolor(YELLOW); setcolor(BLACK); setlinestyle(SOLID_LINE,0,3); int x1,y1,x2,y2; for ( ; is_run(); delay_fps(120)) { while (mousemsg()) { mouse_msg m = getmouse(); if (m.msg == mouse_msg_down) { x1=m.x; y1=m.y; } if (m.msg == mouse_msg_up) { x2=m.x; y2=m.y; //line(x1,y1,x2,y2); rectangle(x1,y1,x2,y2); } } } }
自由绘图 #include "graphics.h" #include "stdio.h" #include "stdlib.h"
main() { int driver=VGA,model=VGAHI; initgraph(&driver,&model,""); ege::initgraph(800,800); setbkcolor(YELLOW); setcolor(BLACK); setlinestyle(SOLID_LINE,0,3); int x1,y1,x2,y2,start=0; for ( ; is_run(); delay_fps(120)) { while (mousemsg()) { mouse_msg m = getmouse(); if (m.msg == mouse_msg_down) { x1=m.x; y1=m.y; start=1; } if (m.msg == mouse_msg_move && start==1) { x2=m.x; y2=m.y; line(x1,y1,x2,y2); x1=m.x; y1=m.y; } if (m.msg == mouse_msg_up) { start=0; }
} } }
此主题相关图片如下:无标题.png

[此贴子已经被作者于2015-12-12 09:09:27编辑过]
|