Pascal/Turbo Pascal - Movimiento Matriz Pascal

 
Vista:

Movimiento Matriz Pascal

Publicado por noc107 (1 intervención) el 07/12/2011 20:12:20
Hola, soy nuevo en el foro.
Les escribo para ver si me pueden ayudar con un problema en pascal del tipo de matrices..
Me mandan a recorrer una matriz en forma de zig zag espiral hacia el centro
y tambien en diagonal en ambos sentidos de antemano gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Movimiento Matriz Pascal

Publicado por ramon (2158 intervenciones) el 14/12/2011 21:27:35
{Hay varias formas dime si esta te sirve}

program zigzag;
uses
crt;
type
mat = array[0..63] of integer;


var
matriz : mat;
one : array[0..7,0..7] of integer;
p, x, y : integer;

procedure zigzagmatriz(matri : mat);
var
posx, posy, ti : integer;
xc, yc, xx, yy : integer;
sal : boolean;
begin
ti := 0;
xc := 0;
yc := 0;
xx := xc;
yy := yc;
sal := false;
repeat
one[xx][yy] := matri[ti];
ti := ti + 1;
if ti > 63 then
sal := true;
case ti of
1,6,15,28,36,49,58,63 : xx := xx + 1;

2,7,8,9,16,17,18,19,20,29,30,31,32,33,34,35,44,45,46,47,
48,55,56,57,62 : begin
xx := xx - 1;
yy := yy + 1;
end;

3,10,21,43,54,61 : yy := yy + 1;

4,5,11,12,13,14,22,23,24,25,26,27,37,38,39,40,41,42,50,
51,52,53,59,60 : begin
xx := xx + 1;
yy := yy - 1;
end;
end;
until (sal = true) or (ti > 63);
gotoxy(40,1);write(' En zigzag ');
for xc := 0 to 7 do
for yc := 0 to 7 do
begin
gotoxy(40 + (xc * 3),(2 + (yc + 1)));write(' ',one[xc][yc]);
end;
end;

begin
clrscr;
for x := 0 to 63 do
matriz[x] := x + 1;
gotoxy(4,1);write(' Original ');
y := 0;
x := 1;
p := 1;
repeat
gotoxy(3 + x,2 + p);write(matriz[y]);
y := y + 1;
x := x + 3;
if x > 24 then
begin
x := 1;
p := p + 1;
end;
until y > 63;
zigzagmatriz(matriz);
readln;
end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Movimiento Matriz Pascal

Publicado por leo (4 intervenciones) el 04/01/2012 03:55:21
Hola Ramon veo que le diste una solucion al de arriba, yo estoy haciendo un proyecto pero me tranque en la parte de hacer una matriz que se rellene con colores aleatoria, sera que me puedes hechar una manito, Gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Movimiento Matriz Pascal

Publicado por ramon (2158 intervenciones) el 05/01/2012 21:38:10
{Esto te crea una matriz de 15 colores distintos esta como veras en modo texto si es en
gráficos tendrías que darle los colores que quisieras o que tuviera el modo gráfico}

program colores;
uses
crt;

var
p, nume : integer;
num : array[0..15] of integer;

procedure asignanum;
var
i, t : integer;
si : byte;
begin
randomize;
i := 1;
repeat
nume := random(33);
si := 0;
t := 1;
repeat
if (num[t] = nume) or (nume > 15) then
begin
si := 1;
end;
t := t + 1;
until (t > 15) or (si = 1);
if si = 0 then
begin
num[i] := nume;
i := i + 1;
end;
until i > 15;
for i := 1 to 15 do
begin
textcolor(num[i]);
write(num[i],' ');
textcolor(15);
end;
end;


begin
clrscr;
asignanum;
readln;
end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Movimiento Matriz Pascal

Publicado por leo (4 intervenciones) el 05/01/2012 21:54:55
Hola Ramon gracias por tu respuesta, disculpa la molestia. Sabes que he intentado pasar la matriz a modo grafico pero solo me sale la pantalla en negro y despues me sale la pantalla en modo texto, yo intento hacer una matriz de cuadros, es decir, que el usuario meta 5x5 columnas y filas y que se coloquen en cuadro y se pongan aleatoria los colores en esos cuadros, pero no lo he podido, tengo la parte de que se crea los cuadros pero no lo toma en el modo grafico, Tienes algun correo o algo? Disculpa la molestia
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Movimiento Matriz Pascal

Publicado por ramon (2158 intervenciones) el 06/01/2012 11:45:29
[Perdona pero solo respondo aqui te comento en modo grafico seria de otra forma primero
define una matriz de color luego ejecuta esto con los valores de la matriz,}

program colores;
uses
crt, graph;
const
paleta : FillPatternType = ($ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff);
var
h, x, y, p, nume : integer;
num : array[0..15] of integer;
driver, modo : integer;


procedure asignanum;
var
i, t : integer;
si : byte;
begin
randomize;
i := 1;
repeat
nume := random(33);
si := 0;
t := 1;
repeat
if (num[t] = nume) or (nume > 15) then
begin
si := 1;
end;
t := t + 1;
until (t > 15) or (si = 1);
if si = 0 then
begin
num[i] := nume;
i := i + 1;
end;
until i > 15;
end;


