Copy Link
Add to Bookmark
Report

NULL mag Issue 09 18 Simple animator

eZine's profile picture
Published in 
null magazine
 · 3 years ago

this script is used to make simple animations with ascii/ansi chars. it will display a sequence of characters, to form an animation and it will also, replace the background chars, that may be overwritten. this way, the

animation will not interfere with the background image.

uses cfg; 
procedure anim(str:string);
type
tchar = record
x : byte;
y : byte;
a : byte;
c : char;
end;
var
buf : array[1..10] of tchar
i,d:integer;
s:string;
tmp:string;
wait:integer;
sx,sy:string;
sa:byte;
ch:char;
procedure clearbuf;
var a:byte;
begin
for a:=1 to 10 do begin
buf[a].x:=0;
buf[a].y:=0;
buf[a].a:=0;
buf[a].c:=' ';
end;
end;

procedure restorebuf;
var a:byte;
begin
for a := 1 to 10 do
if buf[a].x<>0 then writexy(buf[a].x,buf[a].y,buf[a].a,buf[a].c);
end;

begin
s := str;
if s[length(s)]<>';' then s:=s+';';
while length(s)>0 do begin
d := pos(';',s);
if d>0 then begin
tmp:=copy(s,1,d-1);
delete(s,1,d);
end else begin
tmp:=s;
end;
wait := str2int(copy(tmp,length(tmp)-2,3));
delete(tmp,length(tmp)-2,3);
i:=1;
clearbuf;
while length(tmp)>0 and i<11 do begin
buf[i].x:=str2int(copy(tmp,1,2));
buf[i].y:=str2int(copy(tmp,3,2));
buf[i].a:=GetAttrXY(buf[i].x,buf[i].y);
buf[i].c:=GetCharXY(buf[i].x,buf[i].y);
if buf[i].c=#0 then buf[i].c:=' ';
sa := str2int(copy(tmp,5,3));
ch := copy(tmp,8,1);
delete(tmp,1,8);
writexy(buf[i].x,buf[i].y,sa,ch);
i:=i+1;
end;
delay(wait);
restorebuf;
end;
end;

// frame field
// xxyyattc
// xx : two digit x position (ex. 03,10,70)
// yy : two digit y position (ex. 01,03,10,24)
// att : three digit color attribute. calculate like this: att = fg + (bg * 16)
// yellow on blue background is att = 14 + (1 * 16) = 31, so att = 031
// black on gray background is att = 0 + (7 * 16) = 112, so att = 112
// c : the character to display

begin
dispfile('logoff');
anim('1010014!500;1013014!510;1019014!510;1021014@510;');
anim('0921014`1021014#1121014\510;0921014.1021014:1121014,300');
anim('1010003.300;1010003o300;1010003O300');
anim('4015003.300;4015003o300;4015003O300');
anim('7005003.300;7005003o300;7005003O300');

gotoxy(1,24);
write('|PN');

end.

each frame is separated with the symbol ; you can have up to 10 frame fields in the same frame. each frame is drawn immediately. at the end of each frame you must enter a time delay in milliseconds from 000 to 999. if you don't want to delay the display just enter 000.

each frame field is 8 chars wide. if you do a mistake, the script may even crash. see frame field explanation above.

using the anim function, you can even make a script to use it as an oneliner to display animations inside menus.

← previous
next →
loading
sending ...
New to Neperos ? Sign Up for free
download Neperos App from Google Play
install Neperos as PWA

Let's discover also

Recent Articles

Recent Comments

Neperos cookies
This website uses cookies to store your preferences and improve the service. Cookies authorization will allow me and / or my partners to process personal data such as browsing behaviour.

By pressing OK you agree to the Terms of Service and acknowledge the Privacy Policy

By pressing REJECT you will be able to continue to use Neperos (like read articles or write comments) but some important cookies will not be set. This may affect certain features and functions of the platform.
OK
REJECT