How to resolve the algorithm Chaos game step by step in the BASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Chaos game step by step in the BASIC 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 BASIC programming language
Source code in the basic programming language
10 SCREEN 1
20 X = INT(RND(0) * 200)
30 Y = INT(RND(0) * 173)
40 FOR I=1 TO 20000
50 V = INT(RND(0) * 3) + 1
60 ON V GOTO 70,100,130
70 X = X/2
80 Y = Y/2
90 GOTO 150
100 X = 100 + (100-X)/2
110 Y = 173 - (173-Y)/2
120 GOTO 150
130 X = 200 - (200-X)/2
140 Y = Y/2
150 PSET X,Y,V
160 NEXT I
10 HGR2
20 X = INT(RND(1) * 200)
30 Y = INT(RND(1) * 173)
40 FOR I=1 TO 20000
50 V = INT(RND(1) * 3) + 1
60 ON V GOTO 70,100,130
70 X = X/2
80 Y = Y/2
90 GOTO 150
100 X = 100 + (100-X)/2
110 Y = 173 - (173-Y)/2
120 GOTO 150
130 X = 200 - (200-X)/2
140 Y = Y/2
150 HCOLOR=V+4
160 HPLOT X,Y
170 NEXT I
#Chaos game
ancho = 500 : alto = 300
x = Int(Rand * ancho)
y = Int(Rand * alto)
Clg
FastGraphics
Graphsize ancho , alto
For iteracion = 1 To 30000
vertice = Int(Rand * 3) + 1
Begin Case
Case vertice = 1
x = x / 2
y = y / 2
Color red
Case vertice = 2
x = (ancho/2) + ((ancho/2)-x) / 2
y = alto - (alto-y) / 2
Color green
Case vertice = 3
x = ancho - (ancho-x) / 2
y = y / 2
Color blue
End Case
#Pset (x,y),vertice
Plot (x,y)
Next iteracion
Refresh
ImgSave "chaos_game.jpg", "jpg"
End
100 REM Chaos game
110 CLS
120 SCREEN 7 '320x200 EGA Color
130 X = INT(RND(1) * 200)
140 Y = INT(RND(1) * 173)
150 FOR I=1 TO 20000
160 V = INT(RND(1) * 3) + 1
170 ON V GOTO 180,210,240
180 X = X/2
190 Y = Y/2
200 GOTO 260
210 X = 100 + (100-X)/2
220 Y = 173 - (173-Y)/2
230 GOTO 260
240 X = 200 - (200-X)/2
250 Y = Y/2
260 PSET(X,Y),V
270 NEXT I
280 END
100 PROGRAM "ChaosGam.bas"
110 RANDOMIZE
120 GRAPHICS HIRES 4
130 LET X=RND(800):LET Y=RND(600)
140 FOR I=1 TO 20000
150 LET VERTEX=RND(3)
160 SELECT CASE VERTEX
170 CASE 0
180 LET X=X/2
190 LET Y=Y/2
200 CASE 1
210 LET X=400+(400-X)/2
220 LET Y=600-(600-Y)/2
230 CASE 2
240 LET X=800-(800-X)/2
250 LET Y=Y/2
260 END SELECT
270 SET INK VERTEX+1
280 PLOT X,Y
290 NEXT
10 mode 1:randomize time:defint a-z
20 x = 640 * rnd
30 y = 400 * rnd
40 for i=1 to 20000
50 v = rnd * 2 + 1
60 on v goto 70,100,130
70 x = x/2
80 y = y/2
90 goto 150
100 x = 320 + (320-x)/2
110 y = 400 - (400-y)/2
120 goto 150
130 x = 640 - (640-x)/2
140 y = y/2
150 plot x,y,v
160 next i
100 REM Chaos game
110 CLS
120 SCREEN 2
130 X = INT(RND(1) * 256)
140 Y = INT(RND(1) * 192)
150 FOR I=1 TO 20000
160 V = INT(RND(1) * 3) + 1
170 ON V GOTO 180,220,260
180 X = X/2
190 Y = Y/2
200 V = 8 'red
210 GOTO 290
220 X = 128 + (128-X)/2
230 Y = 192 - (192-Y)/2
240 V = 3 'green
250 GOTO 290
260 X = 256 - (256-X)/2
270 Y = Y/2
280 V = 7 'blue
290 PSET(X,Y),V
300 NEXT I
310 END
10 LET X=RND*46
20 LET Y=RND*40
30 FOR I=1 TO 5000
40 LET VERTEX=INT (RND*3)
50 GOTO 60+VERTEX*30
60 LET X=X/2
70 LET Y=Y/2
80 GOTO 140
90 LET X=23+(23-X)/2
100 LET Y=40-(40-Y)/2
110 GOTO 140
120 LET X=46-(46-X)/2
130 LET Y=Y/2
140 PLOT X,42-Y
150 NEXT I
10 LET x=RND*200
20 LET y=RND*173
30 FOR i=1 TO 20000
40 LET vertex=INT (RND*3)
50 IF vertex=1 THEN GO TO 100
60 IF vertex=2 THEN GO TO 130
70 LET x=x/2
80 LET y=y/2
90 GO TO 150
100 LET x=100+(100-x)/2
110 LET y=173-(173-y)/2
120 GO TO 150
130 LET x=200-(200-x)/2
140 LET y=y/2
150 INK vertex+1
160 PLOT x,y
170 NEXT i
180 INK 0
You may also check:How to resolve the algorithm Prime conspiracy step by step in the zkl programming language
You may also check:How to resolve the algorithm Quine step by step in the beeswax programming language
You may also check:How to resolve the algorithm AKS test for primes step by step in the Prolog programming language
You may also check:How to resolve the algorithm Run-length encoding step by step in the Scala programming language
You may also check:How to resolve the algorithm Golden ratio/Convergence step by step in the Odin programming language