Recent

Author Topic: creating moving ellipses with arrays  (Read 1806 times)

bradyhartsfield

  • New Member
  • *
  • Posts: 41
creating moving ellipses with arrays
« on: December 28, 2017, 02:14:35 pm »
hey,

i want to create multiple moving ellipses with arrays. i already programmed that i have one ellipse which is bouncing off the borders (width and height) but now i am struggling to add 19 others with arrays.
my first thought was to add "circles:array[1..19] of integer;" to  "var". but now i dont know how to go on.

regards
brady

btw
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  9.   StdCtrls;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     Button2: TButton;
  18.     Image1: TImage;
  19.     Timer1: TTimer;
  20.     Timer2: TTimer;
  21.     procedure Button1Click(Sender: TObject);
  22.     procedure Button2Click(Sender: TObject);
  23.     procedure FormCreate(Sender: TObject);
  24.     procedure Timer1Timer(Sender: TObject);
  25.   private
  26.  
  27.   public
  28.  
  29.   end;
  30.  
  31. var
  32.   Form1: TForm1;
  33.   mx, my, r, vx, vy : integer;
  34.   circle:array[1..19] of integer;
  35.  
  36. implementation
  37.  
  38. {$R *.lfm}
  39.  
  40. { TForm1 }
  41.  
  42. procedure TForm1.Button1Click(Sender: TObject);
  43. begin
  44.   timer1.enabled := true;
  45. end;
  46.  
  47. procedure TForm1.Button2Click(Sender: TObject);
  48. begin
  49.   timer1.enabled := false;
  50. end;
  51.  
  52. procedure TForm1.FormCreate(Sender: TObject);
  53. begin
  54.   doublebuffered := true;
  55.   mx := 10;
  56.   my := 10;
  57.   r := 10;
  58.   vx := 1;
  59.   vy := 1;
  60.   timer1.enabled := false;
  61. end;
  62.  
  63. procedure TForm1.Timer1Timer(Sender: TObject);
  64. begin
  65.   with image1.canvas do begin
  66.     pen.color := clblack;
  67.     brush.color := clblack;
  68.     ellipse(mx-r, my-r, mx+r, my+r);
  69.     mx:=mx+vx;
  70.     my:=my+vy;
  71.     pen.color:=clred;
  72.     brush.color:=clred;
  73.     ellipse(mx-r, my-r, mx+r, my+r);
  74.   end;
  75.  
  76.   if my+r>=image1.height
  77.   then vy:= -vy;
  78.   if mx+r>=image1.width
  79.   then vx:=-vx;
  80.   if my-r<0
  81.   then vy:=-vy;
  82.   if mx-r<0
  83.   then vx:=-vx;
  84.  
  85.  
  86.   end;
  87.  
  88.  
  89. end.
  90.  

bradyhartsfield

  • New Member
  • *
  • Posts: 41
Re: creating moving ellipses with arrays
« Reply #1 on: December 28, 2017, 02:19:48 pm »
hey,

maybe then add to the timer1 function:
for circle: 1 to 19 do begin
    r[circle] := 10;
    mx[circle] := 10;
    my[circle] := 10;
    vx[circle] := 1;
    vy[circle] := 1;



thats only an idea, and in addition to that how can i randomize the starting positions from my ellipses so they dont all start at the same x and y coordinate?

bradyhartsfield

  • New Member
  • *
  • Posts: 41
Re: creating moving ellipses with arrays
« Reply #2 on: December 28, 2017, 09:59:11 pm »
sorry for the mess guys!
the error thread was useless and i tried to delete this one because i thought that you cant understand my problem.

regards
nick

 

TinyPortal © 2005-2018