![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-15 01:10 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS开发编程 & 发展交流 (开发室) » Implementing artistic screen clearing in C [repost] |
| Printable Version 1,671 / 9 |
| Floor1 ko20010214 | Posted 2003-06-22 00:00 |
| 版主 Posts 1,628 Credits 7,296 | |
|
Implementing artistic screen clearing in C
Raising the question: when we write programs, we often need to clear the screen, such as cls under DOS, clrscr() under Turbo C, and so on. They all have screen-clearing capability, but these are only screen clears in the general sense, and do not show any particular clearing pattern. But sometimes, in order to achieve an artistic and pleasing screen-clearing effect, we often have some specific requirements for clearing the screen, such as: opening screen clear; closing screen clear; upward clear; downward clear; center clear. For this reason, several subfunctions written in C are provided here. When used in a program, they can not only achieve the purpose of clearing the screen, but also add artistic beauty to the display. Subfunctions and demo program: #include #include #include void goto_xy(int x,int y); void dcls(int x1,int x2,int y1,int y2); void bcls(int x1,int x2,int y1,int y2); void kcls(int x1,int x2,int y1,int y2); void recls(int x1,int x2,int y1,int y2); void zcls(int x1,int x2,int y1,int y2); void puta(void); /*--------------Demo program---------------------*/ main() { puta(); getch(); dcls(0,4,0,79); getch(); puta(); getch(); bcls(0,25,0,79); getch(); puta(); getch(); zcls(0,25,0,79); getch(); } /*********center clear screen(center clear screen)***********/ void zcls(int x1,int x2,int y1,int y2) { int x00,y00,x0,y0,i,d; if((y2-y1)>(x2-x1)){ d=(x2-x1)/2; x0=(x1+x2)/2; y0=y1+d; y00=y2-d; for(i=0;i<(d+1);i++) recls((x0-i),(x00+i),(y0-i),(y00+i)); delay(10); } else{ d=(y2-y1)/2; y0=(y1+y2)/2; x0=x1+d; x00=x2-d; for(i=0;i<d+1;i++) recls(x0-i,x00+i,y0-i,y00+i); delay(10); } } /************* clear rectangle side(rectangle-edge clear)***********************/ void recls(int x1,int x2,int y1,int y2) { int i,j; for(i=y1;i<y2;i++){ goto_xy(x1,i); putchar(' ' ;goto_xy(x2,i); putchar(' ' ;delay(10); } for(j=x1;j<x2;j++){ goto_xy(i,y1); putchar(' ' ;goto_xy(j,y2); putchar(' ' ;delay(10); } } /******************open screen clear(opening-style clear)*********************/ void kcls(int x1,int x2,int y1,int y2) { int t,s,i,j; t=s=(y1+y2)/2; for(;t<=y2;t++,s--) for(j=x1;j<x2;j++){ goto_xy(j,t); putchar(' ' ;goto_xy(j,s); putchar(' ' ;delay(10); } } /*****************close screen clear*****closing-style clear*******************/ void bcls(int x1,int x2,int y1,int y2) { int t,s,j; t=y1; s=y2; for(t=y1;t<(y1+y2)/2;t++,s--) for(j=x1;jx1;j--) for(i=y1;i<y2;i++){ goto_xy(j,i); putchar(' ' ;delay(10); } } /******************Subfunction for setting the cursor******************/ void goto_xy(int x,int y) { union REGS r; r.h.ah=2; r.h.dl=y; r.h.dh=x; r.h.bh=0; int86(0x10,&r,&r); } /**********************Print a string of letter a's on the screen for the demo program******************/ void puta(void) { int i,j; for(i=0;i<24;i++){ for(j=0;j<79;j++){ goto_xy(i,j); printf("a" ;} } } The calls in the main function are only for a demo program; for actual use, just make slight modifications. Copyright © 2002 Computer Room, Tieling Teachers College, Liaoning Province |
|
| Floor2 ricepot100 | Posted 2003-06-22 00:00 |
| 初级用户 Posts 49 Credits 294 | |
|
What language was the DOS system written in: assembly? C?
|
|
| Floor3 yiyesong | Posted 2003-06-22 00:00 |
| 元老会员 Posts 632 Credits 1,987 | |
|
Assembly
|
|
| Floor4 LanE | Posted 2003-06-23 00:00 |
| 银牌会员 Posts 648 Credits 1,835 | |
|
They all clear the screen by drawing spaces.
|
|
| Floor5 jhuang | Posted 2003-06-24 00:00 |
| 初级用户 Posts 3 Credits 124 From chongqing | |
|
An unconventional way to clear the screen!!!
:) |
|
| Floor6 hongying | Posted 2003-06-26 00:00 |
| 初级用户 Posts 4 Credits 112 | |
|
This can't really be called artistic screen clearing. Your algorithm is too simple. Hehe, I'm being direct, so please forgive any offense.
|
|
| Floor7 LanE | Posted 2003-06-27 00:00 |
| 银牌会员 Posts 648 Credits 1,835 | |
|
This really isn't that good. Then the poster above, give us a better algorithm:)
|
|
| Floor8 阿瑞斯 | Posted 2003-07-06 00:00 |
| 初级用户 Posts 25 Credits 176 | |
|
A long paper!
|
|
| Floor9 hit | Posted 2003-07-09 00:00 |
| 初级用户 Posts 148 Credits 688 From 陕西 | |
|
Explain the algorithm a bit
|
|
| Floor10 luler | Posted 2003-07-19 00:00 |
| 初级用户 Posts 5 Credits 111 | |
|
Something flashy but impractical. (Please don't attack me)
Pointless. |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |