S
S
samsungovetch2018-09-27 15:27:09
Pascal
samsungovetch, 2018-09-27 15:27:09

PascalABC - Simple keyboard drawing, questions?

Hello
, there is a task to make a simple drawing on the keys.
The question is this: when you press the buttons, there is a delay, i.e. - I press "right", "right", "right", "down", "down", and the picture goes "right", "right", "right", "right", "down". How to fix?
And another question - how to make a visible cursor that does not leave a trace in the form of a picture? Thanks in advance

uses graphabc,crt;

var x0,y0:integer;
    c:char;

const WH = 600;
      WW = 600;

begin
  SetBrushColor(clBlack);
  SetPenStyle(psSolid);
  x0:=0;
  y0:=0;
  while (1=1) do
    begin
      c:=readkey;
      case c of
      #75: begin  //left
             x0:=x0+10;
             rectangle(x0,y0,x0-10,y0+10);
           end;
      #77: begin  //right
             x0:=x0-10;
             rectangle(x0,y0,x0+10,y0-10);
           end;
      #72: begin  //up
             y0:=y0-10;
             rectangle(x0,y0,x0-10,y0+10);
           end;
      #80: begin  //down
             y0:=y0+10;
             rectangle(x0,y0,x0+10,y0-10);
           end;
      end;

    end;
end.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexalexes, 2018-09-27
@alexalexes

one)

when you press the buttons, there is a delay, i.e. - I press "right", "right", "right", "down", "down", and the picture goes "right", "right", "right", "right", "down". How to fix?

It's all about using an infinite while loop.
This style of programming is typical for microcontrollers.
In high-level languages, event handlers are used, in your case you need to add a keystroke handler and already write an action for the event in it, and not wait until this event occurs.
2) The canvas on which you draw must support layering. Drawing on one layer, cursor on another. No other way.
PS: I'm not familiar with PascalABC.
The solution is written on the general concepts of any programming language.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question