China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-09-15 00:54
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » Implementing artistic screen clearing in C [repost] View 1,669 Replies 9
Original Poster Posted 2003-06-22 00:00 ·  中国 江西 吉安 电信
版主
★★★★
Credits 7,296
Posts 1,628
Joined 2002-10-16 12:00
23-year member
UID 10
Gender Male
Status Offline
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
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
AlexZhang +2 2026-01-30 21:14
ko20010214
=================================
大功告成,打个Kiss!
ko20010214@MSN.com
神州优雅Q300C
Intel CeleronM 370处理器 | 256MbDDR内存
40G硬盘 | USB2.0 | IEEE 1394
13.3 ' WXGA 宽屏(16:10) | COMBO光驱
10/100M网卡 | 四合一读卡器
Floor 2 Posted 2003-06-22 00:00 ·  中国 四川 成都 教育网
初级用户
Credits 294
Posts 49
Joined 2003-05-16 00:00
23-year member
UID 2138
Gender Male
Status Offline
What language was the DOS system written in: assembly? C?
Floor 3 Posted 2003-06-22 00:00 ·  中国 湖北 随州 电信
元老会员
★★★
Credits 1,987
Posts 632
Joined 2002-10-27 00:00
23-year member
UID 73
Gender Male
Status Offline
Assembly
http://dos.e-stone.cn/dosbbs
uploadImages/200311161145850422.swf
Floor 4 Posted 2003-06-23 00:00 ·  中国 安徽 滁州 天长市 电信
银牌会员
★★★
Credits 1,835
Posts 648
Joined 2002-11-08 00:00
23-year member
UID 197
Gender Male
Status Offline
They all clear the screen by drawing spaces.
Floor 5 Posted 2003-06-24 00:00 ·  中国 重庆 教育网
初级用户
Credits 124
Posts 3
Joined 2003-06-15 00:00
23-year member
UID 5240
Gender Male
From chongqing
Status Offline
An unconventional way to clear the screen!!!
:)
Floor 6 Posted 2003-06-26 00:00 ·  中国 上海 静安区 电信
初级用户
Credits 112
Posts 4
Joined 2003-06-26 00:00
23-year member
UID 5956
Gender Male
Status Offline
This can't really be called artistic screen clearing. Your algorithm is too simple. Hehe, I'm being direct, so please forgive any offense.
Floor 7 Posted 2003-06-27 00:00 ·  中国 安徽 滁州 天长市 电信
银牌会员
★★★
Credits 1,835
Posts 648
Joined 2002-11-08 00:00
23-year member
UID 197
Gender Male
Status Offline
This really isn't that good. Then the poster above, give us a better algorithm:)
Floor 8 Posted 2003-07-06 00:00 ·  中国 浙江 杭州 华数宽带骨干网节点
初级用户
Credits 176
Posts 25
Joined 2003-07-03 00:00
23-year member
UID 6324
Gender Male
Status Offline
A long paper!
Floor 9 Posted 2003-07-09 00:00 ·  中国 陕西 西安 电信
初级用户
★★
孤胆枪手
Credits 688
Posts 148
Joined 2002-10-26 00:00
23-year member
UID 63
Gender Male
From 陕西
Status Offline
Explain the algorithm a bit
我:╭∩╮(︶︿︶)╭∩╮。靠!!!
Floor 10 Posted 2003-07-19 00:00 ·  中国 广西 南宁 电信
初级用户
Credits 111
Posts 5
Joined 2003-07-19 00:00
23-year member
UID 7170
Gender Male
Status Offline
Something flashy but impractical. (Please don't attack me)
Pointless.
Forum Jump: