Board index » delphi » how to clear screen and paint thereafter ?

how to clear screen and paint thereafter ?

Hi !

My problem is the following source code. When I "activate" clearscreen
(means I do not // it), I only see a black form and not a form with a
red graphic on it. Why ??

procedure tform1.clearscreen;
begin
  PaintBox1.Canvas.Pen.Width := 1;
  PaintBox1.Canvas.Brush.Style := bsSolid;
  PaintBox1.Canvas.Brush.Color := clBlack;
  PaintBox1.Canvas.Rectangle(0, 0, clientwidth, clientheight);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var a,x,y, i, dist : integer;
begin
  for i := 0 to clientheight do
  begin
    clearscreen;
    dist := abs(trunc( sin((i+(a*10))/20) * 20 ));
    y := i;
    x := 50+dist;
    PaintBox1.canvas.pixels[x,y] := clRed;
    x := 50-dist;
    PaintBox1.canvas.pixels[x,y] := clRed;
    if (i mod 10) = 0 then
    for x := 50-dist to 50+dist do
    PaintBox1.canvas.pixels[x,y] := clRed;
  end;
  timer1.tag := timer1.tag+1;
end;

 

Re:how to clear screen and paint thereafter ?


Quote
Christopher Renning wrote:
> My problem is the following source code. When I "activate" clearscreen
> (means I do not // it), I only see a black form and not a form with a
> red graphic on it. Why ??

   Put Application.ProcessMessages...

Quote
> procedure TForm1.Timer1Timer(Sender: TObject);
> var a,x,y, i, dist : integer;
> begin
>   for i := 0 to clientheight do
>   begin
>     clearscreen;
>     dist := abs(trunc( sin((i+(a*10))/20) * 20 ));
>     y := i;
>     x := 50+dist;
>     PaintBox1.canvas.pixels[x,y] := clRed;
>     x := 50-dist;
>     PaintBox1.canvas.pixels[x,y] := clRed;
>     if (i mod 10) = 0 then
>     for x := 50-dist to 50+dist do
>     PaintBox1.canvas.pixels[x,y] := clRed;

      Application.ProcessMessages;   // <--- here

Quote
>   end;
>   timer1.tag := timer1.tag+1;  // ???
> end;

Cheers,
--
Marko Peric

Re:how to clear screen and paint thereafter ?


Maybe your pen mode is set wrong ?
Quote
Christopher Renning wrote:
> Hi !

> My problem is the following source code. When I "activate" clearscreen
> (means I do not // it), I only see a black form and not a form with a
> red graphic on it. Why ??

> procedure tform1.clearscreen;
> begin
>   PaintBox1.Canvas.Pen.Width := 1;
>   PaintBox1.Canvas.Brush.Style := bsSolid;
>   PaintBox1.Canvas.Brush.Color := clBlack;
>   PaintBox1.Canvas.Rectangle(0, 0, clientwidth, clientheight);
> end;

> procedure TForm1.Timer1Timer(Sender: TObject);
> var a,x,y, i, dist : integer;
> begin
>   for i := 0 to clientheight do
>   begin
>     clearscreen;
>     dist := abs(trunc( sin((i+(a*10))/20) * 20 ));
>     y := i;
>     x := 50+dist;
>     PaintBox1.canvas.pixels[x,y] := clRed;
>     x := 50-dist;
>     PaintBox1.canvas.pixels[x,y] := clRed;
>     if (i mod 10) = 0 then
>     for x := 50-dist to 50+dist do
>     PaintBox1.canvas.pixels[x,y] := clRed;
>   end;
>   timer1.tag := timer1.tag+1;
> end;

Other Threads