Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program snake;
- uses crt, graph;
- var graphicsdriver,graphicsmode:smallint;
- entry,active,n,count,s,r:integer;
- x,y:array of integer;
- b:array[1..2] of integer;
- procedure varinit;
- begin
- b[1] := 1000;
- b[2] := 600;
- end;
- procedure opgr;
- begin
- active := 1;
- graphicsdriver := detect;
- initgraph(graphicsdriver, graphicsmode,'');
- end;
- procedure clgr;
- begin
- active := 0;
- closegraph;
- end;
- procedure valout;
- begin
- textcolor(lightred);
- write('* Please enter a number within the defined parameters. ');
- textcolor(yellow);
- write('[1..6]');
- writeln();
- textcolor(lightgray);
- end;
- procedure coordout;
- begin
- textcolor(lightred);
- write('* Your entered coordinate is out of the border. ');
- textcolor(yellow);
- write('[',b[1],' x ',b[2],']');
- writeln();
- textcolor(lightgray);
- end;
- procedure border;
- begin
- rectangle(0,0,b[1],b[2]);
- end;
- procedure xyvals;
- begin
- count := n;
- for n := 1 to count do
- begin
- repeat
- textcolor(lightgray);
- write('Please enter the value of ');
- textcolor(white);
- write('x');
- textcolor(yellow);
- write('[',n,']');
- textcolor(lightgray);
- if n = 1 then
- begin
- textcolor(lightgreen);
- write(' (the origin coordinates).');
- textcolor(lightgray);
- end
- else
- begin
- write('.');
- end;
- writeln();
- readln(x[n]);
- if (x[n] < 1) or (x[n] > (b[1]-1)) then
- begin
- coordout;
- end;
- until (x[n] > 0) and (x[n] < b[1]);
- //
- repeat
- textcolor(lightgray);
- write('Please enter the value of ');
- textcolor(white);
- write('y');
- textcolor(yellow);
- write('[',n,']');
- textcolor(lightgray);
- if n = 1 then
- begin
- textcolor(lightgreen);
- write(' (the origin coordinates).');
- textcolor(lightgray);
- end
- else
- begin
- write('.');
- end;
- writeln();
- readln(y[n]);
- if (y[n] < 1) or (y[n] > (b[2]-1)) then
- begin
- coordout;
- end;
- until (y[n] > 0) and (y[n] < b[2])
- end;
- end;
- procedure tri;
- begin
- n := 3;
- setlength(x, n);
- setlength(y, n);
- xyvals;
- opgr;
- border;
- line(x[1],y[1],x[2],y[2]);
- line(x[2],y[2],x[3],y[3]);
- line(x[3],y[3],y[1],y[1]);
- delay(3000);
- clgr;
- end;
- procedure rect;
- begin
- n := 2;
- setlength(x, n);
- setlength(y, n);
- xyvals;
- opgr;
- border;
- rectangle(x[1],y[1],x[2],y[2]);
- delay(3000);
- clgr;
- end;
- procedure squ;
- begin
- n := 1;
- setlength(x, n);
- setlength(y, n);
- xyvals;
- repeat
- writeln('Please enter the side length of the square.');
- readln(s);
- if ((x[1]+s) > (b[1]-1)) or ((y[1])+s > (b[2]-1)) or ((x[1]-s) < 1) or ((y[1]-s) < 1) then
- begin
- textcolor(lightred);
- write('* Your entered side length causes the square to exceed the border. ');
- textcolor(yellow);
- write('[',b[1],' x ',b[2],']');
- writeln();
- textcolor(lightgray);
- end;
- until ((x[1])+s < b[1]) and ((y[1])+s < b[2]) and ((x[1]-s) > 0) and ((y[1]-s) > 0);
- opgr;
- border;
- rectangle(x[1],y[1],x[1]+s,y[1]+s);
- delay(3000);
- clgr;
- end;
- procedure circ;
- begin
- n := 1;
- setlength(x, n);
- setlength(y, n);
- xyvals;
- repeat
- writeln('Please enter the radius of the circle.');
- readln(r);
- if ((x[1]+r) > (b[1]-1)) or ((y[1])+r > (b[2]-1)) or ((x[1]-r) < 1) or ((y[1]-r) < 1) then
- begin
- textcolor(lightred);
- write('* Your entered radius causes the circle to exceed the border. ');
- textcolor(yellow);
- write('[',b[1],' x ',b[2],']');
- writeln();
- textcolor(lightgray);
- end;
- until ((x[1])+r < b[1]) and ((y[1])+r < b[2]) and ((x[1]-r) > 0) and ((y[1]-r) > 0);
- opgr;
- border;
- circle(x[1],y[1],r);
- delay(3000);
- clgr;
- end;
- procedure scr;
- begin
- end;
- procedure proc;
- begin
- case entry of
- 1:tri;
- 2:rect;
- 3:squ;
- 4:circ;
- 5:scr;
- 6:halt(0);
- end;
- end;
- procedure menu;
- begin
- textcolor(lightgray);
- writeln('1. Draw Triangle');
- writeln('2. Draw Rectangle');
- writeln('3. Draw Square');
- writeln('4. Draw Circle');
- writeln('5. Screensaver');
- textcolor(lightmagenta);
- writeln('6. EXIT');
- textcolor(lightgray);
- writeln();
- repeat
- write('Please enter your option ');
- textcolor(lightcyan);
- write('[1..6]');
- writeln();
- textcolor(lightgray);
- readln(entry);
- if (entry < 1) or (entry > 6) then
- begin
- valout;
- end;
- until (entry > 0) and (entry < 7);
- end;
- begin
- varinit;
- while true do
- begin
- clrscr;
- menu;
- proc;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement