How to resolve the algorithm Chaos game step by step in the FutureBasic programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Chaos game step by step in the FutureBasic programming language

Table of Contents

Problem Statement

The Chaos Game is a method of generating the attractor of an iterated function system (IFS). One of the best-known and simplest examples creates a fractal, using a polygon and an initial point selected at random.

Play the Chaos Game using the corners of an equilateral triangle as the reference points.   Add a starting point at random (preferably inside the triangle).   Then add the next point halfway between the starting point and one of the reference points.   This reference point is chosen at random. After a sufficient number of iterations, the image of a Sierpinski Triangle should emerge.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Chaos game step by step in the FutureBasic programming language

Source code in the futurebasic programming language

void local fn DoIt
  long w = 460, h = 400, i, x = rnd(w), y = rnd(h)
  for i = 1 to 50000
    select ( rnd(3)-1 )
      case 1
        x = w/2+(w/2-x)/2
        y = h-(h-y)/2
        pen ,fn ColorRed
      case 2
        x = w-(w-x)/2
        y = y/2
        pen ,fn ColorGreen
      case else
        x = x/2
        y = y/2
        pen ,fn ColorBlue
    end select
    line x-0.5,y-0.5,x+0.5,y+0.5
  next
end fn

window 1, @"Chaos Game", (0,0,460,400)
WindowSetBackgroundColor( 1, fn ColorWhite )

fn DoIt

HandleEvents

  

You may also check:How to resolve the algorithm Multiple regression step by step in the ERRE programming language
You may also check:How to resolve the algorithm Sort using a custom comparator step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Find limit of recursion step by step in the Oforth programming language
You may also check:How to resolve the algorithm Symmetric difference step by step in the C programming language
You may also check:How to resolve the algorithm Anagrams step by step in the ABAP programming language