Pascal/Turbo Pascal - Ayuda, necesito poder guardar un dibujo con la unit graph.

 
Vista:

Ayuda, necesito poder guardar un dibujo con la unit graph.

Publicado por Fede (4 intervenciones) el 06/07/2017 18:12:37
Hola, practicando para la universidad hice un codigo de una especie de "paint" pero que se usa con el teclado, y lo que quiero aprender a hacer es a guardar lo que dibuje con este programa como imagen. espero me sepan ayudar, estoy haciendo todo con la unit Graph usando putPixel. Aca les dejo el codigo, desde ya muchas gracias:
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
program dib;
uses graph,crt;
var
	driver,modo:integer;
	tecla:char;
	color,colorActual,x,y,velocidad:integer;
 
procedure mover(var x:integer;var y:integer;var colorAcual);
begin
	repeat begin
		colorActual:=GetPixel(x,y);
		repeat begin
			if colorActual=15 then begin
				putpixel(x,y,0);
			end
			else begin
				putpixel(x,y,15);
			end;
		end until KeyPressed();
		tecla:=readkey;
		case tecla of
			'8':begin
				putpixel(x,y,colorActual);
				y:=y-velocidad;
			end;
			'4':begin
				putpixel(x,y,colorActual);
				x:=x-velocidad;
			end;
			'6':begin
				putpixel(x,y,colorActual);
				x:=x+velocidad;
			end;
			'5':begin
				putpixel(x,y,colorActual);
				y:=y+velocidad;
			end;
		end;
	end until tecla='m';
	putpixel(x,y,colorActual);
end;
procedure borrar(var x:integer;var y:integer;color:integer);
begin
	colorActual:=GetPixel(x,y);
	color:=0;
	repeat begin
		putpixel(x,y,color);
		tecla:=readkey;
		case tecla of
			'8':y:=y-velocidad;
			'4':x:=x-velocidad;
			'6':x:=x+velocidad;
			'5':y:=y+velocidad;
		end
	end until tecla='k';
	color:=colorActual
end;
begin
	driver:=detect;
	initgraph(driver,modo,'');
	x:=getMaxX div 2; { Comienzo en el centro }
	y:=getMaxY div 2;
	color:=15;
	velocidad:=1;
	repeat begin
		tecla:=readkey;
		case tecla of
			'8':begin
				y:=y-velocidad;
				putpixel(x,y,color);
			end;
			'4':begin
				x:=x-velocidad;
				putpixel(x,y,color);
			end;
			'6':begin
				x:=x+velocidad;
				putpixel(x,y,color);
			end;
			'5':begin
				y:=y+velocidad;
				putpixel(x,y,color);
			end;
			'n':read(color);
			'b':ClearDevice;
			'm':mover(x,y,color);
			'v':read(velocidad);
			'k':borrar(x,y,color);
			'7':begin
				x:=x-velocidad;
				putpixel(x,y,color);
				y:=y-velocidad;
				putpixel(x,y,color);
			end;
			'9':begin
				x:=x+velocidad;
				putpixel(x,y,color);
				y:=y-velocidad;
				putpixel(x,y,color);
			end;
			'1':begin
				x:=x-velocidad;
				putpixel(x,y,color);
				y:=y+velocidad;
				putpixel(x,y,color);
			end;
			'3':begin
				x:=x+velocidad;
				putpixel(x,y,color);
				y:=y+velocidad;
				putpixel(x,y,color);
			end;
		end;
	end until tecla='f';
	closegraph;
end.
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