This example is the optimized version for the "Sierpinski Challenge", an exciting challenge regarding fractals. This example reproduces the famous "SIERPINSKI TRIANGLE" on retrocomputers. It is a very simple fractal to obtain, which takes its name from the mathematician who first studied its properties. Such a triangle can have different shapes and sizes and can be obtained in various ways. One of the methods to create it is the so-called "Game of chaos". The fractal is built by creating iteratively a sequence of points, starting from a random initial point, in which each point of the sequence is a given fraction of the distance between the previous point and one of the vertices of the polygon; the vertex is chosen at random in each iteration. Repeating this iterative process a large number of times, selecting the vertex at random at each iteration, often (but not always) produces a fractal shape. Using a regular triangle and the factor 1/2, it will result in a Sierpinski triangle.
source
compile
sandbox
issues?
back to examples
' ============================================================================ ' INITIALIZATION ' ============================================================================ ' We start measure time from the graphical initialization. t=TI ' Enable the monocrome bitmap graphic, ' with a minimum resolution of 160x100 pixels. BITMAP ENABLE(320,200,2) ' Pen color is black INK BLACK ' Paper color is white CLS WHITE ' Let's calculate the three constants CONST x1=(SCREEN WIDTH \ #2): CONST y1=0 CONST x2=0: CONST y2=(SCREEN HEIGHT - 1 ) CONST x3=(SCREEN WIDTH - 1): CONST y3=(SCREEN HEIGHT - 1 ) ' Number of points to draw CONST limit = 10000 ' ============================================================================ ' MAIN CYCLE ' ============================================================================ ' Initialize the coordinates. x=#x1 AS POSITION y=#y1 AS POSITION ' Initialize the counter. n=#0 AS INTEGER ' Repeat the cycle up to (limit) points. REPEAT ' Select a random triangle r=(RANDOM BYTE \ 32) AND 3 ' If the triange has been chosen... IF r=0 THEN ' Update the coordinates accordingly. ADD x, x1 : DIV x, #2 ADD y, y1 : DIV y, #2 ELSE IF r=1 THEN ADD x, x2 : DIV x, #2 ADD y, y2 : DIV y, #2 ELSE ADD x, x3 : DIV x, #2 ADD y, y3 : DIV y, #2 ENDIF ' Plot the point on the screen. PLOT x, y ' Increment the number of point traced. INC n UNTIL n=limit ' Calculate the time passed te=TI-t HOME ' Print the stats PRINT "time = ";(te/TICKS PER SECOND);" sec" PRINT "points = ";n%
The instructions here refer to compiling the example from the command line. For Microsoft Windows
users we suggest using UGBASIC-IDE, which allows
you to download and compile each single example with just one click.
Are instructions for your specific home computer / console missing? First of all, check if your computer
is supported by clicking here. If so, since ugBASIC is a language which does not provide abstractions, it is possible
that this example will not work on your target. If you think this is an issue, please click here.
In order to compile the example, type this command on the command line:
Linux
ugbc.cpc -O dsk -o contrib_sierpinski2.dsk contrib_sierpinski2.bas
Windows
ugbc.cpc.exe -O dsk -o contrib_sierpinski2.dsk contrib_sierpinski2.bas
For Microsoft Windows users we suggest using UGBASIC-IDE, which allows
you to download and compile this example with just one click.
In order to compile the example, type this command on the command line:
Linux
ugbc.atarixl -O xex -o contrib_sierpinski2.xex contrib_sierpinski2.bas
Windows
ugbc.atarixl.exe -O xex -o contrib_sierpinski2.xex contrib_sierpinski2.bas
For Microsoft Windows users we suggest using UGBASIC-IDE, which allows
you to download and compile this example with just one click.
In order to compile the example, type this command on the command line:
Linux
ugbc.atari -O xex -o contrib_sierpinski2.xex contrib_sierpinski2.bas
Windows
ugbc.atari.exe -O xex -o contrib_sierpinski2.xex contrib_sierpinski2.bas
For Microsoft Windows users we suggest using UGBASIC-IDE, which allows
you to download and compile this example with just one click.
In order to compile the example, type this command on the command line:
Linux
ugbc.coleco -O rom -o contrib_sierpinski2.rom contrib_sierpinski2.bas
Windows
ugbc.coleco.exe -O rom -o contrib_sierpinski2.rom contrib_sierpinski2.bas
For Microsoft Windows users we suggest using UGBASIC-IDE, which allows
you to download and compile this example with just one click.
In order to compile the example, type this command on the command line:
Linux
ugbc.c128 -O prg -o contrib_sierpinski2.prg contrib_sierpinski2.bas
Windows
ugbc.c128.exe -O prg -o contrib_sierpinski2.prg contrib_sierpinski2.bas
For Microsoft Windows users we suggest using UGBASIC-IDE, which allows
you to download and compile this example with just one click.
In order to compile the example, type this command on the command line:
Linux
ugbc.c64 -O prg -o contrib_sierpinski2.prg contrib_sierpinski2.bas
Windows
ugbc.c64.exe -O prg -o contrib_sierpinski2.prg contrib_sierpinski2.bas
For Microsoft Windows users we suggest using UGBASIC-IDE, which allows
you to download and compile this example with just one click.
In order to compile the example, type this command on the command line:
Linux
ugbc.d32 -O bin -o contrib_sierpinski2.bin contrib_sierpinski2.bas
Windows
ugbc.d32.exe -O bin -o contrib_sierpinski2.bin contrib_sierpinski2.bas
For Microsoft Windows users we suggest using UGBASIC-IDE, which allows
you to download and compile this example with just one click.
In order to compile the example, type this command on the command line:
Linux
ugbc.d64 -O bin -o contrib_sierpinski2.bin contrib_sierpinski2.bas
Windows
ugbc.d64.exe -O bin -o contrib_sierpinski2.bin contrib_sierpinski2.bas
For Microsoft Windows users we suggest using UGBASIC-IDE, which allows
you to download and compile this example with just one click.
In order to compile the example, type this command on the command line:
Linux
ugbc.sc3000 -O rom -o contrib_sierpinski2.rom contrib_sierpinski2.bas
Windows
ugbc.sc3000.exe -O rom -o contrib_sierpinski2.rom contrib_sierpinski2.bas
For Microsoft Windows users we suggest using UGBASIC-IDE, which allows
you to download and compile this example with just one click.
In order to compile the example, type this command on the command line:
Linux
ugbc.sg1000 -O rom -o contrib_sierpinski2.rom contrib_sierpinski2.bas
Windows
ugbc.sg1000.exe -O rom -o contrib_sierpinski2.rom contrib_sierpinski2.bas
For Microsoft Windows users we suggest using UGBASIC-IDE, which allows
you to download and compile this example with just one click.
In order to compile the example, type this command on the command line:
Linux
ugbc.coco -O bin -o contrib_sierpinski2.bin contrib_sierpinski2.bas
Windows
ugbc.coco.exe -O bin -o contrib_sierpinski2.bin contrib_sierpinski2.bas
For Microsoft Windows users we suggest using UGBASIC-IDE, which allows
you to download and compile this example with just one click.
In order to compile the example, type this command on the command line:
Linux
ugbc.zx -O tap -o contrib_sierpinski2.tap contrib_sierpinski2.bas
Windows
ugbc.zx.exe -O tap -o contrib_sierpinski2.tap contrib_sierpinski2.bas
For Microsoft Windows users we suggest using UGBASIC-IDE, which allows
you to download and compile this example with just one click.
If you have found a problem trying to run this example, if you think there is a bug or, more
simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!
open an issue
BACK TO EXAMPLES