How to resolve the algorithm Polyspiral step by step in the Delphi programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Polyspiral step by step in the Delphi programming language

Table of Contents

Problem Statement

A Polyspiral is a spiral made of multiple line segments, whereby each segment is larger (or smaller) than the previous one by a given amount. Each segment also changes direction at a given angle.

Animate a series of polyspirals, by drawing a complete spiral then incrementing the angle, and (after clearing the background) drawing the next, and so on. Every spiral will be a frame of the animation. The animation may stop as it goes full circle or continue indefinitely. The given input values may be varied. If animation is not practical in your programming environment, you may show a single frame instead.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Polyspiral step by step in the Delphi programming language

Source code in the delphi programming language

procedure PolySpiral(Image: TImage);
var Step,Angle,LineLen,I: integer;
var X,Y,X1,Y1: double;
begin
AbortFlag:=False;
ClearImage(Image,clBlack);
Image.Canvas.Pen.Width:=1;
while true do
	begin
	Image.Canvas.Pen.Color:=clYellow;
	Step:=(Step + 5) mod 360;
	X:=Image.Width/2;
	Y:=Image.Height/2;

	LineLen:=5;
	angle:=Step;
	for I:=1 to 150 do
		begin
		X1:=X + LineLen*cos(DegToRad(angle));
		Y1:=Y + LineLen*sin(DegToRad(angle));
		Image.Canvas.MoveTo(Round(X),Round(Y));
		Image.Canvas.LIneTo(Round(X1),Round(Y1));
		Image.Repaint;

		LineLen:=LineLen+2;

		Angle:=(Angle + Step) mod 360;
		X:=X1;
		Y:=Y1;
		end;
	if Application.Terminated then exit;
	if AbortFlag then break;
	Sleep(1200);
	Application.ProcessMessages;
	WaitForButton;
	ClearImage(Image,clBlack);
	end;
end;


  

You may also check:How to resolve the algorithm Jacobi symbol step by step in the Crystal programming language
You may also check:How to resolve the algorithm Hello world/Standard error step by step in the Scheme programming language
You may also check:How to resolve the algorithm Loops/With multiple ranges step by step in the Eiffel programming language
You may also check:How to resolve the algorithm Colour pinstripe/Display step by step in the C programming language
You may also check:How to resolve the algorithm Van Eck sequence step by step in the Ruby programming language