begin
clrscr;
asignanum;
driver := detect;
initgraph(driver, modo,'c:\tp\bgi');
if graphresult <> 0 then
halt;
x := 10;
y := 10;
for h := 1 to 15 do
begin
setfillpattern(paleta,num[h]);
bar(x,y,x + 20,y + 20);
x := x + 24;
if x > 500 then
begin
y := y + 24;
x := 10;
end;
end;
readln;
closegraph;
end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Movimiento Matriz Pascal

Publicado por leo (4 intervenciones) el 21/01/2012 21:57:34
Hola Ramon gracias por la ayuda, estoy haciendo un proyecto de un juego, pero me tranque en la parte de comer hacer que me funciones las flechas en movimientos, es decir, el juego va subiendo con ciertas condicienones entonces como hago para que me lea las teclas de movimientos? Muchas gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Movimiento Matriz Pascal

Publicado por alejandro ibarra (1 intervención) el 28/11/2014 17:15:04
buenas ramón muy efectiva tu respuesta pero necesito rellenar una matriz de forma espiral tanto desde afuera hacia a adentro como al contrario
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Movimiento Matriz Pascal

Publicado por ramon (2158 intervenciones) el 03/12/2014 00:35:18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
{Mira esto te hayudara}
 
 program matrizespiral;
 uses
   crt;
  const
     maxx = 8;
     maxy = maxx;
 
 
   type
      lamatriz = array[1..maxx,1..maxy] of integer;
 
 
  var
    matriz : lamatriz;
    x, y, cont : integer;
 
 
 
 
  procedure rellenamatriz(var m : lamatriz);
  begin
     x := 1;
     y := 1;
     for cont := 1 to (maxx * maxx) do
     begin
        m[x,y] := cont;
        x := x + 1;
        if x > maxx then
        begin
           y := y + 1;
           x := 1;
        end;
     end;
  end;
 
  procedure presentaoriginal(m : lamatriz);
  begin
     writeln;
     writeln;
     for y := 1 to maxx do
     begin
        write('   ');
        for x := 1 to maxx do
        begin
           if m[x,y] in [1..9] then
           write('   ',m[x,y])
        else
           write('  ',m[x,y]);
        end;
        writeln;
        writeln;
      end;
  end;
 
  procedure recorrido_en_espiral_hacia_dentro(m : lamatriz);
  var
     t, h, hh, h1, v, vv, v1 : integer;
     sal : boolean;
  begin
     x := 45;
     y := 3;
     hh := maxx;
     h1 := 1;
     vv := maxx;
     v1 := 1;
     sal := false;
     t := 1;
  repeat
      for h := h1 to hh do
      begin
         gotoxy(x + (h * 3),y + (v1 * 2));write(m[h,v1]);
         delay(200);
      end;
      for v := v1 + 1 to vv do
      begin
         gotoxy(x + (h * 3),y + (v * 2));write(m[h,v]);
         delay(200);
      end;
      for h := hh - 1 downto h1 do
      begin
         gotoxy(x + (h * 3),y + (vv * 2));write(m[h,vv]);
         delay(200);
      end;
      for v := vv - 1 downto v1 + 1 do
      begin
         gotoxy(x + (h * 3),y + (v * 2));write(m[h,v]);
         delay(200);
      end;
      h1 := h1 + 1;
      hh := hh - 1;
      v1 := v1 + 1;
      vv := vv - 1;
  t := t + 1;
  if t > 8 then
  sal := true;
  until sal = true;
  end;
 
  procedure recorrido_en_espiral_hacia_fuera(m : lamatriz);
  var
     t, h, hh, h1, v, vv, v1 : integer;
     sal : boolean;
  begin
     h1 := round(maxx / 2);
     if maxy mod 2 = 0 then
     v1 := round(maxy / 2) + 1
   else
     v1 := round(maxy / 2);
     hh := h1 + 1;
     vv := v1 - 1;
     sal := false;
     t := 0;
     x := 15;
     y := 24;
  repeat
      t := t + hh - h1;
      if t > (maxx * maxy) then
      break;
      for h := h1 to hh do
      begin
         gotoxy(x + (h * 3),y + (v1 * 2));write(m[h,v1]);
         delay(200);
      end;
      t := t + v1 - vv;
      if t > (maxx * maxy) then
      break;
      for v := v1 downto vv do
      begin
         gotoxy(x + (h * 3),y + (v * 2));write(m[h,v]);
         delay(200);
      end;
      h1 := h1 - 1;
      if h1 < 1 then
      h1 := 1;
      t := t + hh - h1;
      if t > (maxx * maxy) then
      break;
      for h := hh downto h1 do
      begin
         gotoxy(x + (h * 3),y + (vv * 2));write(m[h,vv]);
         delay(200);
      end;
      v1 := v1 + 1;
      if v1 > maxx then
      v1 := maxx;
      t := t + v1 - vv;
      if t > (maxx * maxy) then
      break;
      for v := vv to v1 do
      begin
         gotoxy(x + (h * 3),y + (v * 2));write(m[h,v]);
         delay(200);
      end;
      hh := hh + 1;
      vv := vv - 1;
      if hh > maxx then
      hh := maxx;
      if vv < 1 then
      vv := 1;
      if t > (maxx * maxy) then
      sal := true;
    until sal = true;
  end;
 
 
 
  begin
      clrscr;
      rellenamatriz(matriz);
      presentaoriginal(matriz);
      recorrido_en_espiral_hacia_dentro(matriz);
      recorrido_en_espiral_hacia_fuera(matriz);
      readkey;
  end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar