Pascal/Turbo Pascal - Eliminar grafico pero no limpiar toda la pantalla.

 
Vista:

Eliminar grafico pero no limpiar toda la pantalla.

Publicado por iñigo ozcoidi gallues (1 intervención) el 28/10/2015 00:43:22
Hola, es mi primera vez en este foro así que no se muy bien como funciona. El problema que me ha surgido es que quiero hacer que un un gráfico en forma de cuadrado(rojo) quiero que se mueva libremente, pero que un recuadro verde se quede fijo para ello habia pensado lo siguiente:

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
program dibujar;
 
uses graph, wincrt;
 
var
  driver, modo: integer;
  tecla: char;
  x, y: integer;
 
begin
  driver := detect;
  initgraph(driver, modo, '');
  setfillstyle(1,green);
  bar(0,900,10000,1800);
  setfillstyle(1,red);
  x := 512;
  y := 384;
  repeat
     ClearViewPort;
    bar(x,y,20+x,20+y);
    tecla := readkey;
    case tecla of
      '8': y := y-10;
      '4': x := x-10;
      '6': x := x+10;
      '2': y := y+10;
    end;
  until tecla = 'f';
  closegraph;
end.

Se que lo que ocurre es que se borra el recuadro verde antes justo después de ser creado y que una posible solución sería crear el cuadro verde cada vez que borras la pantalla. Pero si los elementos fijos son mas numerosos esto podría saturar el programa ya que crearía varias veces lo mismo. Mi pregunta es: ¿se puede borrar exclusivamente el recuadro rojo?
Gracias por vuestra atención.
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

Eliminar grafico pero no limpiar toda la pantalla.

Publicado por ramon (2158 intervenciones) el 01/11/2015 16:35:55
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
{Mira este ejemplo haber si te ayuda
Modifica esto a tu dirección
initgraph(driver, modo, 'c:\tp\bgi'); }
 
program dibujar;
 
uses
  graph, crt;
 
var
  driver, modo: integer;
  tecla: char;
  antx, anty, x, y: integer;
  temp, p : pointer;
  resc, tama : word;
  FillInfo: FillSettingsType;
 
begin
  driver := detect;
  initgraph(driver, modo, 'c:\tp\bgi');
  if GraphResult <> 0 then
  Halt(1);
  GetFillSettings(FillInfo);
  tama := imagesize(10,60,50,110);
  resc := imagesize(10,60,50,110);
  getmem(temp,resc);
  getmem(p, tama);
  getimage(10,60,50,110,temp^);
  SetFillStyle(SolidFill, GetMaxColor - 9);
  bar3d(10, 60, 50, 110, 0, topoff);
  getimage(10, 60, 50, 110, p^);
  putimage(10, 60, p^, normalput);
  x := 10;
  y := 60;
  antx := x;
  anty := y;
  outtextxy(100,getmaxy - 140,'Termina Tecla ESC Mueven Teclas Flechas');
  SetFillStyle(XHatchFill, GetMaxColor - 5);
  bar3d(100,100,160,160,0,topoff);
  SetFillStyle(XHatchFill, GetMaxColor - 4);
  bar3d(200,100,260,160,0,topoff);
  SetFillStyle(XHatchFill, GetMaxColor - 2);
  bar3d(100,200,160,260,0,topoff);
  with FillInfo do
  SetFillStyle(Pattern, Color);
  repeat
     tecla := readkey;
     if tecla = #0 then
     tecla := readkey;
     if tecla = #72 then
     begin
        putimage(antx, anty, p^, xorput);
        putimage(antx,anty,temp^,copyput);
        y := y - 1;
        if y < 10 then
        y := 10;
        getimage(x,y,x + 40,y + 50,temp^);
        putimage(x, y, p^, copyput);
        antx := x;
        anty := y;
     end;
    if tecla = #80 then
    begin
       putimage(antx, anty, p^, xorput);
       putimage(antx,anty,temp^,copyput);
       y := y + 1;
       if y > getmaxy - 194 then
       y := getmaxy - 194;
       getimage(x,y,x + 40,y + 50,temp^);
       putimage(x, y, p^, copyput);
       antx := x;
       anty := y;
    end;
    if tecla = #75 then
    begin
       putimage(antx, anty, p^, xorput);
       putimage(antx,anty,temp^,copyput);
       x := x - 1;
       if x < 10 then
       x := 10;
       getimage(x,y,x + 40,y + 50,temp^);
       putimage(x, y, p^, copyput);
       antx := x;
       anty := y;
    end;
    if tecla = #77 then
    begin
       putimage(antx, anty, p^, xorput);
       putimage(antx,anty,temp^,copyput);
       x := x + 1;
       if x > getmaxx - 15 then
       x := getmaxx - 15;
       getimage(x,y,x + 40,y + 50,temp^);
       putimage(x, y, p^, copyput);
       antx := x;
       anty := y;
     end;
  until tecla = #27;
  putimage(antx, anty, p^, xorput);
  putimage(antx,anty,temp^,copyput);
  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