首页 > 编程语言 >Delphi 经典游戏程序设计40例 的学习 例27 残留的轨迹是抛物线

Delphi 经典游戏程序设计40例 的学习 例27 残留的轨迹是抛物线

时间:2022-09-07 20:59:16浏览次数:80  
标签:begin 27 end Sender Delphi 40 TObject Image1 procedure

 

unit R27;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TRei27 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    ScrollBar1: TScrollBar;
    ScrollBar2: TScrollBar;
    ScrollBar3: TScrollBar;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Image1: TImage;
    Timer1: TTimer;
    Edit3: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure ScrollBar1Change(Sender: TObject);
    procedure ScrollBar2Change(Sender: TObject);
    procedure ScrollBar3Change(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Rei27: TRei27;
  Stn : Byte;
  X,Y,DX,DY,MX,QX,b,c : Integer;
  a : Single;
  RectD : TRect;



implementation

{$R *.dfm}

procedure TRei27.FormCreate(Sender: TObject);
begin
  St := 0 ;
  b := 120;
  c := 250;
  DX := 4;
  ScrollBar1.Position := b;
  ScrollBar2.Position := c;
  ScrollBar3.Position := DX;
end;

procedure TRei27.Timer1Timer(Sender: TObject);
begin
  case St of
    0: begin
      RectD := Rect(0,0,Image1.Width,Image1.Height);
      Image1.Canvas.Brush.Color := clBlack;
      Image1.Canvas.FillRect(RectD);
      Edit1.Text := ' ' + IntToStr(b * 2);
      Edit2.Text := ' ' + IntToStr(c);
      Edit3.Text := ' ' + IntToStr(DX);
      if DX < 0 then
      begin
        X := Image1.Width div 2 + b;
        MX := b;
      end
      else begin
        X := Image1.Width div 2 - b;
        MX := -b;
      end;
      a := -c / (b * b);
      if a < 0 then
        Y := 0
      else
        Y := Image1.Height;
      St := 1;
    end;

    1: begin
      Qx := MX;
      MX := MX + DX;
      DY := Round(a * (MX * MX - QX * QX));
      X := X + DX;
      Y := Y + DY;
      Image1.Canvas.Pixels[X,Y] := clWhite;
      Image1.Canvas.Pixels[X + 1,Y] := clWhite;
      if (X <= 0) or (X >= Image1.Width) then
        St := 2;
    end;
  end;
end;

procedure TRei27.ScrollBar1Change(Sender: TObject);
begin
  b := ScrollBar1.Position;
  Edit1.Text := ' ' + IntToStr(b * 2);
end;

procedure TRei27.ScrollBar2Change(Sender: TObject);
begin
   c := ScrollBar2.Position;
   Edit2.Text := ' ' + IntToStr(c);
end;

procedure TRei27.ScrollBar3Change(Sender: TObject);
begin
  DX := ScrollBar3.Position;
  Edit3.Text := ' ' + IntToStr(DX);
end;

procedure TRei27.Button1Click(Sender: TObject);
begin
  St := 0;
end;

end.

1,前2天估计有BUG ,网站不能发帖。

2,忘记保存了,注释没有了。

3,程序结构简单,在TIMER中绘图,用间隔 实现了一个点一个点显示的效果?

4,对三角函数的应用,三角函数还是搞不明白,开始一点还能明白,后面都是对基本公式的变化使用了,

   尤其是对三角函数对应坐标系的讲解

    只能套用公式吧

5,实数 ,实数取整函数

6,以后几个程序例子,都是这个界面,可以套用下了。

标签:begin,27,end,Sender,Delphi,40,TObject,Image1,procedure
From: https://www.cnblogs.com/D7mir/p/16667198.html

相关文章