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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Chaos game step by step in the Amazing Hopper 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 Amazing Hopper programming language

Source code in the amazing programming language

/* Chaos game - JAMBO hopper */

#include 

#define LIMITE  50000

Main
  ancho = 700, alto = 150
  x=0,y=0,color=0
  vertice=0, 
  c=0, Let( c := Utf8(Chr(219)))
  Let(x := Int(Rand(ancho)))
  Let(y := Int(Rand(alto)))

  mid ancho=0, Let( mid ancho:= Div(ancho,2))

  Cls
  i=LIMITE
  Void(pixeles)

  Loop
    Ceil(Rand(3)), On gosub( EQ1, EQ2, EQ3 )

    Set( Int(y), Int(x), color),Apndrow(pixeles)
    --i
  Back if (i) is not zero

  Canvas-term  
  Cls
  i=1
  Iterator(++i, Leq(i,LIMITE), Colorfore([i,3]Get(pixeles)), \
                             Locate( [i,1]Get(pixeles), [i,2]Get(pixeles) ), Print(c) )
  Pause

End
Subrutines
    EQ1:
          Let(x := Div(x, 2))
          Let(y := Div(y, 2))
          Let(color:=9), Return

    EQ2:
          Let(x := Add( mid ancho, Div(Sub(mid ancho, x), 2) ) )
          Let(y := Sub( alto, Div( Sub(alto, y), 2 )))
          Let(color:=10), Return
    EQ3:
          Let(x := Sub(ancho,  Div( Sub(ancho, x), 2)))
          Let(y := Div(y, 2))
          Let(color:=4), Return

  

You may also check:How to resolve the algorithm Inverted syntax step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm Koch curve step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Unicode strings step by step in the REXX programming language
You may also check:How to resolve the algorithm Machine code step by step in the 6502 Assembly programming language
You may also check:How to resolve the algorithm Topic variable step by step in the Wren programming language