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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Cantor set step by step in the Processing 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 Processing programming language

Source code in the processing programming language

//Aamrun, 1st July 2022

void cantorSet(int x1,int y1,int x2,int y2,int strWt,int gap,int n){
    strokeWeight(strWt);
    line(x1,y1,x2,y2);
  if(n>0){
    cantorSet(x1,gap + y1,(2*x1+x2)/3,gap + (2*y1+y2)/3,strWt,gap,n-1);
    cantorSet((2*x2+x1)/3,gap + (2*y2+y1)/3,x2,gap + y2,strWt,gap,n-1);
  }
}

void setup(){
  size(1000,1000);
  cantorSet(100,10,900,10,1,10,5);
}


  

You may also check:How to resolve the algorithm N-queens problem step by step in the Processing programming language
You may also check:How to resolve the algorithm Repeat a string step by step in the Processing programming language
You may also check:How to resolve the algorithm Fusc sequence step by step in the Processing programming language
You may also check:How to resolve the algorithm Superellipse step by step in the Processing programming language
You may also check:How to resolve the algorithm Additive primes step by step in the Processing programming language