|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
|||
|
|||
Перемещение эллипса по параболе
Код:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls; type TForm1 = class(TForm) Image1: TImage; Image2: TImage; Image3: TImage; BitBtn1: TBitBtn; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; Label9: TLabel; Timer1: TTimer; procedure BitBtn1Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { Private declarations } public procedure procABC(x1,x2,x3,y1,y2,y3:integer;var a,b,c:Real); { Public declarations } end; var Form1: TForm1; a,b,c:Real; x,y,r,x1,x2,x3,y1,y2,y3,i,Ypar:Integer; implementation {$R *.dfm} procedure Tform1.procABC(x1,x2,x3,y1,y2,y3:integer;var a,b,c:Real); begin a:=( y3-(x3*(y2-y1)+x2*y1-x1*y2)/(x2-x1) )/(x3*(x3-x1-x2)+x1*x2 ); label7.caption:='a = '+floattostr((a)); b:=(y2-y1)/(x2-x1)-a*(x1+x2); label8.caption:='b = '+floattostr((b)); c:=(x2*y1-x1*y2)/(x2-x1)+a*x1*x2; label9.caption:='c = '+floattostr((c)); end; procedure TForm1.BitBtn1Click(Sender: TObject); begin randomize; r:=random(50)+1; x1:=image1.left+32; y1:=image1.Top+r; x2:=image2.left+32; y2:=image2.Top+r; x3:=image3.left+32; y3:=image3.Top; label1.Caption:='Left x1:= '+inttostr(x1); label2.Caption:='Top y1:= '+inttostr(y1); label3.Caption:='Left x2:= '+inttostr(x2); label4.Caption:='Top y2:= '+inttostr(y2); label5.Caption:='Left x3:= '+inttostr(x3); label6.Caption:='Top y3:= '+inttostr(y3); procABC(x1,x2,x3,y1,y2,y3,a,b,c); for i:=x3 to x1 do Canvas.Pixels[i,Round(a*i*i+b*i+c)]:=clRed; Timer1.Enabled:=True; x:=x3; end; procedure TForm1.Timer1Timer(Sender: TObject); var y:Integer; begin DoubleBuffered := True; if x>x1 then Exit; Canvas.Brush.Color:=Color; //Canvas.FillRect(Canvas.ClipRect); y:=Round(a*x*x+b*x+c); Canvas.Ellipse(x,y,x+5,y+5); x:=x+10; end; end. Нужно изменить место полета эллипса . Тоесть эллипс начинает своё движение с левой точки в правую , нужно сделать наоборот , чтобы справа налево он двигался |
#2
|
||||
|
||||
В таймере измени приращение X на уменьшение и в процедуре нажатия кнопки, измени начальные координаты.
Je venus de nulle part 55.026263 с.ш., 73.397636 в.д. |
#3
|
|||
|
|||
Да вы правы
Кнопа1 Цитата:
Таймер1 Цитата:
----------- Эллипс отправился в ад |
#4
|
||||
|
||||
Достаточно изменить в процедуре BitBtn1Click последнюю строку с x := x3; на x := x1; и в процедуре таймера x := x + 10; на x := x - 10;
Je venus de nulle part 55.026263 с.ш., 73.397636 в.д. |
#5
|
|||
|
|||
Цитата:
|