How to resolve the algorithm Cantor set step by step in the Delphi programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Cantor set step by step in the Delphi programming language

Table of Contents

Problem Statement

Draw a Cantor set.

See details at this Wikipedia webpage:   Cantor set

Let's start with the solution:

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

Source code in the delphi programming language

program Cantor_set;

{$APPTYPE CONSOLE}

const
  WIDTH: Integer = 81;
  HEIGHT: Integer = 5;

var
  Lines: TArray>;

procedure Init;
var
  i, j: Integer;
begin
  SetLength(lines, HEIGHT, WIDTH);
  for i := 0 to HEIGHT - 1 do
    for j := 0 to WIDTH - 1 do
      lines[i, j] := '*';
end;

procedure Cantor(start, len, index: Integer);
var
  seg, i, j: Integer;
begin
  seg := len div 3;
  if seg = 0 then
    Exit;
  for i := index to HEIGHT - 1 do
    for j := start + seg to start + seg * 2 - 1 do
      lines[i, j] := ' ';
  Cantor(start, seg, index + 1);
  Cantor(start + seg * 2, seg, index + 1);
end;

var
  i, j: Integer;

begin
  Init;
  Cantor(0, WIDTH, 1);
  for i := 0 to HEIGHT - 1 do
  begin
    for j := 0 to WIDTH - 1 do
      Write(lines[i, j]);
    Writeln;
  end;
  Readln;
end.


  

You may also check:How to resolve the algorithm Zebra puzzle step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Loops/N plus one half step by step in the Stata programming language
You may also check:How to resolve the algorithm Color of a screen pixel step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Knapsack problem/Continuous step by step in the Nim programming language
You may also check:How to resolve the algorithm Prime conspiracy step by step in the C# programming language