Programación General > Pascal
Letras En Espiral
Enko:
{ La funcion 'Car' fue hecha gracias a .B. y chujkero miembros de la }
{pag.¡Saludos :hola: ! }
{ El programa llena la pantalla con letras al azar de 'A' a 'Z' sigiuendo una espiral}
program Espiral;
uses Crt;
const
Tiempo = 1000; {Modifica segun la velocidad de tu ordenador !
En el mio anduvo BIEN.}
var
Control : integer; { Lleva el control de las repeticiones }
X,Y : byte; { Variables de tipo contador }
Xi,Xf : byte;
Yi,Yf : byte;
procedure InitTextMode; {Inicia todas las variabes con sus valores}
begin
Randomize;
TextMode(C80); { Inicia modo CGA 80*25 ( casi indespensable en mi win XP)}
Window(1,1,80,25);
TextBackground(0);
Textcolor(10);
ClrScr;
X := 1;
Y := 1;
Xf := 79;
Yf := 24;
Xi := 1;
Yi := 1;
Control := 1;
end;
function Car : char; { Saca al azar letras de la 'A' a 'Z'}
begin
Car := Chr(Random(25)+65);
end;
begin { El begin principal}
InittextMode;
repeat
while X < Xf do { Aqui se comienza a dibujar la espiral}
begin
GotoXY(X+1,Yi);
Write(car);
X := X+1;
if KeyPressed then Break; { Por si se presiona una tecla para el Bucle}
Delay(Tiempo);{ Aqui es donde se hace mas lento el movimiento}
end;
while Y < Yf do
begin
Y := Y+1;
GotoXY(Xf,Y);
Write(car);
if KeyPressed then Break;
Delay(Tiempo);
end;
while X > Xi do
begin
GotoXY(X,Yf);
Write(car);
X := X-1;
if KeyPressed then Break;
Delay(Tiempo);
end;
while Y > Yi do
begin
GotoXY(Xi,Y);
Write(car);
Y := Y-1;
if KeyPressed then Break;
Delay(Tiempo);
end;
Xi := Xi+1; { Parte necesaria para que continue la espiral}
Yi := Yi+1;
Xf := Xf-1;
Yf := Yf-1;
Control := Control+1; {Lleva el control de las repiticiones}
until (KeyPressed) or (Control = 13); { Me parece que el
KeyPressed esta demas pero ...}
ReadLn;
end.
_.B._:
:good: Good!.
Ahora, se me ocurre, podrias meterle por ahi un TextColor random a ver que tal.
Suerte, y a programar!.
Bernardo L. :comp:
Enko:
:P Hola de Vuelta !
Le meti desde el principio el TextColor pero............. <_<
.... <_< para hacerlo mas censillito ........Uno nunca sabe
:comp: Tambien a quien le interesa puede agregar en la funcion de constantes la sig linea :
const
car = #176;
esto hara que escriba cuadrados.
¡ Oho al piojo , cambien le el nombre al la funcion" Car" el nombre a "Caracter"
o bien , borela completamente sino :blink: Manda un ERROR.
_.B._:
Eugenio, 'tas seguro?. Yo lo corri con el codigo COPIADO y PEGADO que tu escribistes, y me corrio bien.
Enko:
aqui esta el mismo programa pero utilizando recursividad y TestColor.
[Cprogram Demo;
uses Crt;
const
Tiempo = 100; {Modifica segun la velocidad de tu ordenador !
En el mio anduvo BIEN.}
Car = #176;
var
Control : integer; { Lleva el control de las repeticiones }
X,Y : byte; { Variables de tipo contador }
Xi,Xf : byte;
Yi,Yf : byte;
procedure InitTextMode; {Inicia todas las variabes con sus valores}
begin
Randomize;
TextMode(C80); { Inicia modo CGA 80*25 ( casi indespensable en mi win XP)}
Window(1,1,80,25);
TextBackground(0);
Textcolor(10);
ClrScr;
X := 1;
Y := 1;
Xf := 79;
Yf := 24;
Xi := 1;
Yi := 1;
Control := 1;
end;
function Caro : char; { Saca al azar letras de la 'A' a 'Z'}
begin
Caro := Chr(Random(25)+65);
end;
procedure espiralado; { El begin principal}
begin
repeat
while X < Xf do { Aqui se comienza a dibujar la espiral}
begin
GotoXY(X+1,Yi);
Write(car);
X := X+1;
if KeyPressed then Exit; { Por si se presiona una tecla para el Bucle}
Delay(Tiempo);{ Aqui es donde se hace mas lento el movimiento}
end;
while Y < Yf do
begin
Y := Y+1;
GotoXY(Xf,Y);
Write(car);
if KeyPressed then Exit;
Delay(Tiempo);
end;
while X > Xi do
begin
GotoXY(X,Yf);
Write(car);
X := X-1;
if KeyPressed then Exit;
Delay(Tiempo);
end;
while Y > Yi do
begin
GotoXY(Xi,Y);
Write(car);
Y := Y-1;
if KeyPressed then Exit;
Delay(Tiempo);
end;
Xi := Xi+1; { Parte necesaria para que continue la espiral}
Yi := Yi+1;
Xf := Xf-1;
Yf := Yf-1;
TextColor(Random(15)+1);
Control := Control+1; {Lleva el control de las repiticiones}
until Control = 13;
ClrScr;
InitTextMode;
Espiralado; { La parte recursiva}
end ;
begin
InitTextMode;
Espiralado;
end.
ODE]programa[/CODE]
Navegación
[#] Página Siguiente
Ir a la versión completa