I tried the previous suggestion. I cannot use it.
Scenario: simulation program
Use timer to update / refresh images to mimic animation / simulation
first run sets up the the initial values and calculates the base illustration
normal run takes the values from the first run and keeps running and updating until user ends program or barriers reached then the animation stops
Procedure RedrawWeights();
begin
TimeInterval := TimeInterval + 1;
MyForm.TxtGreenX1.Text:=inttostr(MyForm.MovingWeight.Left);
MyForm.TxtGreenY1.Text:=inttostr(MyForm.MovingWeight.Top);
MyForm.txtrednewx1.Text:=inttostr(MyForm.PullingWeight.Left);
MyForm.txtrednewy1.Text:=inttostr(MyForm.PullingWeight.Top);
ForceMovingWeight:= ForceDisplacement(StrToFloat(MyForm.TxtMovingWeight.Text),StrtoFloat(MyForm.TxtMovingAngle.Text));
MyForm.txtupwardForceMWF.Text:=Floattostr(ForceMovingWeight);
ForcePullingWeight := ForceDisplacement(StrToFloat(MyForm.TxtPullingWeight.Text),StrtoFloat(MyForm.TxtPullingAngle.Text));
MyForm.txtDownwardForcePWF.Text:=Floattostr(ForcePullingWeight);
movingacceleration:= acceleration(round(ForcePullingWeight), round(ForceMovingWeight));
MyForm.txtAcceleration.Text:=FloattoStr(Movingacceleration);
MWTension:=CalcTension(Movingacceleration, ForceMovingWeight);
MyForm.txttension.text:=FloattoStr(MWTension);
CurrentVelocityValue:=Velocity(TotalVelocityValue, movingacceleration, TimeInterval);
DistanceCovered:=Distance(TotalVelocityValue,CurrentVelocityValue, TimeInterval);
TotalDistanceCovered:=TotalDistanceCovered + (DistanceCovered/10);
MyForm.txtDistanceCovered.Text:=inttostr(round(TotalDistanceCovered));
MyForm.txtElapsedTime.Text:=inttostr(TimeInterval);
//Calculating pullingWeight Angle
MyForm.txtPullingAngle.Text:=inttoStr(CalcPullingWeightAngle((CalcLength(basex3, basex2, basey3, basey2)), (Basex2-Basex1), (CalcLength(basex3, basex1, basey3, basey1))));
TotalVelocityValue:=TotalVelocityValue+CurrentVelocityValue;
//Plot New Location Of Moving Weight (Green)
TempGradient:=CalcGradient(basex1, basey1, round(basex3), round(basey3));
TempNewX:=NewX(Distance(TotalVelocityValue,CurrentVelocityValue, TimeInterval), MovingWeightAngle);
TempNewY:=NewY(round(MyForm.MovingWeight.Left + TempNewX),MyForm.MovingWeight.Left, MyForm.MovingWeight.Top, TempGradient);
MyForm.MovingWeight.Left:=round(MyForm.MovingWeight.Left + (TempNewX/10));
MyForm.MovingWeight.Top:=round(MyForm.MovingWeight.Top + (TempNewY/10));
//Plot New Location PullingWeight (RED)
TempGradient:=CalcGradient(basex2, basey2, round(basex3), round(basey3));
TempNewX:=NewX(Distance(TotalVelocityValue,CurrentVelocityValue, TimeInterval), PullingWeightAngle);
TempNewY:=NewY(round(MyForm.PullingWeight.Left+TempNewX),MyForm.PullingWeight.Left, MyForm.PullingWeight.Top, TempGradient);
MyForm.PullingWeight.Left:=round(MyForm.PullingWeight.Left + (TempNewX/10));
MyForm.PullingWeight.Top:=round(MyForm.PullingWeight.Top + (TempNewY/10));
//Fixed values for testing only to ensure can stop timer
if (MyForm.MovingWeight.Left > 720) or (MyForm.MovingWeight.Top > 335) then
begin
//MyForm.Timer1.Destroy;
//StopTimer:=True;
ShowMessage('ERROR: Cannot kill Pascal application! ');
//MyForm.Timer1.free;
//MyForm.Timer1.Destroy;
//MyForm.Timer1.Enabled:=false;
//MyForm.Timer1.Destroying;
//MyForm.Timer1._Release;
//MyForm.Timer1.FreeInstance;
//MyForm.Timer1.CleanupInstance;
StopTimer:=True;
Exit;
end;
// check if TOP barrier reached (using pulling weight (red))
if TopBarrierReached(MyForm.PullingWeight.Left,MyForm.PullingWeight.Top) = true then
begin
ShowMessage('ERROR: Top Barrier Reached! ');
StopTimer:=True;
Exit;
end;
// check if TOP barrier reached (using pulling weight (red))
if BottomBarrierReached(MyForm.PullingWeight.Left, MyForm.PullingWeight.Top) = true then
begin
ShowMessage('ERROR: BottomBarrierReached! ');
StopTimer:=True;
Exit;
end;
MyForm.TxtRedx1.Text:=inttostr(MyForm.PullingWeight.Left);
MyForm.TxtRedy1.Text:=inttostr(MyForm.PullingWeight.Top);
//Draw string
MyForm.canvas.Pen.Width:=10;
MyForm.Canvas.Pen.color:= clblack;
MyForm.canvas.Line(MyForm.MovingWeight.Left+20,MyForm.MovingWeight.Top+10,round(basex3),round(calcbasey3)-40);
MyForm.canvas.Line(MyForm.PullingWeight.Left+20,MyForm.PullingWeight.Top+10,round(basex3),round(calcbasey3)-40);
end;
// loop for ever
procedure TMyForm.Timer1Timer(Sender: TObject);
begin
// for each iteration intialise intermediate variables
PulleyRadius:=20;
PullingMidPointx1:= 0;
PullingMidPointy1:= 0;
MovingMidPointx1:= 0;
MovingMidPointy1:= 0;
newx2 := 0;
newy2 := 0;
ForceMovingWeight:=0;
ForcePullingWeight:=0;
MWTension:=0;
// if user has entered values and pressed the submit button
if SubmitPressed = true then
begin
// if first run then set up simulation base screen
if StartSimulation = true then
begin
InitialRun();
DrawTriangle();
DrawWeights();
end
//if first run then set up simulation base screen
else
begin
DrawTriangle();
DrawWeights();
RedrawWeights();
//MyForm.Timer1.free;
//Exit;
//MyForm.Timer1.Destroy;
//MyForm.Timer1.Enabled:=false;
//MyForm.Timer1.Destroying;
//MyForm.Timer1._Release;
//MyForm.Timer1.FreeInstance;
//MyForm.Timer1.CleanupInstance;
end;
end;
end;